feat: intégration plugin Kirby SEO
All checks were successful
Deploy / Deploy to Production (push) Successful in 22s
All checks were successful
Deploy / Deploy to Production (push) Successful in 22s
- Ajout de tobimori/kirby-seo via Composer
- snippet('seo/head') dans header.php (remplace les meta manuels)
- snippet('seo/schemas') dans footer.php pour JSON-LD
- Onglet SEO ajouté dans site.yml et tous les blueprints de pages
- Configuration SEO dans config.php (sitemap, robots, canonicalBase TODO)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
baab2fb3a1
commit
58c31ea391
133 changed files with 9201 additions and 253 deletions
48
site/plugins/kirby-seo/config/site-methods.php
Normal file
48
site/plugins/kirby-seo/config/site-methods.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Http\Url;
|
||||
use Kirby\Toolkit\Str;
|
||||
use tobimori\Seo\Seo;
|
||||
|
||||
return [
|
||||
'schema' => fn ($type) => Seo::option('components.schema')::getInstance($type),
|
||||
'schemas' => fn () => Seo::option('components.schema')::getInstances(),
|
||||
'lang' => fn () => Seo::option('components.meta')::normalizeLocale(Seo::option('default.locale', args: [$this->homePage()]), '-'),
|
||||
'canonicalFor' => function (string $url, bool $useRootUrl = false) {
|
||||
// Determine the base URL
|
||||
$base = Seo::option('canonical.base', Seo::option('canonicalBase'));
|
||||
if (!$base) {
|
||||
// If useRootUrl is true or this is a multilang site requesting root URL, use kirby()->url()
|
||||
if ($useRootUrl && kirby()->multilang()) {
|
||||
$base = kirby()->url();
|
||||
} else {
|
||||
$base = $this->url();
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::startsWith($url, $base)) {
|
||||
$canonicalUrl = $url;
|
||||
} else {
|
||||
$path = Url::path($url);
|
||||
$canonicalUrl = url($base . '/' . $path);
|
||||
}
|
||||
|
||||
$trailingSlash = Seo::option('canonical.trailingSlash', false);
|
||||
if ($trailingSlash) {
|
||||
// check if URL has a file extension (like .xml, .jpg, .pdf, etc.)
|
||||
$path = parse_url($canonicalUrl, PHP_URL_PATH) ?? '';
|
||||
$pathInfo = pathinfo($path);
|
||||
$hasExtension = !empty($pathInfo['extension'] ?? null);
|
||||
|
||||
// Only add trailing slash if:
|
||||
// - URL doesn't already have one
|
||||
// - URL doesn't have a file extension
|
||||
// - URL isn't just the base domain
|
||||
if (!Str::endsWith($canonicalUrl, '/') && !$hasExtension && $canonicalUrl !== $base) {
|
||||
$canonicalUrl .= '/';
|
||||
}
|
||||
}
|
||||
|
||||
return $canonicalUrl;
|
||||
}
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue