/home

Simple Stupid Static Site Generator (S4G) in Python

Yes, this is yet another static site generator.
I use raw python template and markdown syntax with little tweaking.
It has been inspired by this post on Hacker News.

Look at gen.py for details.
I try to keep it simple stupid.

Principles are:

Configuration

Front Matter metadata

Activation of publication

Only .md files with activated publication are generated in the target directory hierarchy.

---
published: yes
---

Custom templage

With the following metadata gen.py will use _template\my_template.html instead of _template\default.html

---
template: my_template
---

PHP generation

As an alternative to the default .html file generation, it is possible to generate a .php file.

---
extension: php
---

Having a php extension allows to include raw php code through oneliner comments. For example:

<!-- php_code: include 'citation.php'; -->

will put

<?php include 'citation.php' ?>

in the php output file.

This is how the dynamic citation of the main index page is done and the citation.php file contains something like:

<div id="citation">
<?php
    $json_str = file_get_contents('citations.json');
    $arr = json_decode($json_str);
    $entry_id = random_int(0, count($arr)-1);
    echo $arr[$entry_id];
?>
</div>

Python add-ons

It is possible to load one addon per markdown file. The following meta-data loads module_name.py from the markdown file directory.

---
addon: module_name
---

Once loaded, it is possible to call functions from this module to generate additional outputs. Currently, it only support generation of markdown outputs through oneliner comments such as:

<!-- markdown_addon: function_name() -->

With markdown_addon it calls function_name within the markdown data before the HTML production.

Python dependencies

For converting markdown .md files to .html I use markdown it py with core plugins (mdit-py-plugins).

Install it using the pip install markdown-it-py[plugins] command.