Create subcollections based on the collection
Project description
Render Engine Subcollections
A plugin system for Render Engine that enables automatic generation of subcollections based on page metadata like tags, dates, categories, and more.
Overview
The subcollections plugin extends Render Engine's Collection and Blog classes with a powerful plugin architecture that automatically processes your content and creates organized subcollections. This makes it easy to generate tag pages, monthly archives, category listings, and any other groupings based on your page metadata.
Features
- Automatic subcollection generation - Group pages by any metadata field
- Built-in processors - Common patterns like tags and monthly archives included
- Plugin architecture - Easy to create custom processors
- Permalink generation - Automatic URL generation for subcollection pages
- Template support - Custom templates for each subcollection type
Installation
pip install render-engine-subcollections
Quick Start
from render_engine import Site, Blog
from render_engine_subcollections import subcollections, tags, monthly_archives
site = Site()
@site.collection
class MyBlog(Blog):
content_path = "content/posts"
# Register the subcollections plugin
plugins = [subcollections]
# Enable subcollection processing
subcollections = [
tags, # Creates tag-based subcollections
monthly_archives, # Creates monthly archive subcollections
]
Usage
Basic Configuration
First, register the subcollections plugin, then use the subcollections attribute to specify processor functions or tuples containing a name and function:
from render_engine_subcollections import subcollections
class MyBlog(Blog):
content_path = "content/posts"
# Register the plugin
plugins = [subcollections]
# Configure subcollections
subcollections = [
("tags", process_tags),
("months", process_months),
("categories", process_categories),
]
Built-in Processors
Tags Processor
Groups pages by their tags metadata field:
from render_engine_subcollections import subcollections, tags
class MyBlog(Blog):
plugins = [subcollections]
subcollections = [tags]
This creates subcollections for each unique tag, accessible at URLs like /tags/python/, /tags/javascript/, etc.
Monthly Archives
Groups pages by their date metadata field into monthly collections:
from render_engine_subcollections import subcollections, monthly_archives
class MyBlog(Blog):
plugins = [subcollections]
subcollections = [monthly_archives]
This creates subcollections for each month, accessible at URLs like /2024/01/, /2024/02/, etc.
Creating Custom Processors
A processor is a function that takes a collection and returns a dictionary mapping subcollection names to lists of pages:
from collections import defaultdict
def process_categories(collection):
"""Group pages by category metadata."""
categories = defaultdict(list)
for page in collection:
if hasattr(page, 'category'):
categories[page.category].append(page)
return categories
def process_authors(collection):
"""Group pages by author metadata."""
authors = defaultdict(list)
for page in collection:
# Handle multiple authors
page_authors = getattr(page, 'authors', [])
if isinstance(page_authors, str):
page_authors = [page_authors]
for author in page_authors:
authors[author].append(page)
return authors
# Use in your blog
from render_engine_subcollections import subcollections
class MyBlog(Blog):
plugins = [subcollections]
subcollections = [
("categories", process_categories),
("authors", process_authors),
]
Advanced Example
from datetime import datetime
from collections import defaultdict
from render_engine_subcollections import subcollections
def process_months(collection):
"""Group pages by month and year."""
month_year = defaultdict(list)
for page in collection:
if hasattr(page, 'date'):
# Parse the date string
if isinstance(page.date, str):
date_obj = datetime.strptime(page.date, "%Y-%m-%d")
else:
date_obj = page.date
# Create month-year key
month_key = date_obj.strftime("%B %Y") # "January 2024"
month_year[month_key].append(page)
return month_year
def process_tags(collection):
"""Group pages by individual tags."""
tags = defaultdict(list)
for page in collection:
page_tags = getattr(page, 'tags', [])
# Handle both string and list formats
if isinstance(page_tags, str):
page_tags = [tag.strip() for tag in page_tags.split(',')]
for tag in page_tags:
tags[tag.lower()].append(page)
return tags
class TechBlog(Blog):
content_path = "content/posts"
template = "post.html"
plugins = [subcollections]
subcollections = [
("tags", process_tags),
("monthly", process_months),
]
Templates
Subcollection Templates
Each subcollection type can have its own template. By default, subcollections use the collection's template, but you can specify custom templates:
# In your processor function
def process_tags(collection):
tags = defaultdict(list)
for page in collection:
for tag in getattr(page, 'tags', []):
tags[tag].append(page)
# Each subcollection can specify its template
return {
tag: {
'pages': pages,
'template': 'tag.html', # Custom template for tag pages
'title': f'Posts tagged with {tag}',
'description': f'All posts about {tag}',
}
for tag, pages in tags.items()
}
Template Variables
Subcollection templates have access to:
pages- List of pages in the subcollectiontitle- Subcollection titlecollection- Parent collection datasubcollection_type- The processor name (e.g., "tags", "months")subcollection_key- The specific subcollection identifier- All collection template*vars prefixed with
collection*(e.g.,collection_site_title,collection_description, etc.)
<!-- tag.html template -->
<h1>{{ title }}</h1>
<p>{{ pages|length }} posts tagged with "{{ subcollection_key }}"</p>
<ul>
{% for post in pages %}
<li>
<a href="{{ post.url_for() }}">{{ post.title }}</a>
<time>{{ post.date }}</time>
</li>
{% endfor %}
</ul>
URL Structure
Subcollections automatically generate URLs based on the collection path, subcollection name, and key:
{collection-path}/{subcollection-name}/{key}/
Examples:
- Tags:
/blog/tags/python/ - Monthly archives:
/blog/monthly/january-2024/ - Categories:
/blog/categories/web-development/
Integration Examples
Complete Blog Setup
from render_engine import Site, Blog
from render_engine_subcollections import tags, monthly_archives, subcollections
site = Site(
SITE_TITLE="My Tech Blog",
SITE_URL="https://example.com"
)
@site.collection
class Posts(Blog):
content_path = "content/posts"
template = "post.html"
archive_template = "archive.html"
has_archive = True
plugins = [subcollections]
subcollections = [
tags,
monthly_archives,
]
@site.page
class TagIndex:
"""Index page listing all tags"""
template = "tag-index.html"
def tags(self):
# Access processed tags from the blog
return site.collections['Posts'].subcollections.get('tags', {})
if __name__ == "__main__":
site.render()
Multi-language Blog
def process_languages(collection):
"""Group posts by language."""
languages = defaultdict(list)
for page in collection:
lang = getattr(page, 'language', 'en')
languages[lang].append(page)
return languages
from render_engine_subcollections import subcollections
class MultilangBlog(Blog):
plugins = [subcollections]
subcollections = [
("languages", process_languages),
("tags", process_tags),
]
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Projects
- Render Engine - The main static site generator
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file render_engine_subcollections-2025.6.1.tar.gz.
File metadata
- Download URL: render_engine_subcollections-2025.6.1.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8edb188158cd24c9536f59ff41d743ed081ce9218fab0ae366fd6df6f8385bfc
|
|
| MD5 |
fe6e220ad551be09509da837d39a079d
|
|
| BLAKE2b-256 |
590e35e6f1213ce2e6afc681a0e65a67bc9ef3b05f15648567c0d3a02daf1b0e
|
Provenance
The following attestation bundles were made for render_engine_subcollections-2025.6.1.tar.gz:
Publisher:
publish.yml on render-engine/render-engine-subcollections
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
render_engine_subcollections-2025.6.1.tar.gz -
Subject digest:
8edb188158cd24c9536f59ff41d743ed081ce9218fab0ae366fd6df6f8385bfc - Sigstore transparency entry: 245675421
- Sigstore integration time:
-
Permalink:
render-engine/render-engine-subcollections@e9e507b0aac5cbb26564defa03d047e1d9bc4143 -
Branch / Tag:
refs/tags/2025.6.1 - Owner: https://github.com/render-engine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e9e507b0aac5cbb26564defa03d047e1d9bc4143 -
Trigger Event:
release
-
Statement type:
File details
Details for the file render_engine_subcollections-2025.6.1-py3-none-any.whl.
File metadata
- Download URL: render_engine_subcollections-2025.6.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baeba071cb08c02f2352703356b0193b19457fac4488f35ed6596b79350c4dc0
|
|
| MD5 |
d35cca34111fbcc0dc027875c0e99f56
|
|
| BLAKE2b-256 |
6544aadd284fa73b1407af4f0864ce568082d37466b981e27b43890699f3bf5c
|
Provenance
The following attestation bundles were made for render_engine_subcollections-2025.6.1-py3-none-any.whl:
Publisher:
publish.yml on render-engine/render-engine-subcollections
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
render_engine_subcollections-2025.6.1-py3-none-any.whl -
Subject digest:
baeba071cb08c02f2352703356b0193b19457fac4488f35ed6596b79350c4dc0 - Sigstore transparency entry: 245675422
- Sigstore integration time:
-
Permalink:
render-engine/render-engine-subcollections@e9e507b0aac5cbb26564defa03d047e1d9bc4143 -
Branch / Tag:
refs/tags/2025.6.1 - Owner: https://github.com/render-engine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e9e507b0aac5cbb26564defa03d047e1d9bc4143 -
Trigger Event:
release
-
Statement type: