Generate sitemap dynamically

dev
gravel 1 year ago
parent 984c862722
commit fc14e4586a
Signed by: gravel
GPG Key ID: C0538F3C906B308F

3
.gitignore vendored

@ -1,9 +1,10 @@
# Fetched room info # Fetched room info
output/servers.json output/servers.json
# Generated HTML # Generated files
output/*.html output/*.html
output/**/*.html output/**/*.html
output/sitemap.xml
# Downloaded QR codes # Downloaded QR codes
output/qr-codes output/qr-codes

@ -1,27 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?php
require_once '+getenv.php';
function loc_lastmod(string $rel_loc, ?string $changes_under_root = null) {
global $SITE_CANONICAL_URL, $DOCUMENT_ROOT, $TEMPLATES_ROOT;
$root = $changes_under_root ?? $TEMPLATES_ROOT;
$ext = ($root == $TEMPLATES_ROOT) ? "php" : "html";
?>
<loc><?=$SITE_CANONICAL_URL . $rel_loc?></loc>
<lastmod><?=date('c', filemtime("$root$rel_loc/index.$ext"))?></lastmod>
<?php
}
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://sessioncommunities.online/</loc> <?=loc_lastmod("", changes_under_root: $DOCUMENT_ROOT)?>
<changefreq>hourly</changefreq> <changefreq>hourly</changefreq>
<priority>1.0</priority> <priority>1.0</priority>
</url> </url>
<url> <url>
<loc>https://sessioncommunities.online/about</loc> <?=loc_lastmod("/about")?>
<changefreq>monthly</changefreq> <changefreq>monthly</changefreq>
<priority>0.7</priority> <priority>0.7</priority>
</url> </url>
<url> <url>
<loc>https://sessioncommunities.online/privacy</loc> <?=loc_lastmod("/privacy")?>
<changefreq>monthly</changefreq> <changefreq>monthly</changefreq>
<priority>0.0</priority> <priority>0.0</priority>
</url> </url>
<url> <url>
<loc>https://sessioncommunities.online/donate</loc> <?=loc_lastmod("/donate")?>
<changefreq>monthly</changefreq> <changefreq>monthly</changefreq>
<priority>0.0</priority> <priority>0.0</priority>
</url> </url>
<url> <url>
<loc>https://sessioncommunities.online/instructions</loc> <?=loc_lastmod("/instructions")?>
<changefreq>monthly</changefreq> <changefreq>monthly</changefreq>
<priority>0.0</priority> <priority>0.0</priority>
</url> </url>
Loading…
Cancel
Save