diff --git a/site/config/config.php b/site/config/config.php index 1032d14..5fc4253 100644 --- a/site/config/config.php +++ b/site/config/config.php @@ -4,10 +4,33 @@ 'hooks' => [], 'routes' => [ [ + // articles overview is not a page itself but just a container 'pattern' => 'articles', 'action' => fn () => false + ], + [ + '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'], 'cache' => [ 'pages' => [ 'active' => true, diff --git a/site/snippets/sitemap.php b/site/snippets/sitemap.php new file mode 100644 index 0000000..b1ced25 --- /dev/null +++ b/site/snippets/sitemap.php @@ -0,0 +1,13 @@ +'; ?> + + + uri(), $ignore)) { + continue; + } ?> + + url()) ?> + modified('c', 'date') ?> + isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?> + + + \ No newline at end of file