"Sitemap", "version" => "0.1.2", "author" => "Starbeamrainbowlabs", "description" => "Adds XML sitemap generation. Additional manual setup is required to notify search engines about the sitemap. See the Features FAQ in the documentation (or your wiki's credits page) for more information.", "id" => "page-sitemap", "code" => function() { global $settings, $env; /** * @api {get} ?action=sitemap Get an XML sitemap * @apiName Sitemap * @apiGroup Page * @apiPermission Anonymous */ /* * ██████ █████ ██ ██ * ██ ██ ██ ██ ██ ██ * ██████ ███████ ██ █ ██ * ██ ██ ██ ██ ██ ███ ██ * ██ ██ ██ ██ ███ ███ */ add_action("sitemap", function() { global $pageindex, $env; $full_url_stem = full_url(); // Reference: https://www.sitemaps.org/protocol.html $xml = new XmlWriter(); $xml->openMemory(); $xml->startDocument("1.0", "utf-8"); $xml->startElement("urlset"); $xml->writeAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"); foreach($pageindex as $pagename => $pagedata) { $xml->startElement("url"); $xml->writeElement("loc", "$full_url_stem?page=".rawurlencode($pagename)); if(isset($pagedata->lastmodified)) $xml->writeElement("lastmod", date("Y-m-d", $pagedata->lastmodified)); $xml->endElement(); } $xml->endElement(); $sitemap = $xml->flush(); header("content-type: application/xml"); header("content-disposition: inline"); header("content-length: " . strlen($sitemap)); exit($sitemap); }); if($env->is_admin) { add_help_section("947-sitemap", "Sitemap", "
$settings->sitename has a sitemap. You can find it here: sitemap.
In order for crawlers to discover this sitemap however, you must update your robots.txt
file for the domain $settings->sitename is hosted on to add a line like so:
Sitemap: http://example.com/path/to/index.php?action=sitemap
....replacing the relevant parts of the URL as appropriate. Note that more than one Sitemap:
directive is allowed in a single robots.txt
file.