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