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
+4 -3
View File
@@ -47,9 +47,10 @@ RewriteRule ^licenses/?$ /index.php?action=licenses [L,QSA]
RewriteRule ^contact/?$ /index.php?action=contact [L,QSA]
# Flux RSS — /feed est canonique, /rss et /rss.xml redirigent en 301
RewriteRule ^rss/?$ /feed [R=301,L]
RewriteRule ^rss\.xml$ /feed [R=301,L]
RewriteRule ^feed/?$ /feed.php [L,QSA]
RewriteRule ^rss/?$ /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]
# Sitemap
RewriteRule ^sitemap\.xml$ /sitemap.php [L]
+25 -16
View File
@@ -29,13 +29,27 @@ $all = array_values(array_filter(
}
));
$total = count($all);
$lastPage = max(1, (int)ceil($total / FEED_PAGE_SIZE));
$page = max(1, min($lastPage, (int)($_GET['page'] ?? 1)));
$items = array_slice($all, ($page - 1) * FEED_PAGE_SIZE, FEED_PAGE_SIZE);
// ─── Pagination curseur ──────────────────────────────────────────────────────
$after = trim($_GET['after'] ?? '');
$offset = 0;
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 = '';
foreach ($all as $a) {
$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>
<lastBuildDate><?= htmlspecialchars($lastBuild) ?></lastBuildDate>
<!-- Flux canonique (toujours page 1) -->
<atom:link href="<?= htmlspecialchars($feedUrl(1)) ?>" rel="self" type="application/rss+xml"/>
<atom:link href="<?= htmlspecialchars($feedUrl) ?>" rel="self" type="application/rss+xml"/>
<?php if ($page > 1): ?>
<!-- Navigation entre pages -->
<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 if ($offset > 0): ?>
<atom:link href="<?= htmlspecialchars($feedUrl) ?>" rel="first" type="application/rss+xml"/>
<?php endif; ?>
<?php if ($page < $lastPage): ?>
<atom:link href="<?= htmlspecialchars($feedUrl($page + 1)) ?>" rel="next" type="application/rss+xml"/>
<atom:link href="<?= htmlspecialchars($feedUrl($lastPage)) ?>" rel="last" type="application/rss+xml"/>
<?php if ($feedNextUrl !== null): ?>
<atom:link href="<?= htmlspecialchars($feedNextUrl) ?>" rel="next" type="application/rss+xml"/>
<?php endif; ?>
<?php if ($lastPage > 1): ?>
<!-- Métadonnées de pagination (RFC 5005) -->
<?php if ($feedNextUrl !== null || $offset > 0): ?>
<fh:archive/>
<?php endif; ?>