diff --git a/lib/sitemap.php b/lib/sitemap.php index 63f67ac..09fa79d 100644 --- a/lib/sitemap.php +++ b/lib/sitemap.php @@ -7,8 +7,12 @@ function generateSitemap(): string { $site_dirs = array_diff(scandir($routerConfig["page_dir"]), array('.', '..')); + $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; + $domain = $_SERVER['HTTP_HOST']; + $subdomain = ""; // You may need to modify this based on your subdomain logic + $sitemap = '' . PHP_EOL; - $sitemap .= '' . PHP_EOL; + $sitemap .= '' . PHP_EOL; foreach ($site_dirs as $site_dir) { $pages_dir = array_diff(scandir($routerConfig["page_dir"] . $site_dir), array('.', '..')); @@ -17,7 +21,8 @@ function generateSitemap(): string { $page_file_tmp = explode(".", $page_file); $page_basename = $page_file_tmp[0]; $page_file_path = $routerConfig["page_dir"] . $site_dir . "/" . $page_file; - $page_location = "/" . $site_dir . "/" . $page_basename; + + $page_location = $protocol . "://" . $subdomain . $domain . "/" . $site_dir . "/" . $page_basename; if ($page_file_tmp[1] == "html") { $page_tmp = file_get_contents($page_file_path);