This project is a simple static site generator written in Python. It reads Markdown files from a source directory, processes them according to a specified configuration, and outputs HTML files to a target directory.
- Converts Markdown files to HTML.
- Supports front matter for metadata in Markdown files.
- Organizes output files based on metadata and configuration.
- Uses Jinja2 for templating.
- Fully customizable™️
- Python 3.7 or higher
- PyYAML
- Python Frontmatter
- Markdown
- Jinja2
-
Clone the repository:
git clone https://github.com/yourusername/static-site-generator.git cd static-site-generator -
Install the required packages:
pip install -r requirements.txt
The configuration file config.yaml specifies how the files should be processed. It includes format settings and group configurations. Below is an example configuration:
formats:
meta.date: '%Y-%m-%d'
groups:
- name: post
template: blog_template.html
rss: true
path_config:
- "\"p\""
- "['meta']['date'].year"
- "['meta']['handle']"
- name: default
template: generic.html
rss: false
path_config:
- "['meta']['canonical-uri']"-
Create a source directory with Markdown files. Each Markdown file should have front matter metadata. For example:
--- title: "My First Blog Post" date: 2024-06-18 group: "blog" slug: "my-first-blog-post" --- # My First Blog Post This is the content of my first blog post.
-
Create the necessary Jinja2 templates in the
templatesdirectory. For example,blog_template.htmlmight look like this:<!DOCTYPE html> <html> <head> <title>{{ context.meta.title }}</title> </head> <body> <h1>{{ context.meta.title }}</h1> <div>{{ context.content_html | safe }}</div> </body> </html>
Check out
test_folderandtest_outputfor more complete examples. -
Run the script with the source directory, output directory, and configuration file:
python3 do.py --src_dir test_folder --out_dir test_output --site_url https://example.com/
-
Set up a mock server to test the outputs
cd test_output && python3 -m http.server
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
For questions or suggestions, please contact cemrekr@aol.com.