site_opytex/plugins/always_modified.py

23 lines
573 B
Python
Raw Permalink Normal View History

2020-06-26 08:25:33 +00:00
"""
If "modified" date/time is not defined in article metadata, fall back to the "created" date.
"""
from pelican import signals
from pelican.contents import Content, Article
2023-04-14 11:57:39 +00:00
2020-06-26 08:25:33 +00:00
def add_modified(content):
if not isinstance(content, Article):
return
2023-04-14 11:57:39 +00:00
if not content.settings.get("ALWAYS_MODIFIED", False):
2020-06-26 08:25:33 +00:00
return
2023-04-14 11:57:39 +00:00
if hasattr(content, "date") and not hasattr(content, "modified"):
2020-06-26 08:25:33 +00:00
content.modified = content.date
content.locale_modified = content.locale_date
2023-04-14 11:57:39 +00:00
2020-06-26 08:25:33 +00:00
def register():
signals.content_object_init.connect(add_modified)