Dear lovely Kirby people,
not sure if I am right in this category/forum to post this. I have site (moorwald.com) using Kirby and the ClickToNext Firma Theme. And I am trying to use the Cookbook Example to generate a sitemap.xml.
My code looks the following:
config.php
<?php
return [
'debug' => false,
'languages' => false,
'languages.detect' => false,
'panel' => [
'install' => false,
],
'content' => [
'locking' => false
],
'date' => [
'handler' => 'strftime'
],
'thumbs' => require __DIR__ . '/thumbs.php',
'email' => require __DIR__ . '/email.php',
'sitemap' => require __DIR__ . '/sitemap.php',
/**
* autoresize plugin
* https://github.com/medienbaecker/kirby-autoresize
*/
'medienbaecker.autoresize' => require __DIR__ . '/autoresize.php',
/**
* locator plugin
* https://github.com/sylvainjule/kirby-locator
*/
'sylvainjule.locator' => require __DIR__ . '/locator.php',
];
sitemap.php in the config folder:
<?php
return [
'routes' => [
[
'pattern' => 'sitemap.xml',
'action' => function() {
$pages = site()->pages()->index();
// fetch the pages to ignore from the config settings,
// if nothing is set, we ignore the error page
$ignore = kirby()->option('sitemap.ignore', ['error']);
$content = snippet('sitemap', compact('pages', 'ignore'), true);
// return response with correct header type
return new Kirby\Cms\Response($content, 'application/xml');
}
],
[
'pattern' => 'sitemap',
'action' => function() {
return go('sitemap.xml', 301);
}
]
],
'sitemap.ignore' => ['error'],
];
The sitemap.php snippet in the site/snippets folder:
<?= '<?xml version="1.0" encoding="utf-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($pages as $p): ?>
<?php if (in_array($p->uri(), $ignore)) continue ?>
<url>
<loc><?= html($p->url()) ?></loc>
<lastmod><?= $p->modified('c', 'date') ?></lastmod>
<priority><?= ($p->isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?></priority>
</url>
<?php endforeach ?>
</urlset>
But when I try to access moorwald.com/sitemap (or: moorwald.com/sitemap.xml) I always get a page with just the header and the footer, but no XML sitemap.
I am trying for days now and am a bit lost right now. Can anyone point me towards the right direction?