private void BuildSitemap(GoogleSiteMap sitemap, IEnumerable<Entities.Page> pages) { foreach (var page in pages) { AddPage(sitemap, page); if (page.Children.Any()) BuildSitemap(sitemap, page.Children); } }
public async Task Invoke(HttpContext httpContext) { if (httpContext.Request.Path.Value.Contains("sitemap.xml")) { var pages = pageService.Get().MakeTree(); var sitemap = new GoogleSiteMap(); BuildSitemap(sitemap, pages); httpContext.Response.ContentType = "text/xml"; await httpContext.Response.WriteAsync(sitemap.GetXMLString(), Encoding.UTF8); //return Content(sitemap.GetXMLString(), "text/xml", Encoding.UTF8); return; } await next.Invoke(httpContext); }
private void AddPage(GoogleSiteMap sitemap, Entities.Page page) { var url = (context.Site.Url + "/" + page.Url).TrimEnd(new[] { '/' }); var properties = page.GetProperties<GoogleSitemapProperties>(); sitemap.Create(url, properties.LastModified, properties.Priority, properties.ChangeFrequency); }