Static Site Generator
Zuzu converts all your markdown files into static htmls pages to be rendered quickly. It uses Github falvoured Markdown CSS and highlight js to beautify code snippets. This blog, for example, has been written using this generator. This enables noobs like me to write blogs without having to learn a lot of code! It is a very simple and easy to use generator. All you need to do is to write a markdown file and it will be rendered as a page ;) You can create a new page by creating a new markdown file.
Zuzu parses the markdown file using javascript and renders it as html documents. It then saves the html files in the public folder. The public folder, with index.html file, is the final output of the generator and this can be deployed and hosted in various platforms. This particular blog has been deployed on Github Pages.
# This is a title
This is a paragraph
This is another paragraph
This is a list:
* Item 1
* Item 2
* Item 3
This is a code block:
```
print("Hello World")
```
This is a table:
| Column 1 | Column 2 | Column 3 |
| -------- | -------- | -------- |
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |
This is a link: [zuzu](https://anubhavp.me/blog/zuzu.html)
Run npm run generate in the console.
You'll now see the blog in the public folder! Run the index.html file in your browser to see your blog. You may now deploy your site
to a server.
- MarkdownIt Markdown parser done right.
- MarkdownItAnchor Header anchors for markdown-it.
- Glob "Globs" are the patterns you type when you do stuff like ls .js on the command line, or put build/ in a .gitignore file.
- Gray-Matter Parse front-matter from a string or file.
- Mkdirp Create Dirs if they do not exist.
This is the code for the generator.js. The code works in the following way:
fs.readfile() from fsreads all the files from the said directory and stores then infilenameusingglob. It is aglobthat matches all the files in the directory. Thefile systemmodule allows you to work with the file system on your computer.gray-matterhelps extracting front matter from the a string or file. Converts a string with front-matter, like this:
title: Hello
slug: home
---
<h1>Hello world!</h1>
Into an object like this:
{
content: '<h1>Hello world!</h1>',
data: {
title: 'Hello',
slug: 'home'
}
}
It then extracts the front matter and stores it in data. It then stores the content in content and returns the filename to the main() function. It then repeats the process for all the files in the directory.
-
The
main()function then takes in onefilenameat a time and then parses it throughmarkdownit( ,{markdownitanchor}).markdownitparses the file and converts the markdown content into HTML files. It then creates ahtmlfile and writes the parsed content into it. It then saves thehtmlfile in thepublicfolder. This process repeats for all the files in the directory. -
The converted html files are stored in the specified directories then using
mkdirp. Theindex.htmlfile isalready present in thepublicfolder.mkdirpcreates the directories if they do not exist.
Fork and clone this repo. Add your markdown files in the content folder and find the beautifully rendered html files in the public folder :)
- Add a proper template file in the initial folder with index.html and respective assets.
- Create an executable for zuzu.