Skip to content

pixl8/preside-ext-xml-sitemap

Repository files navigation

Preside Extension: XML Sitemap Extension

An extension for Preside that will create sitemap.xml for all active pages.

Installation

From the root of your application, type the following command:

box install preside-ext-sitemap

.gitignore

The sitemap file will be generated by the scheduled task in your webroot. You should add the following pattern to your .gitignore file to keep it out of your repository:

/sitemap*.xml

Making your sitemap available to Google

There are two different ways to make your sitemap available to Google:

OR

  • Insert the following line anywhere in your robots.txt file, specifying the path to your sitemap:

    Sitemap: http://mydomain.com/sitemap.xml

Adding custom pages to your sitemap

By default, the extension will add all the active pages from your sitetree to the sitemap.

It may be that you have some custom, dynamically generated pages which you also wish to add (for example, news pages stored in a separate Preside object). There is an interception point, postPrepareXmlSitemapPages, which is called before the pages get built as an XML sitemap file. Available interceptData is pages (the array of sitemap pages already prepared) and siteId.

You can use whatever logic you want in your interceptor to gather pages to append to the array. Each array item is a struct containing the following keys:

  • loc (required) - the complete URL of the page
  • lastmod (required) - the date the content was last modified
  • priority (optional) - the priority of the page; one of important, high, normal, low. Defaults to normal
  • changeFreq (optional) - how often you expect the content to change; one of always, hourly, daily, weekly, monthly, yearly, never. Defaults to always

Multiple sites

The extension handles multiple sites out of the box. As noted above, the postPrepareXmlSitemapPages interceptor receives the siteId of the current site, for you to handle however you like.

In your Preside site settings page, there is a Sitemap tab. On here you will find a couple of options.

By choosing Exclude from sitemap, the site will be skipped completely when generating sitemaps.

You may also set a Sitemap suffix which is used to create the sitempa's filename. This is advisable when working with multiple sites, as each site will have its own sitemap. For instance, if you set a value of subsite here, the site's sitemap will be saved to /sitemap-subsite.xml. If you leave this empty, the file will be saved to /sitemap.xml.