diff --git a/sitemap.php b/sitemap.php new file mode 100644 index 0000000..c3e3f7f --- /dev/null +++ b/sitemap.php @@ -0,0 +1,109 @@ + + htmlspecialchars( $s, ENT_QUOTES | ENT_XML1, 'UTF-8' ); + +$urls = [ + [ + 'loc' => $baseUrl . '/', + 'priority' => '1.0', + 'changefreq' => 'always', + ], +]; + +foreach ( $langs as $lang ) { + $urls[] = [ + 'loc' => $baseUrl . '/' . rawurlencode( $lang ), + 'priority' => null, + 'changefreq' => 'weekly', + ]; +} + +$alternates = [ + [ + 'hreflang' => 'x-default', + 'href' => $baseUrl . '/', + ], +]; + +foreach ( $langs as $lang ) { + $alternates[] = [ + 'hreflang' => $toHreflang( $lang ), + 'href' => $baseUrl . '/' . rawurlencode( $lang ), + ]; +} + +header( 'Content-Type: application/xml; charset=UTF-8' ); + +echo "\n"; +echo "\n"; + +foreach ( $urls as $u ) { + echo "\t\n"; + echo "\t\t" . $esc( $u['loc'] ) . "\n"; + + if ( $u['priority'] !== null ) { + echo "\t\t" . $esc( $u['priority'] ) . "\n"; + } + + echo "\t\t" . $esc( $u['changefreq'] ) . "\n"; + + foreach ( $alternates as $alt ) { + echo "\t\t\n"; + } + + echo "\t\n"; +} + +echo "\n";