diff --git a/src/Elastic.Markdown/DocumentationGenerator.cs b/src/Elastic.Markdown/DocumentationGenerator.cs index 10abd9c62..020fefd65 100644 --- a/src/Elastic.Markdown/DocumentationGenerator.cs +++ b/src/Elastic.Markdown/DocumentationGenerator.cs @@ -7,6 +7,7 @@ using System.Text.Json; using Elastic.Markdown.Exporters; using Elastic.Markdown.IO; +using Elastic.Markdown.IO.HistoryMapping; using Elastic.Markdown.IO.State; using Elastic.Markdown.Links.CrossLinks; using Elastic.Markdown.Slices; @@ -44,7 +45,8 @@ public DocumentationGenerator( INavigationHtmlWriter? navigationHtmlWriter = null, IDocumentationFileOutputProvider? documentationFileOutputProvider = null, IDocumentationFileExporter? documentationExporter = null, - IConversionCollector? conversionCollector = null + IConversionCollector? conversionCollector = null, + IHistoryMapper? historyMapper = null ) { _documentationFileOutputProvider = documentationFileOutputProvider; @@ -55,7 +57,7 @@ public DocumentationGenerator( DocumentationSet = docSet; Context = docSet.Build; Resolver = docSet.LinkResolver; - HtmlWriter = new HtmlWriter(DocumentationSet, _writeFileSystem, new DescriptionGenerator(), navigationHtmlWriter); + HtmlWriter = new HtmlWriter(DocumentationSet, _writeFileSystem, new DescriptionGenerator(), navigationHtmlWriter, historyMapper); _documentationFileExporter = documentationExporter ?? docSet.Build.Configuration.EnabledExtensions.FirstOrDefault(e => e.FileExporter != null)?.FileExporter diff --git a/src/Elastic.Markdown/IO/HistoryMapping/HistoryMapper.cs b/src/Elastic.Markdown/IO/HistoryMapping/HistoryMapper.cs new file mode 100644 index 000000000..58169fa81 --- /dev/null +++ b/src/Elastic.Markdown/IO/HistoryMapping/HistoryMapper.cs @@ -0,0 +1,15 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +namespace Elastic.Markdown.IO.HistoryMapping; + +public interface IHistoryMapper +{ + string? MapLegacyUrl(string? currentUrl); +} + +public record BypassHistoryMapper : IHistoryMapper +{ + public string? MapLegacyUrl(string? currentUrl) => null; +} diff --git a/src/Elastic.Markdown/Myst/FrontMatter/FrontMatterParser.cs b/src/Elastic.Markdown/Myst/FrontMatter/FrontMatterParser.cs index 65457a013..2f91d5c77 100644 --- a/src/Elastic.Markdown/Myst/FrontMatter/FrontMatterParser.cs +++ b/src/Elastic.Markdown/Myst/FrontMatter/FrontMatterParser.cs @@ -34,4 +34,7 @@ public class YamlFrontMatter [YamlMember(Alias = "applies_to")] public ApplicableTo? AppliesTo { get; set; } + + [YamlMember(Alias = "mapped_pages")] + public IReadOnlyCollection? MappedPages { get; set; } } diff --git a/src/Elastic.Markdown/Slices/HtmlWriter.cs b/src/Elastic.Markdown/Slices/HtmlWriter.cs index 508a2f2f1..c66232ade 100644 --- a/src/Elastic.Markdown/Slices/HtmlWriter.cs +++ b/src/Elastic.Markdown/Slices/HtmlWriter.cs @@ -6,6 +6,7 @@ using System.IO.Abstractions; using Elastic.Markdown.IO; using Elastic.Markdown.IO.Discovery; +using Elastic.Markdown.IO.HistoryMapping; using Elastic.Markdown.IO.Navigation; using Markdig.Syntax; using RazorSlices; @@ -66,13 +67,13 @@ public class HtmlWriter( DocumentationSet documentationSet, IFileSystem writeFileSystem, IDescriptionGenerator descriptionGenerator, - INavigationHtmlWriter? navigationHtmlWriter = null) + INavigationHtmlWriter? navigationHtmlWriter = null, + IHistoryMapper? historyMapper = null) { private DocumentationSet DocumentationSet { get; } = documentationSet; public INavigationHtmlWriter NavigationHtmlWriter { get; } = navigationHtmlWriter ?? new IsolatedBuildNavigationHtmlWriter(documentationSet); private StaticFileContentHashProvider StaticFileContentHashProvider { get; } = new(new EmbeddedOrPhysicalFileProvider(documentationSet.Build)); - - + private IHistoryMapper HistoryMapper { get; } = historyMapper ?? new BypassHistoryMapper(); public async Task RenderLayout(MarkdownFile markdown, Cancel ctx = default) { var document = await markdown.ParseFullAsync(ctx); @@ -106,6 +107,8 @@ private async Task RenderLayout(MarkdownFile markdown, MarkdownDocument var siteName = DocumentationSet.Tree.Index?.Title ?? "Elastic Documentation"; + var legacyUrl = HistoryMapper.MapLegacyUrl(markdown.YamlFrontMatter?.MappedPages?.FirstOrDefault()); + var slice = Index.Create(new IndexViewModel { SiteName = siteName, @@ -128,7 +131,8 @@ private async Task RenderLayout(MarkdownFile markdown, MarkdownDocument GoogleTagManager = DocumentationSet.Build.GoogleTagManager, Features = DocumentationSet.Configuration.Features, StaticFileContentHashProvider = StaticFileContentHashProvider, - ReportIssueUrl = reportUrl + ReportIssueUrl = reportUrl, + LegacyUrl = legacyUrl }); return await slice.RenderAsync(cancellationToken: ctx); } diff --git a/src/Elastic.Markdown/Slices/Index.cshtml b/src/Elastic.Markdown/Slices/Index.cshtml index aca7569ff..786a0cfef 100644 --- a/src/Elastic.Markdown/Slices/Index.cshtml +++ b/src/Elastic.Markdown/Slices/Index.cshtml @@ -19,7 +19,8 @@ GoogleTagManager = Model.GoogleTagManager, Features = Model.Features, StaticFileContentHashProvider = Model.StaticFileContentHashProvider, - ReportIssueUrl = Model.ReportIssueUrl + ReportIssueUrl = Model.ReportIssueUrl, + LegacyUrl = Model.LegacyUrl }; }
diff --git a/src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml b/src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml index c7e37853d..f58e284de 100644 --- a/src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml +++ b/src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml @@ -2,25 +2,16 @@