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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file tanuky-1.3.1.tar.gz.

File metadata

  • Download URL: tanuky-1.3.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for tanuky-1.3.1.tar.gz
Algorithm Hash digest
SHA256 921ca56445fdd379d94d8873d78869df9231085beafb3784c34e64211fd935a9
MD5 9b7fb430bd3bb22da6e87147d6680355
BLAKE2b-256 f552d1cc097a469b8814ea7f084a276897f6c0ef8c0a5532afa83789d91d4738

See more details on using hashes here.

File details

Details for the file tanuky-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: tanuky-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for tanuky-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec0ecead006f3b5dbf533ee629a108dc6d9c58fe8aaa8b58f263cf89aca102ca
MD5 c71d5d11d79708bccb616601492f42e9
BLAKE2b-256 d698493717ffe2f726b6c01cef98844d5984d2a47f813d6bcafd38f5e641f67e

See more details on using hashes here.

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