Skip to main content

Enables nested categories and multiple categories per article

Project description

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican-more-categories-0.0.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

pelican_more_categories-0.0.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file pelican-more-categories-0.0.0.tar.gz.

File metadata

  • Download URL: pelican-more-categories-0.0.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0b4 CPython/3.8.0 Linux/5.0.0-38-generic

File hashes

Hashes for pelican-more-categories-0.0.0.tar.gz
Algorithm Hash digest
SHA256 69a2c2e802352a51fb0b023d5d6be1d4eaea60a800141ab32c3a615e01882517
MD5 8d597c8263a2d659a72f8cd079f6857c
BLAKE2b-256 86691f4804356eda819e9bde8b1308c70003dab9f13c3ba3bb00fd38318903a1

See more details on using hashes here.

File details

Details for the file pelican_more_categories-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pelican_more_categories-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ac9f4d5d90d466c32a5b6dfc3fe597f5d22491e0b8e65d17c05d1c04d77835d
MD5 bdaf7a0f561b016c173acc2ef3625d3b
BLAKE2b-256 1d3595b2ebb960be68f09d3f77f96805f0c5556b7d7f70b76c77d0858535f086

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page