A simple static website generator
Project description
sssimp 🐍
Simple Static SIte Maker in Python
A simple tool to generate a static website while being able to use powerful HTML templates (Jinja2), Markdown files converted to HTML, and other preprocessors.
Why?
I wanted a simple way to generate static websites and I like Jinja2. I had previous experiences working with Jekyll but it seemed like too much work to setup everytime and overkill for the job as it supports many features I don't necessarily use.
Installing
pip install sssimp
How to use
Create a folder called input
, it will hold the data to generate the site.
Running python -m sssimp
will generate content in the output
folder.
Here is an example script for UNIX that will regenerate the site everytime a file changes, useful during development:
trap "echo Exited!; exit 1;" SIGINT SIGTERM
while true; do
python -m venv .venv
source .venv/bin/activate
pip install --upgrade sssimp
python -m sssimp
echo Waiting for change
watch -g ls -lR .
done
Generators
-
Files placed in
input/content
will be directly copied to theoutput
folderExample:
input/content/favicon.png
->output/favicon.png
-
HTML files with the suffix .html placed in
input/content
will be parsed as Jinja2 templates, they can use templates defined ininput/templates
.
See the Jinja2 documentationExample:
input/content/index.html
->output/index.html
Starting with content{% extends "base.html" %} ...
Will use the template
input/templates/base.html
-
CSS files in
input/css
will be merged together in a single fileoutput/bundle.css
-
Markdown files with the suffix .md placed in
input/content
will be parsed to HTML and passed to a template with the same name as their parent folder as the parametermarkdown
Example:
./input/content/post/hello-world.md
->./output/post/hello-world.html
Using the template./input/templates/post.html
Generated with context{'markdown': 'the markdown file converted to HTML'}
The template name can be overriden using the markdown meta argument "template"
Example:
./input/content/post/special.md
->./output/post/special.html
Starting with content--- template: special.html --- ...
Will use the template
./input/templates/special.html
instead ofpost.html
Examples
Additional Jinja2 filters
-
|a
makes any relative path point to the top of the output folder.Example:
input/content/blog/post/tech/2021/11/some-post.html
->output/blog/post/tech/2021/11/some-post.html
With content<link rel="stylesheet" href="{{ "style.css"|a }}">
Will be rendered as
"../../../../style.css"
See also the
<base>
element
Additional Jinja2 variables
-
page
is asssimp.generators.html.Page
, it contains many information about the current document. Markdown files are an instance ofsssimp.generators.markdown.MarkdownPage
instead, which inherits fromPage
This variable itself contains many useful variables:
-
page.last_modified
andpage.created_at
(may be the same on Linux) -
page.href
: The path to the file relative to the output folder -
page.src
: Apathlib.Path
object of the source file in the input folder -
page.target
Apathlib.Path
object of the target file in the output folder -
page.name
: Shortcut forpage.target.name
, the filename of the outputed file -
page.parent
: Shortcut forpage.target.parent
, the name of the parent directory in the output folder file -
page.meta
: The Markdown meta variables, prefixing a var with=
will interpret it as raw JSON Example--- some_var: some value something_else: 42 some_tags:= ["tag1", "tag2"] --- My cool blog post ...
The meta variable will always contain a
template
which will resolve to the parent directory name with .html appended if none is set in the meta fields.The
page.meta
variable isNone
for raw HTML pages, this avoids KeyErrors when trying to filter pages by a specific meta variable.
-
-
plain_text
[^md]: A plain text representation of the Markdown file -
markdown
[^md]: The Markdown content converted to HTML -
meta
[^md]: A shortcut forpage.meta
-
title
[^md]: Returnspage.meta.title
if it exists, else the filename with the characters-
and_
replaced by whitespaces, the suffix removed and the first letter capitalized.Example:
input/content/some-cool-page.md
's title is "Some cool page" -
BUNDLE_FILE
always evaluates to"bundle.css"
for now -
BUNDLE_TIME
modification time of the latest updated file ininput/css
, very useful to make the browser refresh the file only if any of the CSS files changed.Example:
<link rel="stylesheet" href="{{ BUNDLE_FILE}}?{{ BUNDLE_TIME }}">
-
PAGES
a list ofsssimp.generators.html.Page
objects containing every HTML and Markdown files sourced by the site. You can loop over it to generate an index. In conjunction with looking up meta values it can be used to filter by content type.Example:
{% for page in PAGES if page.meta.template == 'post.html' %} <a href="{{ page.href }}">{{ page.title }}</a> <div class="tags"> {% for tag in page.meta.tags %} <span class="tag">{{ tag }}</span> {% endfor %} </div> Posted on <time>{{ page.created_at }}</time> {% endfor %}
[^md]: Markdown only
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sssimp-0.0.9.tar.gz
.
File metadata
- Download URL: sssimp-0.0.9.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd6ef9fdff181783d56c7f9c017267b0b22935aef2a007384f4ea97df4853824 |
|
MD5 | 7cd5f0e5dab4756800dcdcfc5fa9510f |
|
BLAKE2b-256 | 28cfebae460cbb3b2612e4abb8fb5a810b051683cf9d3d40bcd9070c6e3be13c |
File details
Details for the file sssimp-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: sssimp-0.0.9-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 850aa3662f9e75e21b0591e9243805b30706709d4564f003cd049434344525e4 |
|
MD5 | 77c477703cf11db40514686e2a9f8e9a |
|
BLAKE2b-256 | f3f0e30e31e717e45482dca2ccf7979787bf44ad5e7c08ab9d673281a0d06601 |