From 9cde19fe426f9e03589f441fc596c809f68ff54e Mon Sep 17 00:00:00 2001 From: Cedric Abonnel Date: Fri, 8 May 2026 22:56:41 +0200 Subject: [PATCH] feat: flux RSS sur /feed (publies uniquement, autodiscovery dans le head) --- public/.htaccess | 3 ++ public/feed.php | 67 ++++++++++++++++++++++++++++++++++++++++++++ templates/layout.php | 3 ++ 3 files changed, 73 insertions(+) create mode 100644 public/feed.php diff --git a/public/.htaccess b/public/.htaccess index 9f55202..83dbf42 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -11,6 +11,9 @@ RewriteRule ^ - [L] # URL propre pour les articles : /post/ RewriteRule ^post/([a-z0-9][a-z0-9-]*)/?$ /index.php?action=view&slug=$1 [L,QSA] +# Flux RSS +RewriteRule ^feed/?$ /feed.php [L] + # Ajoute .php si le fichier correspondant existe RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f RewriteRule ^(.+?)/?$ /$1.php [L,QSA] diff --git a/public/feed.php b/public/feed.php new file mode 100644 index 0000000..7777aa0 --- /dev/null +++ b/public/feed.php @@ -0,0 +1,67 @@ + 0, 'path' => '/', 'secure' => $isHttps, 'httponly' => true, 'samesite' => 'Lax']); + session_start(); +} + +require_once BASE_PATH . '/src/auth.php'; +require_once BASE_PATH . '/config/config.php'; +require_once BASE_PATH . '/src/ArticleManager.php'; + +$articles = new ArticleManager(BASE_PATH . '/data'); + +$now = time(); +$base = rtrim(APP_URL, '/'); + +$items = array_filter( + $articles->getAll(publishedOnly: true), + static fn (array $a): bool => strtotime((string)($a['published_at'] ?? '')) <= $now +); + +$lastBuild = ''; +foreach ($items as $a) { + $ts = strtotime((string)($a['updated_at'] ?? $a['published_at'] ?? '')); + if ($ts && $ts > strtotime($lastBuild ?: '1970-01-01')) { + $lastBuild = date(DATE_RSS, $ts); + } +} +if ($lastBuild === '') { + $lastBuild = date(DATE_RSS); +} + +header('Content-Type: application/rss+xml; charset=UTF-8'); +header('X-Content-Type-Options: nosniff'); + +echo '' . "\n"; +?> + + + varlog + + Journal personnel de Cédrix — informatique, hack et loisirs techniques. + fr + + + + + <?= $title ?> + + + + + + + + diff --git a/templates/layout.php b/templates/layout.php index 16fddd9..1c496c9 100644 --- a/templates/layout.php +++ b/templates/layout.php @@ -17,6 +17,9 @@ + + +