Skip to content

Instantly share code, notes, and snippets.

@StefanoChiodino
Last active March 5, 2017 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanoChiodino/da7e76e8ca87951623e06fcfb5df3df4 to your computer and use it in GitHub Desktop.
Save StefanoChiodino/da7e76e8ca87951623e06fcfb5df3df4 to your computer and use it in GitHub Desktop.
Sitemap for Umbraco with SEO metadata package installed
@using Page = Website.Core.Models.UmbracoPage
@inherits UmbracoTemplatePage
@{
Layout = null;
// Forces the doc type declaration on the first line.
Response.Write(@"<?xml version=""1.0"" encoding=""UTF-8"" ?>");
Response.ContentType = "text/xml";
var root = Model.Content.Ancestor<Page>();
}
@*http://www.sitemaps.org/protocol.html*@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@OutputAndRecurse(root)
</urlset>
@helper OutputAndRecurse(Page node)
{
var metadata = node.Metadata;
var sitemapXmlPriority = node.SitemapXmlPriority;
var sitemapXmlChangeFrequency = node.SitemapXmlChangeFrequency;
if ((metadata == null || !metadata.NoIndex)
&& node.IsVisible()
&& node.Id != Model.Content.Id)
{
<url>
<loc>@node.UrlWithDomain()</loc>
<lastmod>@(string.Format("{0:s}+00:00", node.UpdateDate))</lastmod>
@if (!string.IsNullOrWhiteSpace(sitemapXmlPriority))
{
<priority>@sitemapXmlPriority</priority>
}
@if (!string.IsNullOrWhiteSpace(sitemapXmlChangeFrequency))
{
<changefreq>@sitemapXmlChangeFrequency</changefreq>
}
</url>
}
foreach (var child in node.Children<Page>())
{
@OutputAndRecurse(child)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment