Skip to content

Instantly share code, notes, and snippets.

@philipdanielhayton
Created August 3, 2016 19:32
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 philipdanielhayton/72af734b6f0363fe4728ab4206cfba05 to your computer and use it in GitHub Desktop.
Save philipdanielhayton/72af734b6f0363fe4728ab4206cfba05 to your computer and use it in GitHub Desktop.
Umbraco Xml Sitemap using Razor
<system.webServer>
<rewrite>
<rules>
<rule name="Xml Sitemap">
<match url="sitemap.xml"/>
<action type="Rewrite" url="xmlsitemap"/>
</rule>
</rules>
</rewrite>
</system.webServer>
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
var root = Umbraco.TypedContentSingleAtXPath("//homePage");
umbraco.library.ChangeContentType("text/xml");
}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@renderUrl(root)
</urlset>
@helper renderUrl(IPublishedContent node)
{
var changeFreq = (node.HasValue("changeFrequency")) ? node.GetPropertyValue<string>("changeFrequency").ToLower() : "monthly";
var priority = node.GetPropertyValue<double>("crawlPriority");
<url>
<loc>@node.UrlAbsolute()</loc>
<lastmod>@node.UpdateDate.ToString("yyyy-MM-dd")</lastmod>
<changefreq>@changeFreq</changefreq>
<priority>@((priority == 0) ? 0.5 : priority)</priority>
</url>
if (node.Children.Any())
{
foreach (var child in node.Children)
{
@renderUrl(child)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment