feat: pagination curseur /feed/<uuid> sur le flux RSS
This commit is contained in:
@@ -49,6 +49,7 @@ 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/([0-9a-f-]{36})/?$ /feed.php?after=$1 [L,QSA]
|
||||
RewriteRule ^feed/?$ /feed.php [L,QSA]
|
||||
|
||||
# Sitemap
|
||||
|
||||
+25
-16
@@ -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; ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user