Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/Elastic.Markdown/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Elastic.Documentation;
using Elastic.Documentation.Configuration.LegacyUrlMappings;
using Elastic.Documentation.Configuration.Products;
using Elastic.Documentation.Configuration.TableOfContents;
using Elastic.Documentation.Configuration.Versions;
using Elastic.Documentation.Site.FileProviders;
using Elastic.Documentation.Site.Navigation;
Expand Down Expand Up @@ -102,9 +103,27 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
fullNavigationRenderResult
);

var currentBaseVersion = legacyPages is { Count: > 0 }
? $"{legacyPages.ElementAt(0).Product.VersioningSystem?.Base.Major}.{legacyPages.ElementAt(0).Product.VersioningSystem?.Base.Minor}+"
: $"{DocumentationSet.Context.VersionsConfiguration.VersioningSystems[VersioningSystemId.Stack].Base.Major}.{DocumentationSet.Context.VersionsConfiguration.VersioningSystems[VersioningSystemId.Stack].Base.Minor}+";
// Acquiring the versioning system for the current page:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to an isolated place like LegacyPageService or something new

// 1. If the page has a legacy page mapping, use the versioning system of the legacy page
// 2. If the page's docset has a name with a direct product maatch, use the versioning system of the product
// 3. If the page's docset has a table of contents entry with a direct product match, use the versioning system of the product
// 4. Fallback to the stack versioning system
VersioningSystem pageVersioning = null!;
if (legacyPages is not null && legacyPages.Count > 0)
pageVersioning = legacyPages.ElementAt(0).Product.VersioningSystem!;
else if (DocumentationSet.Context.ProductsConfiguration.Products.TryGetValue(DocumentationSet.Name, out var belonging))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use Git.RepositoryName explicitly over DocumentationSet.Name

pageVersioning = belonging.VersioningSystem!;
else if (DocumentationSet.Configuration.TableOfContents.FirstOrDefault(t => t is TocReference tRef && !tRef.Source.LocalPath.Equals("/")) is TocReference tocRef)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever I wonder if its too clever though? What are the cases where this is needed?

{
var productFound = DocumentationSet.Context.ProductsConfiguration.Products.TryGetValue(tocRef.Source.LocalPath.Trim('/'), out var tocProduct);
if (productFound && tocProduct is not null)
pageVersioning = tocProduct.VersioningSystem!;
}
else
pageVersioning = DocumentationSet.Context.VersionsConfiguration.VersioningSystems[VersioningSystemId.Stack];

var currentBaseVersion = $"{pageVersioning.Base.Major}.{pageVersioning.Base.Minor}+";

//TODO should we even distinctby
var breadcrumbs = parents.Reverse().DistinctBy(p => p.Url).ToArray();
var breadcrumbsList = CreateStructuredBreadcrumbsData(markdown, breadcrumbs);
Expand Down
Loading