Add Atom feed support to list pages

Introduce `feed` metadata option to enable Atom feeds
Update list item structure with standardized fields
Add `$feedUrl` template variable for autodiscovery
Improve date handling with raw/processed date separation
Document feed generation in architecture and rendering docs
Update template examples to use new item structure
This commit is contained in:
Ruben 2026-02-06 18:24:39 +01:00
parent 1cbfb67a4c
commit 069ce389ea
7 changed files with 128 additions and 48 deletions

View file

@ -194,6 +194,20 @@ hide_list = true
**Type:** Boolean
**Use case:** Section landing pages that should show content instead of list
### `feed`
Enable an Atom feed for this list page, served at `/{list-path}/feed.xml`.
```ini
feed = true
```
**Default:** `false` (no feed generated)
**Values:** `true` or `false`
**Type:** Boolean
**Applies to:** List pages only (directories with subdirectories)
**Effect:** Generates an Atom XML feed containing the full rendered content of each list item. Also adds an autodiscovery `<link>` tag in the HTML `<head>`.
## Language-Specific Overrides
Add language-specific sections to override fields:
@ -327,20 +341,19 @@ Folder: content/blog/2024-12-15-my-post/
## Metadata in List Items
When rendering list views, each item receives these metadata fields:
When rendering list views, each item in the `$items` array has these keys:
```php
$item = [
'url' => '/blog/my-post/',
'path' => '/content/blog/2024-12-15-my-post',
'title' => 'My Post',
'summary' => 'Short description',
'date' => '2024-12-15',
'formatted_date' => '15. desember 2024', // Language-specific
'cover_image' => '/blog/my-post/cover.jpg', // If exists
// All custom metadata fields...
'author' => 'Jane Doe',
'tags' => 'web,design',
'title' => 'My Post', // From metadata, heading, or folder name
'url' => '/blog/my-post/', // Full URL with trailing slash + lang prefix
'date' => '15. desember 2024', // Formatted for display (plugin-processed)
'rawDate' => '2024-12-15', // ISO YYYY-MM-DD (for feeds, <time> elements)
'summary' => 'Short description', // From metadata (nullable)
'cover' => '/blog/2024-12-15-my-post/cover.jpg', // Cover image URL (nullable)
'pdf' => '/blog/2024-12-15-my-post/doc.pdf', // First PDF URL (nullable)
'redirect' => null, // External redirect URL (nullable)
'dirPath' => '/path/to/content/blog/2024-12-15-my-post', // Filesystem path (internal)
];
```
@ -349,13 +362,17 @@ Access in list templates:
```php
<?php foreach ($items as $item): ?>
<article>
<h2><?= htmlspecialchars($item['title']) ?></h2>
<h2>
<a href="<?= $item['url'] ?>">
<?= htmlspecialchars($item['title']) ?>
</a>
</h2>
<?php if (isset($item['author'])): ?>
<p>By <?= htmlspecialchars($item['author']) ?></p>
<?php if ($item['date']): ?>
<time datetime="<?= $item['rawDate'] ?>"><?= $item['date'] ?></time>
<?php endif; ?>
<?php if (isset($item['summary'])): ?>
<?php if ($item['summary']): ?>
<p><?= htmlspecialchars($item['summary']) ?></p>
<?php endif; ?>
</article>

View file

@ -211,6 +211,21 @@ MD5 hash of page-specific CSS for cache busting.
**Optional:** Only set if `$pageCssUrl` exists
**Example:** See `$pageCssUrl` above
### `$feedUrl`
URL to the Atom feed for the current list page.
**Type:** String (URL path)
**Optional:** Only set on list pages with `feed = true` in metadata
**Example:**
```php
<?php if (!empty($feedUrl)): ?>
<link rel="alternate" type="application/atom+xml" title="<?= htmlspecialchars($pageTitle ?? 'Feed') ?>" href="<?= htmlspecialchars($feedUrl) ?>">
<?php endif; ?>
```
**Source:** Set when `feed = true` in the list directory's `metadata.ini`
## Page Template Variables
Available in `page.php`:
@ -238,7 +253,6 @@ All metadata for the current page.
'title' => 'Page Title',
'summary' => 'Short description',
'date' => '2024-12-15',
'formatted_date' => '15. desember 2024',
'show_date' => true,
'author' => 'Jane Doe', // Custom fields
'tags' => 'web,design',
@ -254,7 +268,7 @@ All metadata for the current page.
<?php if (isset($metadata['date']) && ($metadata['show_date'] ?? true)): ?>
<time datetime="<?= $metadata['date'] ?>">
<?= $metadata['formatted_date'] ?? $metadata['date'] ?>
<?= $metadata['date'] ?>
</time>
<?php endif; ?>
```
@ -289,16 +303,15 @@ Array of items to display in the list.
```php
[
[
'url' => '/blog/my-post/',
'path' => '/content/blog/2024-12-15-my-post',
'title' => 'My Post',
'url' => '/blog/my-post/',
'date' => '15. desember 2024', // Formatted for display
'rawDate' => '2024-12-15', // ISO YYYY-MM-DD
'summary' => 'Short description',
'date' => '2024-12-15',
'formatted_date' => '15. desember 2024',
'cover_image' => '/blog/my-post/cover.jpg',
// All custom metadata fields...
'author' => 'Jane Doe',
'category' => 'Tutorial',
'cover' => '/blog/2024-12-15-my-post/cover.jpg',
'pdf' => null,
'redirect' => null,
'dirPath' => '/path/to/content/blog/2024-12-15-my-post',
],
// ... more items
]
@ -308,8 +321,8 @@ Array of items to display in the list.
```php
<?php foreach ($items as $item): ?>
<article>
<?php if (isset($item['cover_image'])): ?>
<img src="<?= $item['cover_image'] ?>"
<?php if ($item['cover']): ?>
<img src="<?= $item['cover'] ?>"
alt="<?= htmlspecialchars($item['title']) ?>">
<?php endif; ?>
@ -319,13 +332,13 @@ Array of items to display in the list.
</a>
</h2>
<?php if (isset($item['date'])): ?>
<time datetime="<?= $item['date'] ?>">
<?= $item['formatted_date'] ?? $item['date'] ?>
<?php if ($item['date']): ?>
<time datetime="<?= $item['rawDate'] ?>">
<?= $item['date'] ?>
</time>
<?php endif; ?>
<?php if (isset($item['summary'])): ?>
<?php if ($item['summary']): ?>
<p><?= htmlspecialchars($item['summary']) ?></p>
<?php endif; ?>
</article>
@ -351,14 +364,15 @@ Each item in `$items` has these properties:
| Property | Type | Description | Optional |
|----------|------|-------------|----------|
| `url` | String | Full URL to the item | No |
| `path` | String | Filesystem path to item | No |
| `title` | String | Item title | No |
| `summary` | String | Short description | Yes |
| `date` | String | ISO date (YYYY-MM-DD) | Yes |
| `formatted_date` | String | Localized date string | Yes |
| `cover_image` | String | URL to cover image | Yes |
| Custom fields | Mixed | Any metadata fields | Yes |
| `title` | String | Item title (from metadata, heading, or folder name) | No |
| `url` | String | Full URL to the item (with trailing slash + lang prefix) | No |
| `date` | String | Formatted date string (plugin-processed for display) | Yes |
| `rawDate` | String | ISO date (YYYY-MM-DD) for feeds and `<time>` elements | Yes |
| `summary` | String | Short description from metadata | Yes |
| `cover` | String | URL to cover image | Yes |
| `pdf` | String | URL to first PDF file | Yes |
| `redirect` | String | External redirect URL | Yes |
| `dirPath` | String | Filesystem path to item directory (internal use) | No |
## Adding Custom Variables
@ -401,6 +415,7 @@ Then use in templates:
| `$translations` | ✓ | — | — |
| `$pageCssUrl` | ✓ | — | — |
| `$pageCssHash` | ✓ | — | — |
| `$feedUrl` | ✓ | — | — |
| `$metadata` | — | ✓ | ✓ |
| `$pageContent` | — | — | ✓ |
| `$items` | — | — | ✓ |