Compare commits

..

2 commits

Author SHA1 Message Date
Ruben
069ce389ea 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
2026-02-06 18:24:39 +01:00
Ruben
1cbfb67a4c Add Atom feed support
Add feed URL to base template
Refactor list item building into separate function
Improve date extraction logic
Add feed XML generation handler
Update template variables handling
2026-02-06 18:24:31 +01:00
11 changed files with 294 additions and 108 deletions

View file

@ -14,6 +14,9 @@
<?php if (!empty($pageCssUrl)): ?>
<link rel="stylesheet" href="<?= htmlspecialchars($pageCssUrl) ?>?v=<?= htmlspecialchars($pageCssHash ?? '') ?>">
<?php endif; ?>
<?php if (!empty($feedUrl)): ?>
<link rel="alternate" type="application/atom+xml" title="<?= htmlspecialchars($pageTitle ?? 'Feed') ?>" href="<?= htmlspecialchars($feedUrl) ?>">
<?php endif; ?>
</head>
<body>
<header>

View file

@ -32,11 +32,73 @@ function extractTitle(string $filePath): ?string {
return null;
}
function extractDateFromFolder(string $folderName): ?string {
// Build sorted list items for a directory
function buildListItems(string $dir, Context $ctx, ?array $parentMetadata): array {
$subdirs = getSubdirectories($dir);
$items = array_filter(array_map(function($item) use ($dir, $ctx) {
$itemPath = "$dir/$item";
$metadata = loadMetadata($itemPath);
$coverImage = findCoverImage($itemPath);
$pdfFile = findPdfFile($itemPath);
$title = $metadata['title'] ?? extractTitle($itemPath) ?? $item;
$rawDate = null;
$date = null;
if (isset($metadata['date'])) {
$rawDate = $metadata['date'];
$date = Hooks::apply(Hook::PROCESS_CONTENT, $rawDate, 'date_format');
} else {
$rawDate = extractRawDateFromFolder($item);
if ($rawDate) {
$date = Hooks::apply(Hook::PROCESS_CONTENT, $rawDate, 'date_format');
} else {
$rawDate = date("Y-m-d", filemtime($itemPath));
$date = Hooks::apply(Hook::PROCESS_CONTENT, $rawDate, 'date_format');
}
}
$urlSlug = ($metadata && isset($metadata['slug'])) ? $metadata['slug'] : $item;
$langPrefix = $ctx->get('langPrefix', '');
$baseUrl = $langPrefix . '/' . trim($ctx->requestPath, '/') . '/' . urlencode($urlSlug);
$assetUrl = $langPrefix . '/' . trim($ctx->requestPath, '/') . '/' . urlencode($item);
return [
'title' => $title,
'url' => $baseUrl . '/',
'date' => $date,
'rawDate' => $rawDate,
'summary' => $metadata['summary'] ?? null,
'cover' => $coverImage ? "$assetUrl/$coverImage" : null,
'pdf' => $pdfFile ? "$assetUrl/$pdfFile" : null,
'redirect' => $metadata['redirect'] ?? null,
'dirPath' => $itemPath
];
}, $subdirs));
$sortOrder = strtolower($parentMetadata['order'] ?? 'descending');
if ($sortOrder === 'ascending') {
usort($items, fn($a, $b) => strcmp($a['date'] ?? '', $b['date'] ?? ''));
} else {
usort($items, fn($a, $b) => strcmp($b['date'] ?? '', $a['date'] ?? ''));
}
return $items;
}
function extractRawDateFromFolder(string $folderName): ?string {
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})-/', $folderName, $matches)) {
$dateString = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
// Let plugins format the date
return Hooks::apply(Hook::PROCESS_CONTENT, $dateString, 'date_format');
return $matches[1] . '-' . $matches[2] . '-' . $matches[3];
}
return null;
}
function extractDateFromFolder(string $folderName): ?string {
$raw = extractRawDateFromFolder($folderName);
if ($raw) {
return Hooks::apply(Hook::PROCESS_CONTENT, $raw, 'date_format');
}
return null;
}

View file

