mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Introduce Jinja2 filters for converting links in additional fields.
Until now, the link replacing worked only on article and page
contents or summaries. With this patch, if one needes to replace
links in custom fields, there are two new Jinja2 filters that can do
that. For fields that are referenced in the `FORMATTED_FIELDS` setting,
one can use the `expand_links` Jinja2 filter in the template, passing
the field name as a parameter:
{{ article|expand_links('legal') }}
If the custom field consists of just one link (for example a link to
article cover image for a social meta tag), one can use the
`expand_link` Jinja2 filter:
{{ article|expand_link('cover') }}
With the above being in a template and `FORMATTED_FIELDS` setting
containing the `'legal'` field, a RST article making use of both fields
could look like this:
An article
##########
📅 2017-06-22
:legal: This article is released under `CC0 {filename}/license.rst`.
:cover: {filename}/img/article-cover.jpg
This commit is contained in:
parent
42b205d75c
commit
b4a09947dc
6 changed files with 171 additions and 65 deletions
|
|
@ -5,6 +5,8 @@ Next release
|
|||
============
|
||||
|
||||
* New signal: ``feed_generated``
|
||||
* Introduced ``expand_link`` and ``expand_links`` Jinja2 filters to allow URL
|
||||
replacement in user-defined metadata fields.
|
||||
|
||||
3.7.1 (2017-01-10)
|
||||
==================
|
||||
|
|
|
|||
|
|
@ -202,6 +202,29 @@ and ``article2.md``::
|
|||
[a link relative to the current file]({filename}category/article1.rst)
|
||||
[a link relative to the content root]({filename}/category/article1.rst)
|
||||
|
||||
The link replacing works by default on article and page contents as well as
|
||||
summaries. If you need to replace links in custom formatted fields that are
|
||||
referenced in the ``FORMATTED_FIELDS`` setting, use the ``expand_links``
|
||||
Jinja2 filter in your template, passing the field name as a parameter::
|
||||
|
||||
{{ article|expand_links('legal') }}
|
||||
|
||||
If your custom field consists of just one link (for example a link to article
|
||||
cover image for a social meta tag), use the ``expand_link`` Jinja2 filter::
|
||||
|
||||
{{ article|expand_link('cover') }}
|
||||
|
||||
With the above being in a template and ``FORMATTED_FIELDS`` setting containing
|
||||
the ``'legal'`` field, a RST article making use of both fields could look like
|
||||
this::
|
||||
|
||||
An article
|
||||
##########
|
||||
|
||||
:date: 2017-06-22
|
||||
:legal: This article is released under `CC0 {filename}/license.rst`.
|
||||
:cover: {filename}/img/article-cover.jpg
|
||||
|
||||
Linking to static files
|
||||
-----------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue