A lightweight static site generator built from scratch in Python that transforms Markdown files into beautiful, responsive HTML websites.
- Markdown files are in the
/contentdirectory. Atemplate.htmlfile is in the root of the project. - The static site generator (the Python code in
src/) reads the Markdown files and the template file. - The generator converts the Markdown files to a final HTML file for each page and writes them to the /docs directory.
- Start the built-in Python HTTP server (a separate program, unrelated to the generator) to serve the contents of the
/docsdirectory onhttp://localhost:8888(local machine). - Open a browser and navigate to
http://localhost:8888to view the rendered site.
- Delete everything in the
/docsdirectory. - Copy any static assets (HTML template, images, CSS, etc.) to the
/docsdirectory. - Generate an HTML file for each Markdown file in the
/contentdirectory. For each Markdown file:- Open the file and read its contents.
- Split the markdown into "blocks" (e.g. paragraphs, headings, lists, etc.).
- Convert each block into a tree of
HTMLNodeobjects. For inline elements (like bold text, links, etc.) we will convert:- Raw markdown ->
TextNode->HTMLNode
- Raw markdown ->
- Join all the
HTMLNodeblocks under one large parentHTMLNodefor the pages. - Use a recursive
to_html()method to convert theHTMLNodeand all its nested nodes to a giant HTML string and inject it in the HTML template.
- Write the full HTML string to a file for that page in the
/docsdirectory.
Purpose: fast rebuilds for local preview
Command: python3 src/main.py (uses root / so links work locally)
When to use: while editing content/templates then serve docs/ locally
Purpose: generate the site exactly as it will appear at https://USERNAME.github.io/REPO_NAME/
Command: python3 src/main.py "/REPO_NAME/" (prefixes links with the repo base path)
When to use: before commit/push to deploy via GitHub Pages
