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
- How to add a new block?
- How to add a new blog post?
- How to build reusable HTML components?
- ✓ How to implement a custom plugin?
- How to display a list of items?
- How to display a list of links?
- How to add dynamic data to a page with a plugin?
- How to use Stapy on Windows?
- How to host my static website for free?
- How to auto-deploy my website with GitHub Action?
- How to write content in Markdown?
- How to add a JSON feed?
- How to use Stapy with Apache HTTP Server?
- How to update Stapy?