Fix sitemap

Most importantly, make it work globally.
This commit is contained in:
2022-01-14 05:22:46 +01:00
parent 51c20d672e
commit 4af70fef6d
11 changed files with 33 additions and 193 deletions

26
sitemap.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
require __DIR__ . '/load.lib.php';
header('Content-Type: text/plain; charset=utf-8');
$directory = new \RecursiveDirectoryIterator('.');
$filter = new class($directory) extends \RecursiveFilterIterator {
public function accept() {
$components = explode('/', $this->current()->getPathname(), 4);
return ($this->current()->isDir() && !isset($components[2])) || (isset($components[2]) && $components[2] === 'pages');
}
};
$iterator = new \RecursiveIteratorIterator($filter);
$isHttps = isHttps();
foreach ($iterator as $info) {
if ($info->isFile()) {
[, $year, $pages, $page] = explode('/', $info->getPathname(), 4);
if (str_ends_with($page, '.pg') && !str_starts_with($page, 'cs/error/') && !str_starts_with($page, 'en/error/') && !str_starts_with($page, 'de/error/')) {
$file = substr($page, 0, -3);
$file = str_replace('/pages', '', $file);
echo ($isHttps ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/' . $year . '/' . $file . "\n";
}
}
}