revert: supprime la détection navigateur sur le flux RSS
This commit is contained in:
+8
-84
@@ -4,16 +4,16 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
define('BASE_PATH', realpath(__DIR__ . '/../'));
|
define('BASE_PATH', realpath(__DIR__ . '/../'));
|
||||||
|
|
||||||
require_once BASE_PATH . '/bootstrap.php';
|
|
||||||
require_once BASE_PATH . '/src/helpers.php';
|
|
||||||
require_once BASE_PATH . '/src/auth.php';
|
require_once BASE_PATH . '/src/auth.php';
|
||||||
require_once BASE_PATH . '/config/config.php';
|
require_once BASE_PATH . '/config/config.php';
|
||||||
require_once BASE_PATH . '/src/ArticleManager.php';
|
require_once BASE_PATH . '/src/ArticleManager.php';
|
||||||
|
require_once BASE_PATH . '/src/Parsedown.php';
|
||||||
|
|
||||||
const FEED_PAGE_SIZE = 20;
|
const FEED_PAGE_SIZE = 20;
|
||||||
|
|
||||||
$articles = new ArticleManager(BASE_PATH . '/data');
|
$articles = new ArticleManager(BASE_PATH . '/data');
|
||||||
$privateCats = $articles->getPrivateCategories();
|
$privateCats = $articles->getPrivateCategories();
|
||||||
|
$Parsedown = new Parsedown();
|
||||||
|
|
||||||
$now = time();
|
$now = time();
|
||||||
$base = rtrim(APP_URL, '/');
|
$base = rtrim(APP_URL, '/');
|
||||||
@@ -29,88 +29,12 @@ $all = array_values(array_filter(
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
// ─── Détection navigateur ────────────────────────────────────────────────────
|
|
||||||
$accept = $_SERVER['HTTP_ACCEPT'] ?? '';
|
|
||||||
$isBrowser = str_contains($accept, 'text/html')
|
|
||||||
&& !str_contains($accept, 'application/rss+xml');
|
|
||||||
|
|
||||||
if ($isBrowser) {
|
|
||||||
require_once BASE_PATH . '/src/Parsedown.php';
|
|
||||||
$Parsedown = new Parsedown();
|
|
||||||
|
|
||||||
$feedUrl = $base . '/feed';
|
|
||||||
$recentItems = array_slice($all, 0, 10);
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
?>
|
|
||||||
<div class="row justify-content-center">
|
|
||||||
<div class="col-lg-7">
|
|
||||||
|
|
||||||
<div class="mb-5">
|
|
||||||
<h1 class="h3 mb-1">Flux RSS — varlog</h1>
|
|
||||||
<p class="text-muted mb-0">Journal personnel de Cédrix — informatique, hack et loisirs techniques.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card mb-5">
|
|
||||||
<div class="card-body">
|
|
||||||
<h2 class="h6 fw-semibold mb-2">S'abonner</h2>
|
|
||||||
<p class="text-muted small mb-3">
|
|
||||||
Copiez cette URL dans votre lecteur RSS (Miniflux, Feedly, NetNewsWire…)
|
|
||||||
pour recevoir les nouveaux articles automatiquement.
|
|
||||||
</p>
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="text" class="form-control font-monospace small"
|
|
||||||
value="<?= htmlspecialchars($feedUrl) ?>"
|
|
||||||
id="rss-url-input" readonly>
|
|
||||||
<button class="btn btn-outline-secondary btn-sm"
|
|
||||||
onclick="navigator.clipboard.writeText(document.getElementById('rss-url-input').value).then(()=>{this.textContent='Copié ✓';setTimeout(()=>this.textContent='Copier',1500)})"
|
|
||||||
type="button">Copier</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2 class="h5 mb-3">Derniers articles</h2>
|
|
||||||
<div class="d-flex flex-column gap-3">
|
|
||||||
<?php foreach ($recentItems as $a):
|
|
||||||
$slug = $a['slug'] ?? '';
|
|
||||||
$pubDate = date('d/m/Y', (int)strtotime((string)($a['published_at'] ?? $a['created_at'] ?? '')));
|
|
||||||
$preview = mb_strimwidth(strip_tags($Parsedown->text($a['content'] ?? '')), 0, 100, '…');
|
|
||||||
$cat = trim($a['category'] ?? '');
|
|
||||||
?>
|
|
||||||
<a href="/post/<?= rawurlencode($slug) ?>" class="text-decoration-none text-reset d-block p-3 border rounded">
|
|
||||||
<div class="d-flex justify-content-between align-items-start gap-2 mb-1">
|
|
||||||
<span class="fw-semibold"><?= htmlspecialchars($a['title'] ?? '') ?></span>
|
|
||||||
<span class="text-muted small text-nowrap"><?= $pubDate ?></span>
|
|
||||||
</div>
|
|
||||||
<?php if ($cat !== ''): ?>
|
|
||||||
<span class="badge bg-secondary fw-normal mb-1"><?= htmlspecialchars($cat) ?></span>
|
|
||||||
<?php endif; ?>
|
|
||||||
<p class="text-muted small mb-0"><?= htmlspecialchars($preview) ?></p>
|
|
||||||
</a>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
$content = ob_get_clean();
|
|
||||||
$title = 'Flux RSS — varlog';
|
|
||||||
$canonical = $base . '/feed';
|
|
||||||
$metaRobots = 'noindex, follow';
|
|
||||||
include BASE_PATH . '/templates/layout.php';
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Flux XML pour les lecteurs RSS ─────────────────────────────────────────
|
|
||||||
require_once BASE_PATH . '/src/Parsedown.php';
|
|
||||||
$Parsedown = new Parsedown();
|
|
||||||
|
|
||||||
$total = count($all);
|
$total = count($all);
|
||||||
$lastPage = max(1, (int)ceil($total / FEED_PAGE_SIZE));
|
$lastPage = max(1, (int)ceil($total / FEED_PAGE_SIZE));
|
||||||
$page = max(1, min($lastPage, (int)($_GET['page'] ?? 1)));
|
$page = max(1, min($lastPage, (int)($_GET['page'] ?? 1)));
|
||||||
$items = array_slice($all, ($page - 1) * FEED_PAGE_SIZE, FEED_PAGE_SIZE);
|
$items = array_slice($all, ($page - 1) * FEED_PAGE_SIZE, FEED_PAGE_SIZE);
|
||||||
|
|
||||||
$feedUrlFn = static fn (int $p): string => $base . '/feed' . ($p > 1 ? '?page=' . $p : '');
|
$feedUrl = static fn (int $p): string => $base . '/feed' . ($p > 1 ? '?page=' . $p : '');
|
||||||
|
|
||||||
$lastBuild = '';
|
$lastBuild = '';
|
||||||
foreach ($all as $a) {
|
foreach ($all as $a) {
|
||||||
@@ -139,16 +63,16 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|||||||
<lastBuildDate><?= htmlspecialchars($lastBuild) ?></lastBuildDate>
|
<lastBuildDate><?= htmlspecialchars($lastBuild) ?></lastBuildDate>
|
||||||
|
|
||||||
<!-- Flux canonique (toujours page 1) -->
|
<!-- Flux canonique (toujours page 1) -->
|
||||||
<atom:link href="<?= htmlspecialchars($feedUrlFn(1)) ?>" rel="self" type="application/rss+xml"/>
|
<atom:link href="<?= htmlspecialchars($feedUrl(1)) ?>" rel="self" type="application/rss+xml"/>
|
||||||
|
|
||||||
<?php if ($page > 1): ?>
|
<?php if ($page > 1): ?>
|
||||||
<!-- Navigation entre pages -->
|
<!-- Navigation entre pages -->
|
||||||
<atom:link href="<?= htmlspecialchars($feedUrlFn(1)) ?>" rel="first" type="application/rss+xml"/>
|
<atom:link href="<?= htmlspecialchars($feedUrl(1)) ?>" rel="first" type="application/rss+xml"/>
|
||||||
<atom:link href="<?= htmlspecialchars($feedUrlFn($page - 1)) ?>" rel="previous" 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 ($page < $lastPage): ?>
|
||||||
<atom:link href="<?= htmlspecialchars($feedUrlFn($page + 1)) ?>" rel="next" type="application/rss+xml"/>
|
<atom:link href="<?= htmlspecialchars($feedUrl($page + 1)) ?>" rel="next" type="application/rss+xml"/>
|
||||||
<atom:link href="<?= htmlspecialchars($feedUrlFn($lastPage)) ?>" rel="last" 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 ($lastPage > 1): ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user