Skip to content

Commit 74a2805

Browse files
committed
Improve versioning system inference
1 parent 6dba0cf commit 74a2805

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/Elastic.Markdown/HtmlWriter.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Elastic.Documentation;
88
using Elastic.Documentation.Configuration.LegacyUrlMappings;
99
using Elastic.Documentation.Configuration.Products;
10+
using Elastic.Documentation.Configuration.TableOfContents;
1011
using Elastic.Documentation.Configuration.Versions;
1112
using Elastic.Documentation.Site.FileProviders;
1213
using Elastic.Documentation.Site.Navigation;
@@ -102,9 +103,27 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
102103
fullNavigationRenderResult
103104
);
104105

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+
108127
//TODO should we even distinctby
109128
var breadcrumbs = parents.Reverse().DistinctBy(p => p.Url).ToArray();
110129
var breadcrumbsList = CreateStructuredBreadcrumbsData(markdown, breadcrumbs);

0 commit comments

Comments
 (0)