示例#1
0
 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);
     }
 }
示例#2
0
        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);
        }
示例#3
0
 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);
 }