Added a custom package to inject datetime in templates
Modified blog pagination filter to show only posts which pubdate is less or equal than today's date.
This commit is contained in:
parent
16b4e652bf
commit
faf958c401
4 changed files with 34 additions and 0 deletions
|
@ -12,3 +12,4 @@ slug_format = {{ (this.pub_date|dateformat('YYYY/MM/dd/') if this.pub_date) ~ "-
|
||||||
[pagination]
|
[pagination]
|
||||||
enabled = yes
|
enabled = yes
|
||||||
per_page = 4
|
per_page = 4
|
||||||
|
items = this.children.filter(F.pub_date <= datetime.date.today())
|
||||||
|
|
5
packages/template-datetime/.gitignore
vendored
Normal file
5
packages/template-datetime/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.egg-info
|
13
packages/template-datetime/lektor_template_datetime.py
Normal file
13
packages/template-datetime/lektor_template_datetime.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
|
from lektor.pluginsystem import Plugin
|
||||||
|
|
||||||
|
|
||||||
|
class TemplateDatetimePlugin(Plugin):
|
||||||
|
name = u'template-datetime'
|
||||||
|
description = u'Adds the datetime package to the template context'
|
||||||
|
|
||||||
|
def on_process_template_context(self, context, **extra):
|
||||||
|
context['datetime'] = datetime
|
15
packages/template-datetime/setup.py
Normal file
15
packages/template-datetime/setup.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='lektor-template-datetime',
|
||||||
|
version='0.1',
|
||||||
|
author=u'Felipe Martin',
|
||||||
|
author_email='me@fmartingr.com',
|
||||||
|
license='MIT',
|
||||||
|
py_modules=['lektor_template_datetime'],
|
||||||
|
entry_points={
|
||||||
|
'lektor.plugins': [
|
||||||
|
'template-datetime = lektor_template_datetime:TemplateDatetimePlugin',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue