Feat: activate always_modified plugin
This commit is contained in:
parent
c7ecf06733
commit
ba64771efb
@ -41,9 +41,12 @@ PLUGIN_PATHS = ["plugins"]
|
|||||||
PLUGINS = [
|
PLUGINS = [
|
||||||
'i18n_subsites',
|
'i18n_subsites',
|
||||||
"pelican-page-hierarchy",
|
"pelican-page-hierarchy",
|
||||||
|
"always_modified",
|
||||||
# 'pdf-img',
|
# 'pdf-img',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ALWAYS_MODIFIED = True
|
||||||
|
|
||||||
# Mirror source structure
|
# Mirror source structure
|
||||||
PATH_METADATA = '(?P<path_no_ext>.*)\..*'
|
PATH_METADATA = '(?P<path_no_ext>.*)\..*'
|
||||||
ARTICLE_URL = ARTICLE_SAVE_AS = PAGE_URL = PAGE_SAVE_AS = '{path_no_ext}.html'
|
ARTICLE_URL = ARTICLE_SAVE_AS = PAGE_URL = PAGE_SAVE_AS = '{path_no_ext}.html'
|
||||||
|
1
plugins/__init__.py
Normal file
1
plugins/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .always_modified import *
|
20
plugins/always_modified.py
Normal file
20
plugins/always_modified.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
def add_modified(content):
|
||||||
|
if not isinstance(content, Article):
|
||||||
|
return
|
||||||
|
|
||||||
|
if not content.settings.get('ALWAYS_MODIFIED', False):
|
||||||
|
return
|
||||||
|
|
||||||
|
if hasattr(content, 'date') and not hasattr(content, 'modified'):
|
||||||
|
content.modified = content.date
|
||||||
|
content.locale_modified = content.locale_date
|
||||||
|
|
||||||
|
def register():
|
||||||
|
signals.content_object_init.connect(add_modified)
|
14
plugins/always_modified/README.md
Normal file
14
plugins/always_modified/README.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Always Modified
|
||||||
|
|
||||||
|
Say you want to sort by modified date/time in a theme template, but not all
|
||||||
|
your articles have modified date/timestamps explicitly defined in article
|
||||||
|
metadata. This plugin facilitates that sorting by assuming the modified date
|
||||||
|
(if undefined) is equal to the created date.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
1. Add `ALWAYS_MODIFIED = True` to your settings file.
|
||||||
|
2. Now you can sort by modified date in your templates:
|
||||||
|
|
||||||
|
{% for article in articles|sort(reverse=True,attribute='modified') %}
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{% for article in articles_page.object_list %}
|
{% for article in articles_page.object_list | sort(reverse=True,attribute='modified') %}
|
||||||
<article>
|
<article>
|
||||||
<header>
|
<header>
|
||||||
<h2><a href="{{ SITEURL }}/{{ article.url }}{% if not DISABLE_URL_HASH %}#{{ article.slug }}{% endif %}">{{ article.title }}</a></h2>
|
<h2><a href="{{ SITEURL }}/{{ article.url }}{% if not DISABLE_URL_HASH %}#{{ article.slug }}{% endif %}">{{ article.title }}</a></h2>
|
||||||
|
Loading…
Reference in New Issue
Block a user