A Coralite plugin for dynamically collecting, filtering, sorting, and displaying content across multiple sources. Build database-free Coralite websites with automated content aggregation.
The Coralite Aggregation Plugin is a powerful tool designed to help developers dynamically collect, filter, sort, and display content across multiple sources within a Coralite project.
- Installation
- Example
- Type definition
- Custom pager
---
- Content Aggregation: Gather content from multiple files or directories using path patterns (e.g., blog/, ['products/all','blog/']).
- Filtering & Sorting: Use metadata-based filters and custom sort functions to refine results based on attributes like tags, categories, dates, or tokens.
- Pagination Support: Easily create paginated views with customizable templates for navigation controls and visible page links.
- Token Handling: Configure token aliases, defaults, and metadata mapping.
---
``bash`
npm install coralite-plugin-aggregation
:`js
// coralite.config.js
import aggregation from 'coralite-plugin-aggregation'export default {
plugins: [aggregation]
}
`> Note: The plugin must be imported as
'coralite-plugin-aggregation' for compatibility with the core Coralite framework.---
$3
#### Entry Point: Displaying Aggregated Results
Create a file like
coralite-posts.html to define your aggregation logic and rendering template:`html
{{ posts }}
`#### Aggregated Content Files
Each file to be aggregated must include metadata via
elements. For example:`html
Great Barrier Reef
`#### Single Result Template
Define a
element for rendering individual items:`html
{{ $title }}
{{ $description }} - {{ formattedPrice }}
`> Token Syntax: Metadata attributes are accessed in templates as
$. For example, the element is referenced using $title.
$3
####
CoraliteAggregate {#coralite-aggregate}
Configuration object for content aggregation processes. | Property | Type | Description | Reference |
|-----------------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|-----------|
|
path | string[] | Array of paths relative to the pages directory (e.g., ['products', 'blog/']). | - |
| template | CoraliteAggregateTemplate or string | Templates used to display the result. Must match an existing element by ID. | CoraliteAggregateTemplate |
| pagination | Object | Pagination settings (optional). | - |
| filter | CoraliteAggregateFilter | Callback to filter out unwanted elements from the aggregated content. | CoraliteAggregateFilter |
| recursive | boolean | Whether to recursively search subdirectories. | - |
| tokens | CoraliteTokenOptions | Token configuration options (optional). | CoraliteTokenOptions |
| sort | CoraliteAggregateSort | Sort aggregated pages. | CoraliteAggregateSort |
| limit | number | Maximum number of results to retrieve (used with pagination). | - |
| offset | number | Starting index for the results list (used with pagination). | - |---
####
CoraliteAggregateTemplate {#coralite-aggregate-template}
Configuration for templates used to render aggregated results. | Property | Type | Description | Reference |
|----------|-----------|-----------------------------------------------------------------------------|-----------|
|
item | string | Unique identifier for the component used for each document (e.g., 'coralite-post'). | - |---
####
CoraliteTokenOptions {#coralite-token-options}
Configuration options for token handling during processing. | Property | Type | Description |
|--------------|-------------------------------------------------------|-----------------------------------------------------------------------------|
|
default | Object. | Default token values for properties not explicitly set (e.g., { author: 'Anonymous' }). |
| aliases | Object. | Token aliases and their possible values (e.g., { tags: ['tech', 'news'] }). |---
####
CoraliteAggregateFilter {#coralite-aggregate-filter}
Callback function for filtering aggregated content based on metadata. | Parameter | Type | Description |
|---------------|-------------------------------------|-----------------------------------------------------------------------------|
|
metadata | CoraliteToken | Aggregated HTML page metadata (e.g., { name: 'category', content: 'tech' }). |---
####
CoraliteAggregateSort {#coralite-aggregate-sort}
Callback function for sorting aggregated results based on metadata. | Parameter | Type | Description |
|-----------|-------------------------------------|-----------------------------------------------------------------------------|
|
a | Object. | Metadata of the first item being compared (e.g., { date: '2025-01-08' }). |
| b | Object. | Metadata of the second item being compared. |---
####
CoraliteToken {#coralite-token}
A representation of a token with name and value. | Property | Type | Description |
|----------|--------|-----------------------------------------------------------------------------|
|
name | string | Token identifier (e.g., 'title', 'category'). |
| content| string | Token value or content (e.g., 'Great Barrier Reef', 'tech'). |---
Custom Pager Template User Guide for Coralite Pagination Component {#custom-pager}
This guide explains how to create a custom pagination template using the existing
coralite-pagination component as a reference. The goal is to define a new pager layout below the default implementation, preserving compatibility with the core logic while enabling customization.---
$3
Define a unique element for your custom pager. Use an ID distinct from the default (coralite-pagination) to avoid conflicts:`html
{{ paginationList }}
`---
$3
Replace or extend the paginationList token function with your custom logic. The core structure remains compatible with Coralite’s API, but you can modify rendering rules (e.g., ellipsis behavior, link formatting).#### Example: Basic Custom Token Function
`javascript
`---
$3
The pagination template receives these token values:| Property | Description |
|------------------------------|-----------------------------------------------------------------------------|
|
paginationIndexPathname | The index path name for pagination (e.g., /blog/index.html). |
| paginationSegment | The current segment of pagination (e.g., "page"). |
| paginationMaxVisible | Maximum number of visible pages in the pagination UI. |
| paginationProcessed | Indicates whether the pagination has been processed (true/false). |
| paginationOffset | String representation of the offset (used for page calculations). |
| paginationFilePathname | The file path name for pagination context (e.g., /blog/page-2.html). |
| paginationFileDirname | The directory name of the file for pagination context (e.g., /blog). |
| paginationURLPathname | The URL path name used in pagination (e.g., /blog/). |
| paginationURLDirname | The URL directory name used in pagination (e.g., /blog). |
| paginationLength | Total length of the paginated data set (used to determine total page count).|
| paginationCurrent` | Current page index (as a string, e.g., "2"). |---