private static SiteMapUpdatePriority GetUpdatePriorityFromAttribute(XmlNode node) { SiteMapUpdatePriority priority = SiteMapUpdatePriority.Automatic; string stringValue = GetStringValueFromAttribute(node, UpdatePriorityAttributeName); if (!string.IsNullOrEmpty(stringValue)) { priority = ToEnum(stringValue, SiteMapUpdatePriority.Automatic); } return(priority); }
private HandlerCacheItem GetNewsSiteMap(HttpContextBase context) { const string DateFormat = "yyyy-MM-ddThh:mm:ssZ"; const string CacheKey = "newsSitemap"; Log.Info("Generating {0}".FormatWith(CacheKey)); HandlerCacheItem cacheItem; Cache.TryGet(CacheKey, out cacheItem); if (cacheItem == null) { XElement urlSet = new XElement(_ns + "urlset", new XAttribute("xmlns", _ns.ToString()), new XAttribute(XNamespace.Xmlns + "news", _googleNews.ToString())); PagedResult <IStory> pagedResult = StoryRepository.FindPublished(0, 1000); // Google only supports 1000 story int i = 0; foreach (IStory story in pagedResult.Result) { SiteMapUpdatePriority priority = (i < 50) ? SiteMapUpdatePriority.Critical : SiteMapUpdatePriority.Normal; AddStoryInNewsSiteMap(context, urlSet, story, priority, DateFormat); i += 1; } XDocument doc = new XDocument(); doc.Add(urlSet); cacheItem = new HandlerCacheItem { Content = doc.ToXml() }; if ((CacheDurationInMinutes > 0) && (!Cache.Contains(CacheKey))) { Cache.Set(CacheKey, cacheItem, SystemTime.Now().AddMinutes(CacheDurationInMinutes)); } } Log.Info("{0} generated".FormatWith(CacheKey)); return(cacheItem); }
private void AddStoryInNewsSiteMap(HttpContextBase context, XContainer target, IStory story, SiteMapUpdatePriority priority, string dateFormat) { XElement url = CreateEntry(context, Settings.RootUrl, "Detail", new { name = story.UniqueName }, story.LastActivityAt, SiteMapChangeFrequency.Daily, priority, false); string keyWords = story.BelongsTo.Name; if (story.HasTags()) { keyWords += ", " + string.Join(", ", story.Tags.Select(t => t.Name).ToArray()); } url.Add(new XElement(_googleNews + "news", new XElement(_googleNews + "publication_date", story.PublishedAt.Value.ToString(dateFormat, Constants.CurrentCulture)), new XElement(_googleNews + "keywords", keyWords))); target.Add(url); }
private static XElement BuildEntry(string url, IFormattable lastModified, SiteMapChangeFrequency frequency, SiteMapUpdatePriority priority, bool forMobile) { XElement x = new XElement(_ns + "url", new XElement(_ns + "loc", url)); if (forMobile) { x.Add(new XElement(_googleMobile + "mobile")); } else { string priorityString; switch (priority) { case SiteMapUpdatePriority.Critical: { priorityString = "0.9"; break; } case SiteMapUpdatePriority.High: { priorityString = "0.7"; break; } case SiteMapUpdatePriority.Low: { priorityString = "0.3"; break; } default: { priorityString = "0.5"; break; } } x.Add(new XElement(_ns + "lastmod", lastModified.ToString("yyyy-MM-dd", Constants.CurrentCulture)), new XElement(_ns + "changefreq", frequency.ToString().ToLowerInvariant()), new XElement(_ns + "priority", priorityString)); } return(x); }
private static XElement CreateEntry(HttpContextBase context, string rootUrl, string controllerName, string actionName, object values, IFormattable lastModified, SiteMapChangeFrequency frequency, SiteMapUpdatePriority priority, bool forMobile) { string url = string.Concat(rootUrl, GenerateUrlFrom(context, controllerName, actionName, values)); return(BuildEntry(url, lastModified, frequency, priority, forMobile)); }
public SiteMapNodeBuilder UpdatePriority(SiteMapUpdatePriority value) { siteMapNode.UpdatePriority = value; return this; }
public virtual SiteMapNodeBuilder UpdatePriority(SiteMapUpdatePriority value) { this.siteMapNode.UpdatePriority = value; return(this); }