@ -48,13 +48,16 @@ function renderTemplate(Context $ctx, string $content, int $statusCode = 200): v
$navigation = $ctx->navigation;
$homeLabel = $ctx->homeLabel;
$pageTitle = null;
$templateVars = Hooks::apply(Hook::TEMPLATE_VARS, [
'content' => $content,
'navigation' => $navigation,
'homeLabel' => $homeLabel,
'pageTitle' => $pageTitle
'pageTitle' => $ctx->get('pageTitle'),
'metaDescription' => $ctx->get('metaDescription'),
'pageCssUrl' => $ctx->get('pageCssUrl'),
'pageCssHash' => $ctx->get('pageCssHash'),
'feedUrl' => $ctx->get('feedUrl')
], $ctx);
extract($templateVars);

View file

@ -52,6 +52,82 @@ if (file_exists($contentAssetPath) && is_file($contentAssetPath)) {
}
}
// Handle Atom feed requests
if (str_ends_with($ctx->requestPath, 'feed.xml')) {
$feedPath = preg_replace('#/?feed\.xml$#', '', $ctx->requestPath);
// Temporarily set requestPath to the parent directory for resolution
$reflection = new ReflectionProperty($ctx, 'requestPath');
$originalPath = $ctx->requestPath;
$reflection->setValue($ctx, $feedPath);
$parsedFeed = parseRequestPath($ctx);
if ($parsedFeed['type'] !== 'list') {
$reflection->setValue($ctx, $originalPath);
} else {
$dir = $parsedFeed['path'];
$metadata = loadMetadata($dir);
if (!isset($metadata['feed']) || !$metadata['feed']) {
$reflection->setValue($ctx, $originalPath);
} else {
$items = buildListItems($dir, $ctx, $metadata);
// Render full content for each item
foreach ($items as &$item) {
$item['content'] = '';
$contentFiles = findAllContentFiles($item['dirPath']);
foreach ($contentFiles as $file) {
$item['content'] .= renderContentFile($file, $ctx);
}
}
unset($item);
// Build Atom XML
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$baseUrl = "$scheme://$host";
$langPrefix = $ctx->get('langPrefix', '');
$listUrl = $baseUrl . $langPrefix . '/' . trim($feedPath, '/') . '/';
$feedUrl = $baseUrl . $langPrefix . '/' . trim($feedPath, '/') . '/feed.xml';
$feedTitle = $metadata['title'] ?? 'Feed';
$updated = !empty($items) ? ($items[0]['rawDate'] ?? date('Y-m-d')) : date('Y-m-d');
header('Content-Type: application/atom+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
echo '<feed xmlns="http://www.w3.org/2005/Atom">' . "\n";
echo ' <title>' . htmlspecialchars($feedTitle) . '</title>' . "\n";
echo ' <link href="' . htmlspecialchars($listUrl) . '" rel="alternate"/>' . "\n";
echo ' <link href="' . htmlspecialchars($feedUrl) . '" rel="self"/>' . "\n";
echo ' <id>' . htmlspecialchars($listUrl) . '</id>' . "\n";
echo ' <updated>' . $updated . 'T00:00:00Z</updated>' . "\n";
foreach ($items as $item) {
$absoluteUrl = $baseUrl . $item['url'];
$itemDate = ($item['rawDate'] ?? date('Y-m-d')) . 'T00:00:00Z';
echo ' <entry>' . "\n";
echo ' <title>' . htmlspecialchars($item['title']) . '</title>' . "\n";
echo ' <link href="' . htmlspecialchars($absoluteUrl) . '" rel="alternate"/>' . "\n";
echo ' <id>' . htmlspecialchars($absoluteUrl) . '</id>' . "\n";
echo ' <updated>' . $itemDate . '</updated>' . "\n";
if ($item['summary']) {
echo ' <summary>' . htmlspecialchars($item['summary']) . '</summary>' . "\n";
}
if ($item['content']) {
$safeContent = str_replace(']]>', ']]]]><![CDATA[>', $item['content']);
echo ' <content type="html"><![CDATA[' . $safeContent . ']]></content>' . "\n";
}
echo ' </entry>' . "\n";
}
echo '</feed>' . "\n";
exit;
}
}
}
// Handle frontpage
if (empty($ctx->requestPath)) {
$contentFiles = findAllContentFiles($ctx->contentDir);
@ -121,59 +197,7 @@ switch ($parsedPath['type']) {
}
// Build list items
$subdirs = getSubdirectories($dir);
$items = array_filter(array_map(function($item) use ($dir, $ctx) {
$itemPath = "$dir/$item";
$metadata = loadMetadata($itemPath);
$coverImage = findCoverImage($itemPath);
$pdfFile = findPdfFile($itemPath);
$title = $metadata['title'] ?? extractTitle($itemPath) ?? $item;
$date = null;
if (isset($metadata['date'])) {
$date = $metadata['date'];
// Let plugins format date
$date = Hooks::apply(Hook::PROCESS_CONTENT, $date, 'date_format');
} else {
$extractedDate = extractDateFromFolder($item);
if ($extractedDate) {
$date = $extractedDate;
} else {
// Convert timestamp to ISO format and let plugins format it
$isoDate = date("Y-m-d", filemtime($itemPath));
$date = Hooks::apply(Hook::PROCESS_CONTENT, $isoDate, 'date_format');
}
}
// Use slug if available
$urlSlug = ($metadata && isset($metadata['slug'])) ? $metadata['slug'] : $item;
$langPrefix = $ctx->get('langPrefix', '');
$baseUrl = $langPrefix . '/' . trim($ctx->requestPath, '/') . '/' . urlencode($urlSlug);
// Assets (cover, PDF) must use actual folder name, not translated slug
$assetUrl = $langPrefix . '/' . trim($ctx->requestPath, '/') . '/' . urlencode($item);
return [
'title' => $title,
'url' => $baseUrl . '/',
'date' => $date,
'summary' => $metadata['summary'] ?? null,
'cover' => $coverImage ? "$assetUrl/$coverImage" : null,
'pdf' => $pdfFile ? "$assetUrl/$pdfFile" : null,
'redirect' => $metadata['redirect'] ?? null
];
}, $subdirs));
// Sort by date - check metadata for order preference
$sortOrder = strtolower($metadata['order'] ?? 'descending');
if ($sortOrder === 'ascending') {
usort($items, fn($a, $b) => strcmp($a['date'] ?? '', $b['date'] ?? ''));
} else {
// Default: descending (newest first)
usort($items, fn($a, $b) => strcmp($b['date'] ?? '', $a['date'] ?? ''));
}
$items = buildListItems($dir, $ctx, $metadata);
// Prepare all variables for base template
$navigation = $ctx->navigation;
@ -186,6 +210,19 @@ switch ($parsedPath['type']) {
$pageCssUrl = $pageCss['url'] ?? null;
$pageCssHash = $pageCss['hash'] ?? null;
// Build feed URL if feed is enabled
$langPrefix = $ctx->get('langPrefix', '');
$feedUrl = (isset($metadata['feed']) && $metadata['feed'])
? $langPrefix . '/' . trim($ctx->requestPath, '/') . '/feed.xml'
: null;
// Store for base template (renderTemplate reads these from context)
$ctx->set('pageTitle', $pageTitle);
$ctx->set('metaDescription', $metaDescription);
$ctx->set('pageCssUrl', $pageCssUrl);
$ctx->set('pageCssHash', $pageCssHash);
$ctx->set('feedUrl', $feedUrl);
// Let plugins add template variables
$templateVars = Hooks::apply(Hook::TEMPLATE_VARS, [
'navigation' => $navigation,
@ -195,7 +232,8 @@ switch ($parsedPath['type']) {
'pageCssUrl' => $pageCssUrl,
'pageCssHash' => $pageCssHash,
'items' => $items,
'pageContent' => $pageContent
'pageContent' => $pageContent,
'feedUrl' => $feedUrl
], $ctx);
extract($templateVars);

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` | — | — | ✓ |

View file

@ -76,22 +76,29 @@ router.php
├─ 3. Check custom/assets/{path} → serve static file + exit
├─ 4. Check content/{path} for static asset (css/img/pdf/font) → serve + exit
├─ 5. Empty path? → frontpage: findAllContentFiles + renderMultipleFiles
├─ 5. Path ends with feed.xml? → Atom feed generation
│ ├─ Strip feed.xml, resolve parent as list directory
│ ├─ Check feed = true in metadata, otherwise 404
│ ├─ buildListItems() + renderContentFile() for full content
│ └─ Output Atom XML + exit
└─ 6. parseRequestPath() → {type, path}
├─ 6. Empty path? → frontpage: findAllContentFiles + renderMultipleFiles
└─ 7. parseRequestPath() → {type, path}
├─ "page": trailing slash redirect → findAllContentFiles → renderMultipleFiles
│ (fires Hook::PROCESS_CONTENT for file filtering)
│ (fires Hook::TEMPLATE_VARS before template render)
│ Template chain: content → page.php → base.php
├─ "list": trailing slash redirect → build items array from subdirectories
├─ "list": trailing slash redirect → buildListItems() from helpers.php
│ ├─ Check hide_list metadata → treat as page if true
│ ├─ Select list template from metadata page_template
│ ├─ For each subdir: loadMetadata, extractTitle, extractDateFromFolder, findCoverImage
│ ├─ buildListItems(): metadata, titles, dates, covers for each subdir
│ ├─ Sort items by date (metadata `order` = ascending|descending)
│ ├─ Store pageTitle, metaDescription, feedUrl etc. on context
│ ├─ Fire Hook::TEMPLATE_VARS
│ └─ Template chain: items → list-*.php → base.php
│ └─ Template chain: items → list-*.php → base.php (via renderTemplate)
└─ "not_found": 404 response
```

View file

@ -53,6 +53,7 @@ Returns flat key-value array with a special `_raw` key containing the full parse
| `menu_order` | int | 999 | Navigation sort order (ascending) |
| `order` | string | `"descending"` | List sort direction (`ascending`\|`descending`) |
| `redirect` | string | — | External URL (list items can redirect) |
| `feed` | bool | `false` | Enable Atom feed on list pages (`feed.xml`) |
| `plugins` | string | — | Comma-separated page-level plugin names |
### Settings Section
@ -83,7 +84,9 @@ Any key not listed above is passed through to templates/plugins unchanged. Add w
## Date Extraction
**`extractDateFromFolder(string $folderName): ?string`** — Extracts date from `YYYY-MM-DD-*` prefix.
**`extractRawDateFromFolder(string $folderName): ?string`** — Extracts raw `YYYY-MM-DD` string from folder name prefix. Returns null if no date prefix. No hook processing.
**`extractDateFromFolder(string $folderName): ?string`** — Calls `extractRawDateFromFolder()` then passes the result through `Hook::PROCESS_CONTENT($date, 'date_format')` for plugin formatting (e.g., `"1. January 2025"`).
If no date prefix exists and no `date` metadata is set, falls back to file modification time (`filemtime`). All dates pass through `Hook::PROCESS_CONTENT($date, 'date_format')` for plugin formatting.
@ -91,6 +94,16 @@ If no date prefix exists and no `date` metadata is set, falls back to file modif
**Sorting with null dates:** Items without any date are sorted as empty strings via `strcmp`. Their relative order among other dateless items is undefined.
## List Item Building
**`buildListItems(string $dir, Context $ctx, ?array $parentMetadata): array`** — Builds and sorts the items array for list views. Defined in `helpers.php`.
For each subdirectory: loads metadata, extracts title/date/cover/PDF, builds URL with lang prefix and slug. Returns sorted array — direction controlled by `order` metadata on parent (`descending` default).
Each item contains both a formatted `date` (hook-processed for display) and a `rawDate` (ISO `YYYY-MM-DD` for Atom feeds and `<time>` elements). Also includes `dirPath` (filesystem path) used by the feed generator to render full content.
Used by both the list case in `router.php` and the Atom feed generator.
## Navigation
**`buildNavigation(Context $ctx): array`** — Scans top-level content directories.

View file

@ -44,6 +44,18 @@ Also supports magic property access: `$ctx->foo = 'bar'` / `$val = $ctx->foo`.
| `langPrefix` | string | languages.php | URL prefix: `""` for default, `"/no"` for others |
| `translations` | array | languages.php | Merged translation strings for current language |
### Built-in Context Keys (set by router.php for list pages)
These are set in the list case so that `renderTemplate()` can pass them to `base.php`:
| Key | Type | Description |
|---|---|---|
| `pageTitle` | ?string | Page title from metadata (for `<title>` tag) |
| `metaDescription` | ?string | SEO description |
| `pageCssUrl` | ?string | Page-specific CSS URL |
| `pageCssHash` | ?string | CSS cache-bust hash |
| `feedUrl` | ?string | Atom feed URL (set when `feed = true` in metadata) |
## Templates Class
Defined in `app/context.php`. Readonly value object.

View file

@ -59,6 +59,7 @@ Variables are injected via `extract()` — each array key becomes a local variab
| `$homeLabel` | string | yes | Home link text |
| `$pageCssUrl` | ?string | no | Page-specific CSS URL |
| `$pageCssHash` | ?string | no | CSS cache-bust hash |
| `$feedUrl` | ?string | no | Atom feed URL (only on lists with `feed = true`) |
| `$currentLang` | string | plugin | Language code (from languages plugin) |
| `$langPrefix` | string | plugin | URL language prefix |
| `$languageUrls` | array | plugin | `[lang => url]` for language switcher |
@ -92,10 +93,12 @@ Each entry in `$items`:
| `title` | string | yes | From metadata, first heading, or folder name |
| `url` | string | yes | Full URL path with trailing slash and lang prefix |
| `date` | ?string | no | Formatted date string (plugin-processed) |
| `rawDate` | ?string | no | ISO `YYYY-MM-DD` date (for feeds, `<time>` elements) |
| `summary` | ?string | no | From metadata |
| `cover` | ?string | no | URL to cover image |
| `pdf` | ?string | no | URL to first PDF file |
| `redirect` | ?string | no | External redirect URL |
| `dirPath` | string | yes | Filesystem path to item directory (internal use) |
Items sorted by date — direction controlled by `order` metadata on parent (`descending` default, `ascending` available).

View file

@ -36,13 +36,26 @@ Handled directly in `router.php` (not a separate function):
1. Render directory's own content files as `$pageContent`
2. Load metadata, check `hide_list`
3. Select list template from `page_template` metadata
4. Build `$items` array from subdirectories (metadata + extraction)
5. Sort items by date
4. Call `buildListItems()` from `helpers.php` (builds + sorts items)
5. Store `pageTitle`, `metaDescription`, `pageCssUrl`, `pageCssHash`, `feedUrl` on context
6. Fire `Hook::TEMPLATE_VARS`
7. Render list template → capture as `$content`
8. Pass to `renderTemplate()` which renders `base.php`
**`renderTemplate(Context $ctx, string $content, int $statusCode = 200): void`** — Wraps content in base template. Used for list views and error pages.
**`renderTemplate(Context $ctx, string $content, int $statusCode = 200): void`** — Wraps content in base template. Used for list views and error pages. Reads `pageTitle`, `metaDescription`, `pageCssUrl`, `pageCssHash`, and `feedUrl` from the context object (set by the list case in `router.php`). For error pages, these context keys are unset, so base.php receives nulls.
## Atom Feed Rendering
Handled in `router.php` before `parseRequestPath()`. When a request path ends with `feed.xml`:
1. Strip `feed.xml` suffix, resolve parent as list directory via `parseRequestPath()`
2. Check `feed = true` in metadata — 404 if missing or if parent is not a list
3. Call `buildListItems()` to get items
4. For each item: call `findAllContentFiles()` + `renderContentFile()` to get full HTML content
5. Build Atom XML with absolute URLs (`$_SERVER['HTTP_HOST']` + scheme detection)
6. Output `Content-Type: application/atom+xml` and exit
Feed piggybacks on the existing Markdown cache — no separate feed cache needed. The `rawDate` field on items provides ISO dates for Atom `<updated>` elements. Content is wrapped in `<![CDATA[...]]>` with `]]>` safely escaped.
## Markdown Caching