feat: pagination curseur /feed/<uuid> sur le flux RSS

This commit is contained in:
Cedric Abonnel
2026-05-12 10:25:19 +02:00
parent b433e37632
commit 5275edfd20
2 changed files with 29 additions and 19 deletions
+1
View File
@@ -49,6 +49,7 @@ RewriteRule ^contact/?$ /index.php?action=contact [L,QSA]
# Flux RSS — /feed est canonique, /rss et /rss.xml redirigent en 301 # Flux RSS — /feed est canonique, /rss et /rss.xml redirigent en 301
RewriteRule ^rss/?$ /feed [R=301,L] RewriteRule ^rss/?$ /feed [R=301,L]
RewriteRule ^rss\.xml$ /feed [R=301,L] RewriteRule ^rss\.xml$ /feed [R=301,L]
RewriteRule ^feed/([0-9a-f-]{36})/?$ /feed.php?after=$1 [L,QSA]
RewriteRule ^feed/?$ /feed.php [L,QSA] RewriteRule ^feed/?$ /feed.php [L,QSA]
# Sitemap # Sitemap
+25 -16
View File
@@ -29,13 +29,27 @@ $all = array_values(array_filter(
} }
)); ));
$total = count($all); // ─── Pagination curseur ──────────────────────────────────────────────────────
$lastPage = max(1, (int)ceil($total / FEED_PAGE_SIZE)); $after = trim($_GET['after'] ?? '');
$page = max(1, min($lastPage, (int)($_GET['page'] ?? 1))); $offset = 0;
$items = array_slice($all, ($page - 1) * FEED_PAGE_SIZE, FEED_PAGE_SIZE); if ($after !== '') {
foreach ($all as $i => $a) {
if ($a['uuid'] === $after) {
$offset = $i + 1;
break;
}
}
}
$feedUrl = static fn (int $p): string => $base . '/feed' . ($p > 1 ? '?page=' . $p : ''); $items = array_slice($all, $offset, FEED_PAGE_SIZE);
$nextCursor = (count($all) > $offset + FEED_PAGE_SIZE)
? ($all[$offset + FEED_PAGE_SIZE - 1]['uuid'] ?? null)
: null;
$feedUrl = $base . '/feed';
$feedNextUrl = $nextCursor !== null ? $base . '/feed/' . $nextCursor : null;
// ─── lastBuildDate ───────────────────────────────────────────────────────────
$lastBuild = ''; $lastBuild = '';
foreach ($all as $a) { foreach ($all as $a) {
$ts = (int)strtotime((string)($a['updated_at'] ?? $a['published_at'] ?? '')); $ts = (int)strtotime((string)($a['updated_at'] ?? $a['published_at'] ?? ''));
@@ -62,21 +76,16 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
<language>fr</language> <language>fr</language>
<lastBuildDate><?= htmlspecialchars($lastBuild) ?></lastBuildDate> <lastBuildDate><?= htmlspecialchars($lastBuild) ?></lastBuildDate>
<!-- Flux canonique (toujours page 1) --> <atom:link href="<?= htmlspecialchars($feedUrl) ?>" rel="self" type="application/rss+xml"/>
<atom:link href="<?= htmlspecialchars($feedUrl(1)) ?>" rel="self" type="application/rss+xml"/>
<?php if ($page > 1): ?> <?php if ($offset > 0): ?>
<!-- Navigation entre pages --> <atom:link href="<?= htmlspecialchars($feedUrl) ?>" rel="first" type="application/rss+xml"/>
<atom:link href="<?= htmlspecialchars($feedUrl(1)) ?>" rel="first" type="application/rss+xml"/>
<atom:link href="<?= htmlspecialchars($feedUrl($page - 1)) ?>" rel="previous" type="application/rss+xml"/>
<?php endif; ?> <?php endif; ?>
<?php if ($page < $lastPage): ?> <?php if ($feedNextUrl !== null): ?>
<atom:link href="<?= htmlspecialchars($feedUrl($page + 1)) ?>" rel="next" type="application/rss+xml"/> <atom:link href="<?= htmlspecialchars($feedNextUrl) ?>" rel="next" type="application/rss+xml"/>
<atom:link href="<?= htmlspecialchars($feedUrl($lastPage)) ?>" rel="last" type="application/rss+xml"/>
<?php endif; ?> <?php endif; ?>
<?php if ($lastPage > 1): ?> <?php if ($feedNextUrl !== null || $offset > 0): ?>
<!-- Métadonnées de pagination (RFC 5005) -->
<fh:archive/> <fh:archive/>
<?php endif; ?> <?php endif; ?>