private void Add(SiteMapEntry se) { if (_seen.Contains(se.Url)) { return; } var pos = se.Url.IndexOf(WebSession.Current.SiteId, StringComparison.InvariantCultureIgnoreCase); if (pos != -1) { var cultureCodeSegment = se.Url.Substring(pos + 5); pos = cultureCodeSegment.IndexOf("/", StringComparison.InvariantCultureIgnoreCase); if (pos != -1) { cultureCodeSegment = cultureCodeSegment.Substring(0, pos); } SiteInfo siteInfo; if (!cultureCodeSegment.Equals(WebSession.Current.CultureCode, StringComparison.InvariantCultureIgnoreCase) && _siteConfig.TryGetSiteInfo(WebSession.Current.SiteId, cultureCodeSegment, out siteInfo)) { return; // because it is a url that contains a different culture code } } _entries.Add(se); _seen.Add(se.Url); }
private void AddCategory(CategoryViewModel cvm) { object cp; var url = _linkGenerator.GenerateCategoryLink(cvm.CategoryId, null, out cp); var categoryPage = cp as CatalogPage; if (categoryPage != null && !categoryPage.IncludeInSitemap()) { return; } var sme = new SiteMapEntry { Title = cvm.DisplayName, Url = url, LastModified = DateTime.Now }; if (categoryPage != null) { sme.LastModified = categoryPage.Published; sme.ChangeFrequency = categoryPage.ChangeFrequency; sme.Priority = categoryPage.Priority; sme.Title = categoryPage.Title; } Add(sme); }
/// <summary> /// Adds the given item to the sitemap with the name as the display value /// </summary> /// <param name="id">The unique id of the content item to which the map will point</param> /// <param name="name">The display name to appear in the navigation</param> /// <returns></returns> public async Task <ActionResult> Add(string id, string name) { var entry = new SiteMapEntry { ContentIdentifier = id, Title = name }; await _mapRepo.AddItemToSiteMapAsync(entry); return(View("SiteMapConfirm")); }
public string SerializeUrlSet(SiteMapEntry item, string template) { return($"<url>" + $"<loc>{string.Concat(_settings.Host, template.Replace("{id}", item.Id.ToString()))}</loc>" + $"<lastmod>{item.DateModified.ToString("s")}</lastmod>" + $"<changefreq>daily</changefreq>" + $"<priority>0.5</priority>" + $"</url>"); }
private void AddContentPages(string url) { var root = GetRootItem(url); // if (root is LanguageRoot) root = root.Parent; // TODO rewrite url to be below LanguageRoot foreach (var item in GetDescendants(root)) { if (!item.IsPublished()) { continue; } var page = item as PageModelBase; if (page != null && !page.IncludeInSitemap()) { continue; } // special case of generic ProductPage and CatalogPage // have to configure generic page in N2 to include in sitemap in order to get all the products and categories to be included in sitemap // but don't want the generic page naked without reference to an ID to be in the sitemap var productPage = item as ProductPage; if ((productPage != null && string.IsNullOrEmpty(productPage.ProductID)) || (item is CatalogPage && string.IsNullOrEmpty(((CatalogPage)item).CategoryID))) { continue; } if (productPage != null) { long pid; if (long.TryParse(productPage.ProductID, out pid)) { var prod = _catalogApi.GetProductAsync(_catalogApi.GetProductUri(pid)).Result; if (prod != null && prod.CustomAttributes.ValueByName("NoIndex", false)) { continue; } } } var se = new SiteMapEntry { Title = item.Title, Url = item.Url, LastModified = item.Published, }; if (page != null) { se.ChangeFrequency = page.ChangeFrequency; se.Priority = page.Priority; } Add(se); } }
public async Task AddItemToSiteMapAsync(SiteMapEntry newEntry) { var map = await GetMapAsync().ConfigureAwait(false); if (map != null) { map.Entries.Add(newEntry); await SaveMapAsync(map).ConfigureAwait(false); } }
protected virtual void WriteItem(XmlWriter writer, string baseUrl, SiteMapEntry item) { // <url> if (item.Url.StartsWith("http")) { return; } writer.WriteStartElement("url"); #if DEBUG2 if (!string.IsNullOrEmpty(item.ID)) { writer.WriteElementString("id", item.ID); } if (!string.IsNullOrEmpty(item.Title)) { writer.WriteElementString("title", item.Title); } if (!string.IsNullOrEmpty(item.Class)) { writer.WriteElementString("class", item.Class); } #endif writer.WriteElementString("loc", baseUrl + item.Url); if (item.LastModified.HasValue) { writer.WriteElementString("lastmod", item.LastModified.Value.ToString("yyyy-MM-dd")); // Google doesn't like IS0 8601/W3C } if (item.ChangeFrequency != ChangeFrequencyEnum.Undefined) { writer.WriteElementString("changefreq", item.ChangeFrequency.ToString().ToLowerInvariant()); } writer.WriteElementString("priority", item.Priority.ToString(CultureInfo.InvariantCulture)); // </url> writer.WriteEndElement(); }
private void AddProduct(Product product) { bool noIndex; var noIndexAttr = product.CustomAttributes.ValueByName("NoIndex"); if (noIndexAttr == null || !bool.TryParse(noIndexAttr, out noIndex)) { noIndex = false; } if (!product.DisplayableProduct || noIndex) { return; } object pp; var url = _linkGenerator.GenerateProductLink(product.Id, out pp); var productPage = pp as ProductPage; if (productPage != null && !productPage.IncludeInSitemap()) { return; } var sme = new SiteMapEntry { Title = product.DisplayName, Url = url, LastModified = DateTime.Now }; if (productPage != null) { sme.LastModified = productPage.Published; sme.ChangeFrequency = productPage.ChangeFrequency; sme.Priority = productPage.Priority; sme.Title = productPage.Title; } Add(sme); }
public Task AddItemToSiteMapAsync(SiteMapEntry newEntry) { _map.Entries.Add(newEntry); return(Task.CompletedTask); }