From 476d237b402bfc7e3bb31d47fdf2f5e0e42299ba Mon Sep 17 00:00:00 2001 From: Tobias Feigel Date: Mon, 22 Sep 2025 09:50:12 +0200 Subject: [PATCH] Added Sitemap --- site/config/config.php | 23 +++++++++++++++++++++++ site/snippets/sitemap.php | 11 +++++++++++ 2 files changed, 34 insertions(+) create mode 100644 site/snippets/sitemap.php diff --git a/site/config/config.php b/site/config/config.php index ab6e282..236cdb3 100644 --- a/site/config/config.php +++ b/site/config/config.php @@ -6,5 +6,28 @@ return [ 'vue' => [ 'compiler' => false ] + ], + '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); + } + ] ], ]; diff --git a/site/snippets/sitemap.php b/site/snippets/sitemap.php new file mode 100644 index 0000000..9510636 --- /dev/null +++ b/site/snippets/sitemap.php @@ -0,0 +1,11 @@ +'; ?> + + + uri(), $ignore)) continue ?> + + url()) ?> + modified('c', 'date') ?> + isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?> + + + \ No newline at end of file