Add configurable file exclusion for Atom feeds

Replaces hardcoded script and style stripping with a substring-based
exclusion list defined in custom/config.ini. Excluded files continue
to render on actual web pages.
This commit is contained in:
Ruben 2026-05-10 21:27:22 +02:00
parent 0866fe93ba
commit a22281c896
3 changed files with 34 additions and 7 deletions

View file

@ -96,20 +96,30 @@ if (str_ends_with($ctx->requestPath, 'feed.xml')) {
$items = buildListItems($dir, $ctx, $metadata);
// Render full content for each item
// Load feed exclusion patterns from config (comma-separated substrings)
$customConfigPath = dirname(__DIR__) . '/custom/config.ini';
$feedConfig = file_exists($customConfigPath) ? (parse_ini_file($customConfigPath, true)['feed'] ?? []) : [];
$excludePatterns = array_map('trim', explode(',', $feedConfig['exclude_files'] ?? ''));
$excludePatterns = array_filter($excludePatterns);
foreach ($items as &$item) {
$item['content'] = '';
$itemMetadata = loadMetadata($item['dirPath']);
getPluginManager()->loadPagePlugins($itemMetadata);
$contentFiles = findAllContentFiles($item['dirPath']);
foreach ($contentFiles as $file) {
$item['content'] .= renderContentFile($file, $ctx);
$basename = basename($file);
$excluded = false;
foreach ($excludePatterns as $pattern) {
if (str_contains($basename, $pattern)) {
$excluded = true;
break;
}
}
if (!$excluded) {
$item['content'] .= renderContentFile($file, $ctx);
}
}
// Strip <script> and <style> blocks — not useful in feed readers
$stripped = preg_replace('#<script[^>]*>.*?</script>#is', '', $item['content']);
if ($stripped !== null) {
$stripped = preg_replace('#<style[^>]*>.*?</style>#is', '', $stripped);
}
$item['content'] = $stripped ?? $item['content'];
}
unset($item);