Skip to main content

simple & flexible SSG

Project description

DB69894C-2EEF-4D2F-AFB8-028A4D9DE74A

tanuky: simple & flexible SSG

Description

This is a simple SSG (Static Site Generator) written in Python.
Unlike other common SSGs, this tool provides only minimal functionality.
It generates a site based on a template and markdown, that's all.
Therefore, all the possibilities of the site that can be created are left to the designer.

Installation

From pypi (recommended):

pip install tanuky

If you want the latest commit:

pip install git+https://github.com/laddge/tanuky

From source:

git clone https://github.com/laddge/tanuky ./tanuky
cd tanuky
python setup.py install

Usage

File placement

.
├── dist # distdir
├── src # srcdir
│   ├── css
│   │   └── style.css
│   ├── images
│   │   └── dog.jpeg
│   ├── js
│   │   └── main.js
│   ├── pages
│   │   └── example.md
│   ├── .build
│   │   └── hoge.txt
│   └── index.html
├── templates # tpldir
│   └── hoge.html
└── generate.py
  • distdir (default: ./dist)
    Generated files are placed here.
    Overwritten each times.

  • srcdir (default: ./src)
    Put source files here.

  • tpldir (default: ./templates)
    Put templates here.
    Template files must be named {template_name}.html.

After generated:

./dist # distdir
├── css
│   └── style.css
├── images
│   └── dog.jpeg
├── js
│   └── main.js
├── pages
│   └── example.html
└── index.html

Like this, Markdown is converted to HTML and other files are copied exactly as they are.
Dotted files and dirs are NOT copied.

How to write Markdown

ex:

---
Template: hoge
Title: Hoge Fuga
Desc: test page
---

# Test page
hoge...
  • Front matter
    Write page config between "---" in Yaml.
    Its value passed to the template.

  • Template name
    Template name must be defined in Front matter.
    And, respective template file must be in tpldir.

  • Markdown sentences
    Markdown sentences are convert to HTML and passed to template as "Body".

How to write templates

ex:

<!DOCTYPE html>
<html>
    <head>
        <meta name="description" content="{{ Desc }}">
        <title>{{ Title }}</title>
    </head>
    <body>
        {{ Body }}
    </body>
</html>

Tanuky uses template engine Jinja2.
Variables defined in Front matter can be used in template.
{{ Body }} shows contents which is converted from Markdown.

Generator script

# generate.py
import tanuky

tnk = tanuky.Tanuky()
tnk.generate()

The generator works with just this script.

  • tnk = tanuky.Tanuky()
    Define the generator object.
    You can specify srcdir, tpldir, distdir like this:
    tnk = tanuky.Tanuky(srcdir="./src", tpldir="./templates", distdir="./dist")

  • tnk.generate()
    Start generate process.

Advanced

Include other templates

ex:

  • templates/header.html
<header>
    <a href="/">{{ Title }}</a>
</header>
  • templates/page.html
<!DOCTYPE html>
<html>
    <head>
        <meta name="description" content="{{ Desc }}">
        <title>{{ Title }}</title>
    </head>
    <body>
        {% include "header.html" %}
        {{ Body }}
    </body>
</html>

You can include other templates using {% include "{template_name}.html" %}.

Define globals

ex:

# generate.py
import tanuky

tnk = tanuky.Tanuky()


def func(arg):
    return f"Arg: {arg}"


hoge = "test var"
tnk.globals.update(func=func)
tnk.globals.update(hoge=hoge)
tnk.generate()

You can define global variables or functions using tnk.globals.update().
They are refered in templates like variables defined in Front matter, and they have lower priority than Front matter.

Custom Markdown converter

By default, tanuky uses Python-Markdown as Markdown converter.
If you want to use another converter, use this:

# generate.py
import tanuky


class MyTanuky(tanuky.Tanuky):
    def mkhtml(self, mdbody):
        # convert mdbody to html
        return html


tnk = MyTanuky()
tnk.generate()

Example

An example is available on laddge/tanuky-example.

Release Note

v1.3.1 (2022/03/31)

Fix Markdown parser

v1.3.0 (2022/03/30)

Remove handler feature

v1.2.3 (2022/03/29)

Fix url of MdDoc object

v1.2.2 (2022/03/29)

Fix error

v1.2.1 (2022/03/29)

Provide Markdown list

v1.2.0 (2022/03/29)

Add handler

v1.1.0 (2022/03/28)

Use Jinja2 environment
This update allows you to use all the features of Jinja2

v1.0.3 (2022/03/28)

Move example tree to another repo

v1.0.2 (2022/03/25)

Add example tree

v1.0.1 (2022/03/24)

Fix install bug

v1.0.0 (2022/03/24)

First release

License

This project is under the MIT-License.
See also LICENSE.

Author

Laddge

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tanuky-1.3.1.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

tanuky-1.3.1-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page