The Static Site Solution In Modern Python
Project description
sssimp 🐍
The Static Site Solution In Modern Python
It's simp with 3 s!
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.
One of the main goals with sssimp is being able to generate a usable website without any configuration file or dependency. You only install the sssimp package and run it.
Installing
Requirement: Python 3.8 or later
pip install --user sssimp
How to use
Create a folder called input, it will hold the data to generate the site.
Running sssimp will generate content in the output folder.
Input and output destination can be changed:
sssimp --input ../some-other/input-dir ~/some-other/output-dir
Use python -m sssimp --help for more details.
Generators
-
Files placed in
input/contentwill be directly copied to theoutputfolderExample:
input/content/favicon.png->output/favicon.png -
HTML files with the suffix .html placed in
input/contentwill be parsed as Jinja2 templates, they can use templates defined ininput/templates. See the Jinja2 documentationExample:
input/content/index.html->output/index.htmlStarting with content{% extends "base.html" %} ...Will use the template
input/templates/base.html -
CSS files in
input/csswill be merged together in a single fileoutput/bundle.css -
Markdown files with the suffix .md placed in
input/contentwill be parsed to HTML and passed to a template with the same name as their parent folder as the parametermarkdownExample:
./input/content/post/hello-world.md->./output/post/hello-world.htmlUsing the template./input/templates/post.htmlGenerated 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.htmlStarting with content--- template: special.html --- ...
Will use the template
./input/templates/special.htmlinstead ofpost.html -
Files placed in
input/datawill exposes their content in templates inside thedatavariable. They can be in either YAML, JSON, or Markdown. The path is part of their position in the data structure tree.Example:
./input/data/categories/tech.ymlWith contentdescription: Nerdy stuff color: #121212 related: - computers - dev
Will populate the
datavariable in templates as so:{ "categories": [ { "tech": { "description": "Nerdy stuff", "color": "#121212", "related": ["computers", "dev"] } } ] }
Examples
See the examples directory for per-feature examples, or my
personal website https://github.com/Tina-otoge/tina-simp for a real-world
example.
Additional Jinja2 filters
-
|amakes 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.htmlWith content<link rel="stylesheet" href="{{ "style.css"|a }}">
Will be rendered as
"../../../../style.css"See also the
<base>element -
|markdowntransforms Markdown content to HTML using the same process that for Markdown files. -
|jsontransforms any object to a formatted JSON.
Additional Jinja2 variables
-
pageis asssimp.generators.html.Page, it contains many information about the current document. Markdown files are an instance ofsssimp.generators.markdown.MarkdownPageinstead, which inherits fromPageThis variable itself contains many useful variables:
-
page.modified_atandpage.created_at(modified_atforcibly set toNoneif same ascreated_at) -
page.href: The path to the file relative to the output folder -
page.src: Apathlib.Pathobject of the source file in the input folder -
page.targetApathlib.Pathobject 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
templatewhich will resolve to the parent directory name with .html appended if none is set in the meta fields.The
page.metavariable isNonefor 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.titleif 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_FILEalways evaluates to"bundle.css"for now -
BUNDLE_TIMEmodification 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 }}">
-
PAGESa list ofsssimp.generators.html.Pageobjects 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sssimp-0.1.4.tar.gz.
File metadata
- Download URL: sssimp-0.1.4.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8992871a8b32d224e0036be699faedc7b22ee621f5f661103f47c69d0058191a
|
|
| MD5 |
a3c5dd9a1046725232afafa90c4f948d
|
|
| BLAKE2b-256 |
c1754b0373aa667245591924d4d4ffe836a2bedfb447811756c8d5ff8e9d98a0
|
File details
Details for the file sssimp-0.1.4-py3-none-any.whl.
File metadata
- Download URL: sssimp-0.1.4-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68c0432aa7c94399fbb606aa5cdd0e032099eb19a1102f3544d733f170f0244f
|
|
| MD5 |
e10b2ee799d84c8efb02e74aeb48ba52
|
|
| BLAKE2b-256 |
3e63855d401391e24fea3ea3fd043de9a607a39b20d536e3bbd4b8c5bd295322
|