Skip to main content

Build Status PyPI Version

Jinja Filters is a plugin for Pelican, a static site generator written in Python.

Jinja Filters provides a selection of functions (called filters) for templates to use when building your website. They are packaged for Pelican, but may prove useful for other projects that make use of Jinja2.

Installation

The easiest way to install Jinja Filters is through the use of Pip. This will also install the required dependencies (currently pelican and titlecase) automatically.

pip install pelican-jinja-filters

As Jinja Filters is a namespace plugin, assuming you are using Pelican 4.5 (or newer) and only other namespace plugins, Jinja Filters will be automatically be loaded by Pelican. And that’s it!

If you are using an older version of Pelican, or non-namespace plugins, you may need to add Jinja Filters to your pelicanconf.py:

PLUGINS = [
    # others...
    "pelican.plugins.jinja_filters",
]

The filters are now available for use in your templates.

Jinja Filters supports Pelican from version 3 on.

Usage

At present, the plugin includes the following filters:

  • datetime – allows you to change to format displayed for a datetime object. Optionally supply a datetime format string to get a custom format.

  • article_date – a specialized version of datetime that returns datetimes as wanted for article dates; specifically Friday, November 4, 2020.

  • breaking_spaces – replaces non-breaking spaces (HTML code  ) with normal spaces.

  • titlecase – Titlecases the supplied string.

  • datetime_from_period – take the period provided on period archive pages, and turn it into a proper datetime.datetime object (likely to feed to another filter)

  • merge_date_url – given a datetime (on the left) and a supplied URL, “apply” the date to it. Envisioned in particular for YEAR_ARCHIVE_URL, MONTH_ARCHIVE_URL, and DAY_ARCHIVE_URL.

For example, within your theme templates, you might have code like:

<span class="published">
    Article Published {{ article.date | article_date }}
</span>

gives:

Article Published Friday, November 4, 2020

Or with your own date format:

<span class="published">
    Article Published {{ article.date | datetime('%b %d, %Y') }}
</span>

gives:

Article Published Nov 04, 2020

Filters can also be chained, or applied in sequence. For example to remove breaking spaces and then titlecase a category name, you might have code like:

<a href="{{ SITEURL -}} / {{- article.category.url }}">
    {{ article.category | breaking_spaces | titlecase }}
</a>

On a Monthly Archive page, you might have the following to link “up” to the Yearly Archive page:

<a href="{{ SITEURL -}} /
         {{- period | datetime_from_period | merge_date_url(YEAR_ARCHIVE_URL) }}">
    {{ period | datetime_from_period | datetime('%Y') }}
</a>

which might give:

<a href="https://blog.minchin.ca/posts/2017/>2017</a>

Contributing

Contributions are most welcome! See Contributing for more details.

To set up a development environment:

  1. Fork the project on GitHub, and then clone your fork.

  2. Set up and activate a virtual environment.

  3. Have invoke on your system path or install it into your virtual environment.

  4. Run invoke setup.

For more details, see Contributing.

License

Jinja Filters is under the MIT License. See attached License.txt for full license text.

Release files for pelican-jinja-filters 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pelican-jinja-filters 2.1.1
File Size Uploaded
pelican-jinja-filters-2.1.1.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pelican-jinja-filters 2.1.1
File Interpreter ABI Platform
pelican_jinja_filters-2.1.1-py3-none-any.whl Python 3 none any Details

Total release size:19.3 kB

Release files / pelican-jinja-filters-2.1.1.tar.gz

Download URL pelican-jinja-filters-2.1.1.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cffa37c566f3e49b9bd1b883e53ff0aa09f7848776213ee2b7c8db68d1030949
BLAKE2b-256 checksum
How to use checksums
75c97f3e96622fb8782493763f53e0a241afa588aec81658308c4fc5c7292df1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.7.11 Linux/5.8.0-1036-azure

Release files / pelican_jinja_filters-2.1.1-py3-none-any.whl

Download URL pelican_jinja_filters-2.1.1-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
124cb738e4850f988f13b05f0000cd4c40fc826b91429f8d480da0fd3a40b18b
BLAKE2b-256 checksum
How to use checksums
1ae4386b18668f8df58177ced6aff06bc13d0e3c27218d34dc6e6935e8f804e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.7.11 Linux/5.8.0-1036-azure

Release history Release notifications | RSS feed

This release

2.1.1 This release

2 release files

2.1.0

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page