forked from Adleraci/adlerka.top
29 lines
1.0 KiB
PHP
29 lines
1.0 KiB
PHP
|
<?php
|
||
|
require "lib/sitemap.php";
|
||
|
|
||
|
function generateSitemap(): string {
|
||
|
global $routerConfig;
|
||
|
$site_dirs = array_diff(scandir($routerConfig["page_dir"]), array('.', '..'));
|
||
|
|
||
|
$sitemap = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
|
||
|
$sitemap .= '<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
|
||
|
|
||
|
foreach ($site_dirs as $site_dir) {
|
||
|
$pages_dir = array_diff(scandir($routerConfig["page_dir"] . $site_dir), array('.', '..'));
|
||
|
|
||
|
foreach ($pages_dir as $page_file) {
|
||
|
$page_file_tmp = explode(".", $page_file);
|
||
|
$page_basename = $page_file_tmp[0];
|
||
|
$page_location = "/" . $site_dir . "/" . $page_basename;
|
||
|
|
||
|
$sitemap .= '<url>' . PHP_EOL;
|
||
|
$sitemap .= '<loc>' . htmlspecialchars($page_location) . '</loc>' . PHP_EOL;
|
||
|
// You can add other optional tags like lastmod, changefreq, priority here if needed
|
||
|
$sitemap .= '</url>' . PHP_EOL;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$sitemap .= '</urlset>' . PHP_EOL;
|
||
|
|
||
|
return $sitemap;
|
||
|
}
|