requestPath);
if ($realAsset && strncmp($realAsset, $assetsDir . '/', strlen($assetsDir) + 1) === 0 && is_file($realAsset)) {
$assetMimeTypes = [
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'geojson' => 'application/json',
'svg' => 'image/svg+xml',
'woff' => 'font/woff',
'woff2' => 'font/woff2',
'ttf' => 'font/ttf',
'otf' => 'font/otf',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'webp' => 'image/webp',
];
$assetExt = strtolower(pathinfo($realAsset, PATHINFO_EXTENSION));
$mime = $assetMimeTypes[$assetExt] ?? 'application/octet-stream';
$cacheSeconds = in_array($assetExt, ['json', 'geojson']) ? 60 : 31536000;
header('Content-Type: ' . $mime);
header('Cache-Control: public, max-age=' . $cacheSeconds);
readfile($realAsset);
exit;
}
// Check for assets in content directory (CSS, images, etc.)
$contentAssetPath = $ctx->contentDir . '/' . $ctx->requestPath;
if (file_exists($contentAssetPath) && is_file($contentAssetPath)) {
$ext = pathinfo($contentAssetPath, PATHINFO_EXTENSION);
// Define MIME types for asset files
$mimeTypes = [
'css' => 'text/css',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'webp' => 'image/webp',
'svg' => 'image/svg+xml',
'pdf' => 'application/pdf',
'woff' => 'font/woff',
'woff2' => 'font/woff2',
'ttf' => 'font/ttf',
'otf' => 'font/otf',
'js' => 'application/javascript',
];
$extLower = strtolower($ext);
if (isset($mimeTypes[$extLower])) {
header('Content-Type: ' . $mimeTypes[$extLower]);
readfile($contentAssetPath);
exit;
}
}
// 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 '' . "\n";
echo '
The requested page could not be found.
", 404); break; }