Last active
March 5, 2017 10:06
-
-
Save StefanoChiodino/da7e76e8ca87951623e06fcfb5df3df4 to your computer and use it in GitHub Desktop.
Sitemap for Umbraco with SEO metadata package installed
This file contains 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
@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