Skip to main content

more-categories

Build Status

This plugin adds support for multiple categories per article, and for nested categories. It requires Pelican 4.0.0 or newer.

Multiple categories

To indicate that an article belongs to multiple categories, use a comma-separated string:

Category: foo, bar, bazz

This will add the article to the categories foo, bar and bazz.

Templates

Existing themes that use article.category will display only the first of these categories, foo. This plugin adds article.categories that you can loop over instead. To accomodate this plugin in a theme whether it is present or not, use:

{% for cat in article.categories or [article.category] %}
    <a href="{{ SITEURL }}/{{ cat.url }}">{{ cat }}</a>{{ ', ' if not loop.last }}
{% endfor %}

Nested categories

(This is a reimplementation of the subcategory plugin.)

To indicate that a category is a child of another category, use a slash-separated string:

Category: foo/bar/bazz

This will add the article to the categories foo/bar/bazz, foo/bar and foo.

Templates

Existing themes that use article.category will display the full path to the most specific of these categories, foo/bar/bazz. For any category cat, this plugin adds cat.shortname, which in this case is bazz, cat.parent, which in this case is the category foo/bar, and cat.ancestors, which is a list of the category's ancestors, ending with the category itself. For instance, to also include a link to each of the ancestor categories on an article page, in case this plugin in present, use:

{% for cat in article.category.ancestors or [article.category] %}
    <a href="{{ SITEURL }}/{{ cat.url }}">{{ cat.shortname or cat }}</a>{{ '/' if not loop.last }}
{% endfor %}

Likewise, category.shortname, category.parent and category.ancestors can also be used on the category template.

Additionally, this plugin adds category.children: a list of categories that have category as a parent.

{% for child in category.children %}
    <a href="{{ SITEURL }}/{{child.url}}">{{child.shortname|capitalize}}</a>
{% endfor %}

If you need all descendents and not just the immediate children, you can use the list of descendents: category.descendents.

Slug

The slug of a category is generated recursively by slugifying the shortname of the category and its ancestors, and preserving slashes:

slug-of-(foo/bar/baz) := slug-of-foo/slug-of-bar/slug-of-baz

Category folders

To specify categories using the directory structure, you can configure PATH_METADATA to extract the article path into the category metadata. The following settings would use the entire structure:

PATH_METADATA = '(?P<category>.*)/.*'

If you store all articles in a single articles/ folder that you want to ignore for this purpose, use:

PATH_METADATA = 'articles/(?P<category>.*)/.*'

Categories in templates

The list categories of all pairs of categories with their corresponding articles, which is available in the context and can be used in templates (e.g. to make a menu of available categories), is ordered lexicographically, so categories always follow their parent:

aba
aba/dat
abaala

Release files for pelican-more-categories 0.1.0

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-more-categories 0.1.0
File Size Uploaded
pelican-more-categories-0.1.0.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pelican-more-categories 0.1.0
File Interpreter ABI Platform
pelican_more_categories-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.1 kB

Release files / pelican-more-categories-0.1.0.tar.gz

Download URL pelican-more-categories-0.1.0.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fe8440db77e52cba6511228b1a7e8b0b84618e9587a05fc5186f118e6243008a
BLAKE2b-256 checksum
How to use checksums
1f6f4032705412fd8afd9868e868e055a061da2ff3fb02ec37cddfc92a617c8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.7 Linux/5.3.0-1022-azure

Release files / pelican_more_categories-0.1.0-py3-none-any.whl

Download URL pelican_more_categories-0.1.0-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d8e424a88f39f4186f9c91587e8e11353fb89054d0cf92a9ef419986386473e
BLAKE2b-256 checksum
How to use checksums
c424e32de438b861f729ecebf9dc49f8ad8c85ca1fec8ce45371430a8b87e721
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.7 Linux/5.3.0-1022-azure

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.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