private static void MergeSubtrees(SitemapItem subtreeRoot, SitemapItem subtreeToMergeInto) { List<SitemapItem> mergedChildItems = subtreeToMergeInto.Items; foreach (SitemapItem childNode in subtreeRoot.Items) { SitemapItem childKeywordToMergeInto = subtreeToMergeInto.Items.FirstOrDefault(i => i.Id == childNode.Id); if (childKeywordToMergeInto == null) { mergedChildItems.Add(childNode); } else { MergeSubtrees(childNode, childKeywordToMergeInto); } } // Ensure that merged child items are ordered correctly subtreeToMergeInto.Items = mergedChildItems.OrderBy(i => i.OriginalTitle).ToList(); }
private static bool IsHome(SitemapItem sitemapItem, Localization localization) { string homePath = string.IsNullOrEmpty(localization.Path) ? "/" : localization.Path; return sitemapItem != null && sitemapItem.Url != null && sitemapItem.Url.Equals(homePath, StringComparison.InvariantCultureIgnoreCase); }
/// <summary> /// Gets a Navigation subtree for the given Sitemap Item. /// </summary> /// <param name="sitemapItemId">The context <see cref="SitemapItem"/> identifier. Can be <c>null</c>.</param> /// <param name="filter">The <see cref="NavigationFilter"/> used to specify which information to put in the subtree.</param> /// <param name="localization">The context <see cref="Localization"/>.</param> /// <returns>A set of Sitemap Items representing the requested subtree.</returns> public IEnumerable<SitemapItem> GetNavigationSubtree(string sitemapItemId, NavigationFilter filter, Localization localization) { using (new Tracer(sitemapItemId, filter, localization)) { if (string.IsNullOrEmpty(sitemapItemId)) { return ExpandTaxonomyRoots(filter, localization); } // Extract Taxonomy TCM UI, Keyword TCM URI and/or Page TCM URI from the Sitemap Item ID string taxonomyId; string keywordId; string pageId; ParseSitemapItemId(sitemapItemId, out taxonomyId, out keywordId, out pageId); string publicationId = localization.LocalizationId; string taxonomyUri = string.Format("tcm:{0}-{1}-512", publicationId, taxonomyId); string keywordUri = string.IsNullOrEmpty(keywordId) ? taxonomyUri : string.Format("tcm:{0}-{1}-1024", publicationId, keywordId); string pageUri = string.Format("tcm:{0}-{1}-64", publicationId, pageId); IEnumerable<SitemapItem> result = new SitemapItem[0]; if (filter.IncludeAncestors) { TaxonomyNode taxonomyRoot = null; if (!string.IsNullOrEmpty(keywordId)) { taxonomyRoot = ExpandAncestorsForKeyword(keywordUri, taxonomyUri, filter, localization); } else if (!string.IsNullOrEmpty(pageId)) { taxonomyRoot = ExpandAncestorsForPage(pageUri, taxonomyUri, filter, localization); } if (taxonomyRoot != null) { if (filter.DescendantLevels != 0) { AddDescendants(taxonomyRoot, filter, localization); } result = new[] { taxonomyRoot }; } } else if (filter.DescendantLevels != 0 && string.IsNullOrEmpty(pageId)) { result = ExpandDescendants(keywordUri, taxonomyUri, filter, localization); } return result; } }
private static SitemapItem RewriteIndexPage(SitemapItem sitemapItem, SitemapItem parentSitemapItem) { // TODO: test on Url instead? return (sitemapItem.Title == "Index") ? parentSitemapItem : sitemapItem; }
/// <summary> /// Retrieves a rendered HTML site map /// </summary> /// <param name="entity">The sitemap entity</param> /// <returns>Rendered site map HTML.</returns> public virtual ActionResult SiteMap(SitemapItem entity) { SitemapItem model = SiteConfiguration.NavigationProvider.GetNavigationModel(WebRequestContext.Localization); SetupViewData(entity); return View(entity.MvcData.ViewName, model); }
private static void AssertProperSitemapItemForPage(SitemapItem pageSitemapItem, string subject) { StringAssert.Matches(pageSitemapItem.Id, new Regex(@"t\d+-p\d+"), subject + ".Id"); Assert.AreEqual(SitemapItem.Types.Page, pageSitemapItem.Type, subject + ".Type"); Assert.IsNotNull(pageSitemapItem.Title, subject + ".Title"); Assert.IsNotNull(pageSitemapItem.Url, subject + ".Url"); Assert.IsNotNull(pageSitemapItem.PublishedDate, subject + ".PublishedDate"); Assert.IsTrue(pageSitemapItem.Visible, subject + ".Visible"); }