/// <summary> /// Gets Navigation Links for the breadcrumb trail for the given request URL path. /// </summary> /// <param name="requestUrlPath">The request URL path.</param> /// <param name="localization">The Localization.</param> /// <returns>The Navigation Links.</returns> public virtual NavigationLinks GetBreadcrumbNavigationLinks(string requestUrlPath, Localization localization) { using (new Tracer(requestUrlPath, localization)) { int levels = requestUrlPath.Split('/').Length; SitemapItem currentItem = GetNavigationModel(localization); // Start with Sitemap root. List <Link> links = new List <Link> { currentItem.CreateLink(localization) }; while (levels > 1 && currentItem.Items != null) { currentItem = currentItem.Items.FirstOrDefault(i => requestUrlPath.StartsWith(i.Url, StringComparison.InvariantCultureIgnoreCase)); if (currentItem == null) { break; } links.Add(currentItem.CreateLink(localization)); levels--; } return(new NavigationLinks { Items = links }); } }
/// <summary> /// Gets Navigation Links for the breadcrumb trail for the given request URL path. /// </summary> /// <param name="requestUrlPath">The request URL path.</param> /// <param name="localization">The Localization.</param> /// <returns>The Navigation Links.</returns> public NavigationLinks GetBreadcrumbNavigationLinks(string requestUrlPath, Localization localization) { using (new Tracer(requestUrlPath, localization)) { var navModel = GetNavigationModel(localization); if (navModel == null) { return(null); } return(SiteConfiguration.CacheProvider.GetOrAdd( $"GetBreadcrumbNavigationLinks:{requestUrlPath}-{localization.Id}", CacheRegions.DynamicNavigation, () => { List <Link> breadcrumb = new List <Link>(); SitemapItem sitemapItem = navModel.FindSitemapItem(requestUrlPath.NormalizePageUrlPath()); if (sitemapItem != null) { // Build a breadcrumb of ancestors, excluding the Taxonomy Root. bool hasHome = false; while (sitemapItem.Parent != null) { breadcrumb.Insert(0, sitemapItem.CreateLink(localization)); hasHome = IsHome(sitemapItem, localization); sitemapItem = sitemapItem.Parent; } // The Home TaxonomyNode/Keyword may be a top-level sibling instead of an ancestor if (!hasHome) { SitemapItem home = sitemapItem.Items.FirstOrDefault(i => IsHome(i, localization)); if (home != null) { breadcrumb.Insert(0, home.CreateLink(localization)); } } } return new NavigationLinks { Items = breadcrumb }; })); } }
/// <summary> /// Gets Navigation Links for the breadcrumb trail for the given request URL path. /// </summary> /// <param name="requestUrlPath">The request URL path.</param> /// <param name="localization">The Localization.</param> /// <returns>The Navigation Links.</returns> public NavigationLinks GetBreadcrumbNavigationLinks(string requestUrlPath, Localization localization) { using (new Tracer(requestUrlPath, localization)) { SitemapItem navModel = GetNavigationModel(localization); if (!(navModel is TaxonomyNode)) { // No Navigation Taxonomy found in this Localization; fallback to the StaticNavigationProvider. return(_fallbackNavigationProvider.GetBreadcrumbNavigationLinks(requestUrlPath, localization)); } SitemapItem sitemapItem = navModel.FindSitemapItem(requestUrlPath.NormalizePageUrlPath()); List <Link> breadcrumb = new List <Link>(); if (sitemapItem != null) { // Build a breadcrumb of ancestors, excluding the Taxonomy Root. bool hasHome = false; while (sitemapItem.Parent != null) { breadcrumb.Insert(0, sitemapItem.CreateLink(localization)); hasHome = IsHome(sitemapItem, localization); sitemapItem = sitemapItem.Parent; } // The Home TaxonomyNode/Keyword may be a top-level sibling instead of an ancestor if (!hasHome) { SitemapItem home = sitemapItem.Items.FirstOrDefault(i => IsHome(i, localization)); if (home != null) { breadcrumb.Insert(0, home.CreateLink(localization)); } } } return(new NavigationLinks { Items = breadcrumb }); } }