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:
Felipe Martin 2016-12-20 10:08:40 +01:00
parent 16b4e652bf
commit faf958c401
4 changed files with 34 additions and 0 deletions

View File

@ -12,3 +12,4 @@ slug_format = {{ (this.pub_date|dateformat('YYYY/MM/dd/') if this.pub_date) ~ "-
[pagination]
enabled = yes
per_page = 4
items = this.children.filter(F.pub_date <= datetime.date.today())

5
packages/template-datetime/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
dist
build
*.pyc
*.pyo
*.egg-info

View 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

View 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',
]
}
)