6

[Pelican] Add Build Timestamp to Pelican Site Automatically

 2 years ago
source link: https://siongui.github.io/2020/11/30/auto-add-build-timestamp-to-pelican-website/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[Pelican] Add Build Timestamp to Pelican Site Automatically

November 30, 2020

When we generate the website using Python Pelican static site generator, we may want to add "Last Updated" time to our website at the footer or somewhere else automatically. This post will show you how to do it.

In pelicanconf.py, add following code:

from datetime import datetime
import pytz

# modify TIMEZONE to your timezone
TIMEZONE = 'Asia/Taipei'
BUILD_TIME = datetime.now(pytz.timezone(TIMEZONE))

In the template html, you can use the BUILD_TIME as follows:

Last Updated: {{ BUILD_TIME | strftime("%b %d, %Y, %H:%M:%S") }} ({{ TIMEZONE }})

If you do not know about Python strftime, check this post.

Tested on: Ubuntu Linux 20.04, Python 3.8.5.


References:

[2]How to keep your copyright year up-to-date • bernhard.scheirle.de[3]python - Print the last modification of a jinja2 template in pelican - Stack Overflow[4]How do I get a value of datetime.today() in Python that is "timezone aware"? - Stack Overflow


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK