boot.dev Static Site Generator
A python application that converts markdown files into html. The SSG script will first convert your markdown into html then setup a python http server for you to view the final result.
# Tolkien Fan Club
**I like Tolkien**. Read my [first post here](/majesty)
> All that is gold does not glitter
## Reasons I like Tolkien
* You can spend years studying the legendarium and still not understand its depths
* It can be enjoyed by children and adults alike
* Disney *didn't ruin it*
* It created an entirely new genre of fantasy
...
Sample files are already included in this repository, but you can alter the content with these steps:
- Build your markdown files representing your website content. These files should be markdown files (.md) and placed inside the
/content
folder. - Place all your static files into the
/static
folder. This should include any css and images. - (Optional) Edit the
template.html
to change the template that is used for the html. - (Optional) Edit the
main.sh
to further configure/alter the http server and editsrc/main.py
to change any of the folder locations should you choose to rename them.
To start the website, simply run the main script:
./main.sh
The console will output the content files it converted to html and let you know the server is ready.
- Generating page from content/majesty/index.md to public/majesty/index.html using template.html
- Generating page from content/index.md to public/index.html using template.html
- Serving HTTP on 0.0.0.0 port 8888 ...
Output is placed and served via the /public
folder by default.
The rough psuedocode for this application's markdown to html converter is as follows:
- Start with the markdown string.
- Split the markdown into text blocks. Blocks represent each 'element' in markdown, such as a heading, paragraph, list, or code block.
- Convert each text block into an html node as follows:
- Detect the block's type and remove the associated characters.
- Convert the remaining text into text nodes (pull out bold, italic, links, images, plain text, etc).
- Convert the text nodes into equivalent html nodes.
- Return a parent html node (using the block type) and set the children to the calculated html nodes.
- Return a parent html node (div) with the aforementioned html nodes as children.
There are two primary improvements that could be made to this project:
- Blocks must be seperated by two newline characters (an empty row inbetween). Typical markdown processors can handle just one newline character and detect either continuations of a prior element or a new element.
- Nested delimiters are not supported. For example, you could not do 'bold text with italic inside the text'.
Both improvements require more robust parsing algorithms. Both aforementioned shortcomings are due to strict delimiter splits being used instead, one for markdown to blocks, and one for text to text nodes.