SEO: canonical, sitemap.xml, robots.txt, JSON-LD, noindex admin
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
|
||||
<!-- SEO -->
|
||||
<meta name="description" content="<?= htmlspecialchars(($seoDescription ?? '') ?: 'Varlog est un journal personnel en ligne de Cédrix. Informatique, hack et loisirs techniques.') ?>">
|
||||
<meta name="robots" content="index, follow">
|
||||
<meta name="robots" content="<?= htmlspecialchars($metaRobots ?? 'index, follow') ?>">
|
||||
<link rel="canonical" href="<?= htmlspecialchars($canonical ?? $ogUrl ?? rtrim(APP_URL, '/') . '/') ?>">
|
||||
|
||||
<!-- Open Graph -->
|
||||
<meta property="og:title" content="<?= htmlspecialchars(($seoTitle ?? '') ?: ($title ?? 'varlog')) ?>">
|
||||
@@ -25,6 +26,10 @@
|
||||
<meta property="article:published_time" content="<?= htmlspecialchars(date('c', strtotime((string)$articlePublishedAt))) ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($jsonLd ?? '')): ?>
|
||||
<script type="application/ld+json"><?= $jsonLd ?></script>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- RSS autodiscovery -->
|
||||
<link rel="alternate" type="application/rss+xml" title="varlog" href="/feed">
|
||||
|
||||
|
||||
@@ -90,4 +90,28 @@ ob_start();
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
$title = 'varlog';
|
||||
|
||||
// Pages avec curseur = contenu non-canonique → noindex
|
||||
if (!empty($cursor)) {
|
||||
$metaRobots = 'noindex, follow';
|
||||
$canonical = rtrim(APP_URL, '/') . '/';
|
||||
} elseif ($filterCat !== '') {
|
||||
$canonical = rtrim(APP_URL, '/') . '/?' . http_build_query(['cat' => $filterCat]);
|
||||
} else {
|
||||
$canonical = rtrim(APP_URL, '/') . '/';
|
||||
}
|
||||
|
||||
// JSON-LD WebSite sur la page d'accueil sans filtre
|
||||
if (empty($cursor) && $filterCat === '') {
|
||||
$jsonLd = json_encode([
|
||||
'@context' => 'https://schema.org',
|
||||
'@type' => 'WebSite',
|
||||
'name' => 'varlog',
|
||||
'url' => rtrim(APP_URL, '/') . '/',
|
||||
'description' => 'Journal personnel de Cédrix. Informatique, hack et loisirs techniques.',
|
||||
'inLanguage' => 'fr-FR',
|
||||
'author' => ['@type' => 'Person', 'name' => 'Cédrix'],
|
||||
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
include __DIR__ . '/layout.php';
|
||||
|
||||
+37
-2
@@ -255,10 +255,45 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
$content = ob_get_clean();
|
||||
$title = htmlspecialchars($article['title']);
|
||||
$seoTitle = ($article['seo_title'] ?? '') ?: $article['title'];
|
||||
$seoDescription = $article['seo_description'] ?? '';
|
||||
$ogImage = $article['og_image'] ?? '';
|
||||
$ogType = 'article';
|
||||
$ogUrl = url('post/' . rawurlencode($article['slug'] ?? ''));
|
||||
$canonical = $ogUrl;
|
||||
$articlePublishedAt = $article['published_at'] ?? '';
|
||||
$mainClass = 'container-fluid';
|
||||
|
||||
// Auto-description depuis le contenu si le champ SEO est vide
|
||||
$seoDescription = $article['seo_description'] ?? '';
|
||||
if ($seoDescription === '') {
|
||||
$plain = strip_tags((new Parsedown())->text($article['content']));
|
||||
$plain = preg_replace('/\s+/', ' ', $plain);
|
||||
$seoDescription = mb_strimwidth(trim((string)$plain), 0, 155, '…');
|
||||
}
|
||||
|
||||
// og:image : cover puis fallback og_image du meta
|
||||
if ($ogImage === null || $ogImage === '') {
|
||||
$ogImage = $article['og_image'] ?? '';
|
||||
}
|
||||
|
||||
// JSON-LD Article
|
||||
$jsonLdData = [
|
||||
'@context' => 'https://schema.org',
|
||||
'@type' => 'BlogPosting',
|
||||
'headline' => $seoTitle,
|
||||
'description' => $seoDescription,
|
||||
'url' => $canonical,
|
||||
'datePublished' => date('c', strtotime((string)$articlePublishedAt)),
|
||||
'dateModified' => date('c', strtotime((string)($article['updated_at'] ?? $articlePublishedAt))),
|
||||
'author' => ['@type' => 'Person', 'name' => 'Cédrix'],
|
||||
'publisher' => [
|
||||
'@type' => 'Person',
|
||||
'name' => 'Cédrix',
|
||||
'url' => rtrim(APP_URL, '/'),
|
||||
],
|
||||
'inLanguage' => 'fr-FR',
|
||||
];
|
||||
if (!empty($ogImage)) {
|
||||
$jsonLdData['image'] = $ogImage;
|
||||
}
|
||||
$jsonLd = json_encode($jsonLdData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
|
||||
include __DIR__ . '/layout.php';
|
||||
|
||||
Reference in New Issue
Block a user