A small command-line tool that generates static HTML from YAML config and .stg template files. Use a shared layout (header, footer, includes) and per-page content to build a static site.
- Layout from YAML — Define header/footer and includes in
.gen/layout.yml - Per-page config — Title, CSS/JS dependencies, and template folder in
.gen/page.yml - Simple templates — One
.stgfile per page; content is wrapped in<main> - Prettified output — Generated HTML is formatted for readability
- Python 3.7+
- Dependencies: PyYAML, BeautifulSoup4
Install dependencies:
pip install -r requirements.txt- Create the config directory (e.g.
.gen) and addpage.ymlandlayout.yml. - Create an
includesfolder with header/footer HTML fragments. - Create a template folder (e.g.
templates) and add.stgfiles (one per page). - Run the generator:
# Build all pages (all .stg files in the template folder)
python stgen-cli.py
# Build only specific pages
python stgen-cli.py index about contactOutput is written to the compiled directory by default.
Use this layout (folder names can vary; set template_dir in page.yml accordingly):
project/
├── .gen/
│ ├── layout.yml # Layout: header/footer includes
│ └── page.yml # Site title, template_dir, CSS/JS deps
├── includes/ # Header/footer fragments (path configurable)
│ ├── header.html
│ ├── sidebar.html
│ └── footer.html
├── templates/ # One .stg file per page (dir from page.yml)
│ ├── index.stg
│ ├── about.stg
│ └── contact.stg
├── compiled/ # Generated HTML (default output dir)
│ ├── index.html
│ ├── about.html
│ └── contact.html
├── stgen-cli.py
└── requirements.txt
title— Used in<title>for all pages.template_dir— Folder that contains.stgpage templates (e.g.templates).dependencies— Optional CSS, JS, and extra HTML:styles— List of CSS URLs →<link rel="stylesheet" href="...">scripts— List of JS URLs →<script src="..." defer></script>html— Optional string (e.g. extra<link>or<script>tags).
Example:
title: "My Site"
template_dir: "templates"
dependencies:
styles:
- "/css/style.css"
scripts:
- "/js/app.js"
html: ''Defines which files are included in header and footer. Paths are relative to the includes directory (default: includes/).
Example:
layout:
header:
include:
- header.html
- sidebar.html
footer:
include:
- footer.html| Command | Description |
|---|---|
python stgen-cli.py |
Build all pages (every .stg in template_dir) |
python stgen-cli.py index about |
Build only index and about (expects index.stg, about.stg) |
python stgen-cli.py -o build |
Write HTML to build/ instead of compiled/ |
python stgen-cli.py -i partials |
Use partials/ as the includes directory |
python stgen-cli.py -g .config |
Use .config/ instead of .gen/ for config |
python stgen-cli.py -q |
Quiet: only print errors |
-
Install and prepare
pip install -r requirements.txt mkdir .gen includes templates compiled
-
Create
.gen/page.ymltitle: "My Site" template_dir: "templates" dependencies: scripts: [] styles: [] html: ''
-
Create
.gen/layout.ymllayout: header: include: ["header.html"] footer: include: ["footer.html"]
-
Create
includes/header.html<header> <a href="index.html">Home</a> <a href="about.html">About</a> </header>
-
Create
includes/footer.html<footer><p>© My Site</p></footer>
-
Create
templates/index.stg<h1>Welcome</h1> <p>This is the home page.</p>
-
Build
python stgen-cli.py
-
Open
compiled/index.htmlin a browser.
To add another page, create e.g. templates/about.stg and run python stgen-cli.py again (or python stgen-cli.py about).
- Fork the project
- Create a branch for your changes
- Commit and push
- Open a Pull Request
Thank you for contributing.