How to Make A Site Map

Every site needs a sitemap, and Radiant can generate one automatically for the whole site and provide a simple way to exempt pages from the sitemap, all with the built in functionality!

Create a child of the homepage titled Sitemap and that somewhere in its Body part contains this:

<ul>
  <r:find url="/">
      <r:snippet name="sitemapper" />
  </r:find>
</ul>

Then create a snippet title sitemapper that contains this:

<r:children:each by="title" order="asc">
  <r:unless_content part="no-map">
    <li>
      <r:link />
      <ul>
        <r:snippet name="sitemapper" />
      </ul>
    </li>
  </r:unless_content>
</r:children:each>

Then add a new Page Part titled no-map to pages that you do not wish to appear in the Site Map, such a Stylesheet page and the Sitemap page itself.

Using a derivate of this technique you can also generate a sitemap.xml to submit to Google.

First create a new layout with text/xml as Content-Type, and the following content:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <r:content />
</urlset>

Then create a Google Sitemap page, with sitemap.xml as slug. Set the layout to the one we created earlier and fill it with this content:

<r:find url="/">
  <r:snippet name="xml_sitemapper" />
</r:find>

The actual magic happens in the xml_sitemapper snippet :

<r:children:each by="title" order="asc">
  <r:unless_content part="no-map">
    <url>
      <loc>http://yourdomain.com<r:url /></loc>
      <lastmod><r:date format="%Y-%m-%d" /></lastmod>
      <changefreq>
        <r:if_content part="changefreq">
          <r:content part="changefreq" />
        </r:if_content>
        <r:unless_content part="changefreq">weekly</r:unless_content>
      </changefreq>
    </url>
    <r:snippet name="xml_sitemapper" />
  </r:unless_content>
</r:children:each>

The no-map page part has the same meaning of the simpler sitemapper snippet, while the changefreq page part is used to override the default for the changefreq property (weekly).