Despite being purely static, many sites will want to incorporate some features that appear to be dynamic. "You might also be interested in these other posts..." sections below blog posts are an example of this.
The collections plugin allows you to add posts and pages to an arbitrary number of collections, exhibit these collections on any other page, and generates overview pages automatically.
read full documentationTo add a page to some collections, simply state so in the config of that page:
1 2 3 | collections: - col1 - col2 |
Any page can then exhibit any collection(s):
1 2 3 | exhibits: - col1 - col2 |
A simple jinja-snippet to display all exhibits of a page could look like this:
1 2 3 4 5 6 7 | {% for exhibit in exhibits %} {% for collectible in exhibit %} {{ collectible["title"] }} {{ collectible["preview"] }} {{ collectible["href"] }} {% endfor %} {% endfor %} |
Due to the way exhibiting collections is handled by the plugin, exhibitors might not update right away when you edit or add a page to an exhibited collection. As soon as you exit barely however, the plugin ensures that all pages are properly caught up, so there's no need to rebuild the project.
The collectibles contain the following usable fields, out of which you can build your previews:
title
preview
(summary, if available, the first couple of words, otherwiseraw
(the entire markdown content of the page)href
(link to the page)image
(if title_image was specified on the original page)date
(modification or creation time of the page)reading_time
(as provided by ReadingTime plugin)If you specify an OVERVIEW_TEMPLATE
and/or a COLLECTION_TEMPLATE
, the plugin can also generate these overview pages for you.
COLLECTION_TEMPLATE
is the template used for each individual collection. This is useful for example for blogs, where you want to display the tags/categories a post belongs to (the post's collections) next to the post and link them to a list of all posts from the same tag/category/collection.
OVERVIEW_TEMPLATE
is used only for one page, where all collections can be listed.
By default these pages will be rendered into /categories/
and subdirectories, though this is configurable (see the docs).
Inside the OVERVIEW_TEMPLATE
, list the available collections like this:
1 2 3 4 5 | {% for collection in collections_list %} {{ collection["name"] }} {{ collection["size"] }} {{ collection['href'] }} {% endfor %} |
where the size
is the number of collectibles in the collection.