Functions
register
Register collection functions with Jinja2 environment.
register
def register(env: Environment, site: Site) -> None
Register collection functions with Jinja2 environment.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
env |
Environment |
— | |
site |
Site |
— |
_get_nested_value
Get nested value using dot notation (e.g., 'metadata.track_id').
_get_nested_value
def _get_nested_value(obj: Any, path: str) -> Any
Get nested value using dot notation (e.g., 'metadata.track_id').
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
obj |
Any |
— | |
path |
str |
— |
Returns
Any
where
Filter items where key matches value using specified operator.
Supports nested attribute access (e…
where
def where(items: list[dict[str, Any]], key: str, value: Any = None, operator: str = 'eq') -> list[dict[str, Any]]
Filter items where key matches value using specified operator.
Supports nested attribute access (e.g., 'metadata.track_id') and comparison operators.
Parameters 4
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[dict[str, Any]] |
— | List of dictionaries or objects to filter |
key |
str |
— | Dictionary key or attribute path to check (supports dot notation like 'metadata.track_id') |
value |
Any |
None |
Value to compare against (required for all operators) |
operator |
str |
'eq' |
Comparison operator: 'eq' (default), 'ne', 'gt', 'gte', 'lt', 'lte', 'in', 'not in' |
Returns
Filtered listlist[dict[str, Any]]
—
where_not
Filter items where key does not equal value.
Supports nested attribute access (e.g., 'metadata.tra…
where_not
def where_not(items: list[dict[str, Any]], key: str, value: Any) -> list[dict[str, Any]]
Filter items where key does not equal value.
Supports nested attribute access (e.g., 'metadata.track_id').
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[dict[str, Any]] |
— | List of dictionaries or objects to filter |
key |
str |
— | Dictionary key or attribute path to check (supports dot notation like 'metadata.track_id') |
value |
Any |
— | Value to exclude |
Returns
Filtered listlist[dict[str, Any]]
—
group_by
Group items by key value.
group_by
def group_by(items: list[dict[str, Any]], key: str) -> dict[Any, list[dict[str, Any]]]
Group items by key value.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[dict[str, Any]] |
— | List of dictionaries to group |
key |
str |
— | Dictionary key to group by |
Returns
Dictionary mapping key values to lists of itemsdict[Any, list[dict[str, Any]]]
—
sort_by
Sort items by key.
sort_by
def sort_by(items: list[Any], key: str, reverse: bool = False) -> list[Any]
Sort items by key.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[Any] |
— | List to sort |
key |
str |
— | Dictionary key or object attribute to sort by |
reverse |
bool |
False |
Sort in descending order (default: False) |
Returns
Sorted listlist[Any]
—
limit
Limit items to specified count.
limit
def limit(items: list[Any], count: int) -> list[Any]
Limit items to specified count.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[Any] |
— | List to limit |
count |
int |
— | Maximum number of items |
Returns
First N itemslist[Any]
—
offset
Skip first N items.
offset
def offset(items: list[Any], count: int) -> list[Any]
Skip first N items.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[Any] |
— | List to skip from |
count |
int |
— | Number of items to skip |
Returns
Items after offsetlist[Any]
—
uniq
Remove duplicate items while preserving order.
uniq
def uniq(items: list[Any]) -> list[Any]
Remove duplicate items while preserving order.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[Any] |
— | List with potential duplicates |
Returns
List with duplicates removedlist[Any]
—
flatten
Flatten nested lists into single list.
Only flattens one level deep.
flatten
def flatten(items: list[list[Any]]) -> list[Any]
Flatten nested lists into single list.
Only flattens one level deep.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[list[Any]] |
— | List of lists |
Returns
Flattened listlist[Any]
—
first
Get first item from list.
first
def first(items: list[Any]) -> Any
Get first item from list.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[Any] |
— | List to get first item from |
Returns
First item or None if list is emptyAny
—
last
Get last item from list.
last
def last(items: list[Any]) -> Any
Get last item from list.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[Any] |
— | List to get last item from |
Returns
Last item or None if list is emptyAny
—
reverse
Reverse a list.
reverse
def reverse(items: list[Any]) -> list[Any]
Reverse a list.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
items |
list[Any] |
— | List to reverse |
Returns
Reversed copy of listlist[Any]
—
_get_item_key
Get unique key for an item (for set operations).
_get_item_key
def _get_item_key(item: Any) -> Any
Get unique key for an item (for set operations).
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
item |
Any |
— |
Returns
Any
union
Combine two lists, removing duplicates (set union).
Preserves order from first list, then adds ite…
union
def union(items1: list[Any], items2: list[Any]) -> list[Any]
Combine two lists, removing duplicates (set union).
Preserves order from first list, then adds items from second list that aren't already present.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
items1 |
list[Any] |
— | First list |
items2 |
list[Any] |
— | Second list |
Returns
Combined list with duplicates removedlist[Any]
—
intersect
Get items that appear in both lists (set intersection).
intersect
def intersect(items1: list[Any], items2: list[Any]) -> list[Any]
Get items that appear in both lists (set intersection).
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
items1 |
list[Any] |
— | First list |
items2 |
list[Any] |
— | Second list |
Returns
List of items present in both listslist[Any]
—
complement
Get items in first list that are not in second list (set difference).
complement
def complement(items1: list[Any], items2: list[Any]) -> list[Any]
Get items in first list that are not in second list (set difference).
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
items1 |
list[Any] |
— | First list (items to keep) |
items2 |
list[Any] |
— | Second list (items to exclude) |
Returns
List of items in first list but not in second listlist[Any]
—
resolve_pages
Resolve page paths to Page objects.
Used with query indexes to convert O(1) path lookups into Page…
resolve_pages
def resolve_pages(page_paths: list[str], site: Site) -> list[Any]
Resolve page paths to Page objects.
Used with query indexes to convert O(1) path lookups into Page objects: {% set blog_paths = site.indexes.section.get('blog') %} {% set blog_pages = blog_paths | resolve_pages %}
PERFORMANCE: Uses cached page path map from Site for O(1) lookups. The cache is automatically invalidated when pages are added/removed.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
page_paths |
list[str] |
— | List of page source paths (strings) |
site |
Site |
— | Site instance with pages |
Returns
List of Page objectslist[Any]
—