Static Site Generator

How-to: How to implement a custom plugin?

How to implement a custom plugin?

We add a plugin to display the last build date in the footer.

Step 1

Create a new script in the plugins directory:

plugins
+------ build_date.py

Step 2

Add a method that returns today's date:

from datetime import datetime


def now(data: dict, args: dict) -> str:
    if 'format' not in args:
        args['format'] = '%B %d, %Y at %H:%M'
    return datetime.now().strftime(args['format'])

Step 3

Call the plugin method in any template file:

<p>
    Last refresh: {: build_date.now :}
</p>

Update the default date format with an option:

<p>
    Last refresh: {: build_date.now format:"%m/%d/%Y %H:%M" :}
</p>

Next