/// <summary> /// Generates url element /// </summary> /// <param name="url"></param> /// <param name="item"></param> /// <param name="sitemapSiteConfiguration"></param> /// <param name="xml"></param> protected virtual void GenerateUrlElement(String url, Item item, SitemapSiteConfiguration sitemapSiteConfiguration, XmlTextWriter xml) { sitemapSiteConfiguration.ItemsCount++; xml.WriteStartElement("url"); xml.WriteElementString("loc", url); if (item != null) { var lastModified = item.Statistics.Updated.ToString("yyyy-MM-ddThh:mm:sszzz"); xml.WriteElementString("lastmod", lastModified); String changeFrequency = sitemapSiteConfiguration.GetChangeFrequency(item); if (changeFrequency != String.Empty) { xml.WriteElementString("changefreq", changeFrequency); } String priority = sitemapSiteConfiguration.GetPriority(item); if (priority != String.Empty) { xml.WriteElementString("priority", priority); } } xml.WriteEndElement(); }
/// <summary> /// Processes all items in site under root path /// </summary> /// <param name="items">List of Items</param> /// <param name="sitemapSiteConfiguration">Current sitemap configuration</param> /// <param name="options">Url Options</param> public List <UrlElement> ProcessItems(List <Item> items, SitemapSiteConfiguration sitemapSiteConfiguration, UrlOptions options) { var urlElements = new List <UrlElement>(); if (sitemapSiteConfiguration == null) { return(null); } Sitecore.Context.SetActiveSite(sitemapSiteConfiguration.Site.Name); foreach (Item item in items) { if (item.Versions.Count > 0) { if (IsIncluded(item, sitemapSiteConfiguration)) { sitemapSiteConfiguration.ItemsCount++; string url = LinkManager.GetItemUrl(item, options); if (string.IsNullOrEmpty(url)) { continue; } url = DynamicSitemapHelper.EnsureHttpPrefix(url, sitemapSiteConfiguration.ForceHttps); if (!String.IsNullOrEmpty(sitemapSiteConfiguration.ServerHost)) { url = DynamicSitemapHelper.ReplaceHost(url, sitemapSiteConfiguration.ServerHost); } if (string.IsNullOrEmpty(url)) { continue; } urlElements.Add( new UrlElement() { Location = url, LastModification = item.Statistics.Updated, ChangeFrequency = sitemapSiteConfiguration.GetChangeFrequency(item), Priority = sitemapSiteConfiguration.GetPriority(item) }); } } } if (sitemapSiteConfiguration.ItemsProcessor != null) { var urlItems = sitemapSiteConfiguration.ItemsProcessor.ProcessItems(sitemapSiteConfiguration); urlItems.AddRange(urlItems); } return(urlElements); }
/// <summary> /// Processes all items in site under root path /// </summary> /// <param name="items">List of Items</param> /// <param name="sitemapSiteConfiguration">Current sitemap configuration</param> /// <param name="options">Url Options</param> public List <UrlElement> ProcessItems(List <Item> items, SitemapSiteConfiguration sitemapSiteConfiguration, UrlOptions options) { var urlElements = new List <UrlElement>(); foreach (var item in items) { if (item.Versions.Count > 0) { //if (DynamicSitemapHelper.IsWildcard(item)) //{ // PrepareDynamicItems(item, sitemapSiteConfiguration, xml); //} if (IsIncluded(item, sitemapSiteConfiguration)) { sitemapSiteConfiguration.ItemsCount++; var url = LinkManager.GetItemUrl(item, options); url = DynamicSitemapHelper.EnsureHttpPrefix(url, sitemapSiteConfiguration.ForceHttps); if (!String.IsNullOrEmpty(sitemapSiteConfiguration.ServerHost)) { url = DynamicSitemapHelper.ReplaceHost(url, sitemapSiteConfiguration.ServerHost); } urlElements.Add( new UrlElement() { Location = url, LastModification = item.Statistics.Updated, ChangeFrequency = sitemapSiteConfiguration.GetChangeFrequency(item), Priority = sitemapSiteConfiguration.GetPriority(item) }); } } } if (sitemapSiteConfiguration.ItemsProcessor != null) { var urlItems = sitemapSiteConfiguration.ItemsProcessor.ProcessItems(sitemapSiteConfiguration); urlItems.AddRange(urlItems); } return(urlElements); }