SEO: canonical, sitemap.xml, robots.txt, JSON-LD, noindex admin
This commit is contained in:
+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