|
7 | 7 | using Elastic.Documentation; |
8 | 8 | using Elastic.Documentation.Configuration.LegacyUrlMappings; |
9 | 9 | using Elastic.Documentation.Configuration.Products; |
| 10 | +using Elastic.Documentation.Configuration.TableOfContents; |
10 | 11 | using Elastic.Documentation.Configuration.Versions; |
11 | 12 | using Elastic.Documentation.Site.FileProviders; |
12 | 13 | using Elastic.Documentation.Site.Navigation; |
@@ -102,9 +103,27 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc |
102 | 103 | fullNavigationRenderResult |
103 | 104 | ); |
104 | 105 |
|
105 | | - var currentBaseVersion = legacyPages is { Count: > 0 } |
106 | | - ? $"{legacyPages.ElementAt(0).Product.VersioningSystem?.Base.Major}.{legacyPages.ElementAt(0).Product.VersioningSystem?.Base.Minor}+" |
107 | | - : $"{DocumentationSet.Context.VersionsConfiguration.VersioningSystems[VersioningSystemId.Stack].Base.Major}.{DocumentationSet.Context.VersionsConfiguration.VersioningSystems[VersioningSystemId.Stack].Base.Minor}+"; |
| 106 | + // Acquiring the versioning system for the current page: |
| 107 | + // 1. If the page has a legacy page mapping, use the versioning system of the legacy page |
| 108 | + // 2. If the page's docset has a name with a direct product maatch, use the versioning system of the product |
| 109 | + // 3. If the page's docset has a table of contents entry with a direct product match, use the versioning system of the product |
| 110 | + // 4. Fallback to the stack versioning system |
| 111 | + VersioningSystem pageVersioning = null!; |
| 112 | + if (legacyPages is not null && legacyPages.Count > 0) |
| 113 | + pageVersioning = legacyPages.ElementAt(0).Product.VersioningSystem!; |
| 114 | + else if (DocumentationSet.Context.ProductsConfiguration.Products.TryGetValue(DocumentationSet.Name, out var belonging)) |
| 115 | + pageVersioning = belonging.VersioningSystem!; |
| 116 | + else if (DocumentationSet.Configuration.TableOfContents.FirstOrDefault(t => t is TocReference tRef && !tRef.Source.LocalPath.Equals("/")) is TocReference tocRef) |
| 117 | + { |
| 118 | + var productFound = DocumentationSet.Context.ProductsConfiguration.Products.TryGetValue(tocRef.Source.LocalPath.Trim('/'), out var tocProduct); |
| 119 | + if (productFound && tocProduct is not null) |
| 120 | + pageVersioning = tocProduct.VersioningSystem!; |
| 121 | + } |
| 122 | + else |
| 123 | + pageVersioning = DocumentationSet.Context.VersionsConfiguration.VersioningSystems[VersioningSystemId.Stack]; |
| 124 | + |
| 125 | + var currentBaseVersion = $"{pageVersioning.Base.Major}.{pageVersioning.Base.Minor}+"; |
| 126 | + |
108 | 127 | //TODO should we even distinctby |
109 | 128 | var breadcrumbs = parents.Reverse().DistinctBy(p => p.Url).ToArray(); |
110 | 129 | var breadcrumbsList = CreateStructuredBreadcrumbsData(markdown, breadcrumbs); |
|
0 commit comments