fix: flux RSS — exclut catégories privées, description en texte brut

This commit is contained in:
Cedric Abonnel
2026-05-12 10:20:26 +02:00
parent 7558fc721f
commit 9f8026bc61
+14 -3
View File
@@ -12,14 +12,21 @@ require_once BASE_PATH . '/src/ArticleManager.php';
const FEED_PAGE_SIZE = 20;
$articles = new ArticleManager(BASE_PATH . '/data');
$articles = new ArticleManager(BASE_PATH . '/data');
$privateCats = $articles->getPrivateCategories();
$now = time();
$base = rtrim(APP_URL, '/');
$all = array_values(array_filter(
$articles->getAll(publishedOnly: true),
static fn (array $a): bool => strtotime((string)($a['published_at'] ?? '')) <= $now
static function (array $a) use ($now, $privateCats): bool {
if (strtotime((string)($a['published_at'] ?? '')) > $now) {
return false;
}
$cat = trim($a['category'] ?? '');
return $cat === '' || !in_array($cat, $privateCats, true);
}
));
// ─── Détection navigateur ────────────────────────────────────────────────────
@@ -95,6 +102,9 @@ if ($isBrowser) {
}
// ─── Flux XML pour les lecteurs RSS ─────────────────────────────────────────
require_once BASE_PATH . '/src/Parsedown.php';
$Parsedown = new Parsedown();
$total = count($all);
$lastPage = max(1, (int)ceil($total / FEED_PAGE_SIZE));
$page = max(1, min($lastPage, (int)($_GET['page'] ?? 1)));
@@ -150,7 +160,8 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$pubDate = date(DATE_RSS, (int)strtotime((string)($article['published_at'] ?? $article['created_at'] ?? '')));
$link = $base . '/post/' . rawurlencode($article['slug'] ?? '');
$title = htmlspecialchars($article['title'] ?? '', ENT_XML1);
$desc = htmlspecialchars(mb_strimwidth(strip_tags($article['content'] ?? ''), 0, 300, '…'), ENT_XML1);
$plain = preg_replace('/\s+/', ' ', strip_tags($Parsedown->text($article['content'] ?? '')));
$desc = htmlspecialchars(mb_strimwidth(trim((string)$plain), 0, 300, '…'), ENT_XML1);
$guid = htmlspecialchars($base . '/post/' . rawurlencode($article['slug'] ?? ''), ENT_XML1);
?>
<item>