Created
August 3, 2016 19:32
-
-
Save philipdanielhayton/72af734b6f0363fe4728ab4206cfba05 to your computer and use it in GitHub Desktop.
Umbraco Xml Sitemap using Razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<system.webServer> | |
<rewrite> | |
<rules> | |
<rule name="Xml Sitemap"> | |
<match url="sitemap.xml"/> | |
<action type="Rewrite" url="xmlsitemap"/> | |
</rule> | |
</rules> | |
</rewrite> | |
</system.webServer> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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