Functions
register
Register taxonomy helper functions with Jinja2 environment.
register
def register(env: Environment, site: Site) -> None
Register taxonomy helper functions with Jinja2 environment.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
env |
Environment |
— | |
site |
Site |
— |
related_posts
Find related posts based on shared tags.
PERFORMANCE NOTE: This function now uses pre-computed rel…
related_posts
def related_posts(page: Any, all_pages: list[Any] | None = None, limit: int = 5) -> list[Any]
Find related posts based on shared tags.
PERFORMANCE NOTE: This function now uses pre-computed related posts for O(1) access. The old O(n²) algorithm is kept as a fallback for backward compatibility with custom templates.
RECOMMENDED: Usepage.related_postsdirectly in templates instead
of calling this function.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
page |
Any |
— | Current page |
all_pages |
list[Any] | None |
None |
All site pages (optional, only needed for fallback) |
limit |
int |
5 |
Maximum number of related posts |
Returns
List of related pages sorted by relevance Example (NEW - recommended):
{% set related = page.related_posts[:3] %} Example (OLD - backward compatible):
{% set related = related_posts(page, limit=3) %}
{% for post in related %}
<a href="{{ url_for(post) }}">{{ post.title }}</a>
{% endfor %}list[Any]
—
popular_tags
Get most popular tags sorted by count.
popular_tags
def popular_tags(tags_dict: dict[str, list[Any]], limit: int = 10) -> list[tuple[str, int]]
Get most popular tags sorted by count.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
tags_dict |
dict[str, list[Any]] |
— | Dictionary of tag -> pages |
limit |
int |
10 |
Maximum number of tags |
Returns
List of (tag, count) tupleslist[tuple[str, int]]
—
tag_url
Generate URL for a tag page.
Uses bengal.utils.text.slugify for tag slug generation.
tag_url
def tag_url(tag: str) -> str
Generate URL for a tag page.
Uses bengal.utils.text.slugify for tag slug generation.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
tag |
str |
— | Tag name |
Returns
URL path to tag pagestr
—
has_tag
Check if page has a specific tag.
has_tag
def has_tag(page: Any, tag: str) -> bool
Check if page has a specific tag.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
page |
Any |
— | Page to check |
tag |
str |
— | Tag to look for |
Returns
True if page has the tagbool
—