Skip to content

Commit f98131a

Browse files
bmorelli25cotti
andauthored
Update historymapping.yml to exclude Serverless mappings (#948)
* Update historymapping.yml * - Add support for acquiring the best first match for multiple mapped page definition on front matter - Fix path replacement issue * Allow the default mapped page url if no better matches were found --------- Co-authored-by: Felipe Cotti <[email protected]>
1 parent fe7ef7b commit f98131a

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/Elastic.Markdown/IO/HistoryMapping/HistoryMapper.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace Elastic.Markdown.IO.HistoryMapping;
66

77
public interface IHistoryMapper
88
{
9-
string? MapLegacyUrl(string? currentUrl);
9+
string? MapLegacyUrl(IReadOnlyCollection<string>? mappedPages);
1010
}
1111

1212
public record BypassHistoryMapper : IHistoryMapper
1313
{
14-
public string? MapLegacyUrl(string? currentUrl) => null;
14+
public string? MapLegacyUrl(IReadOnlyCollection<string>? mappedPages) => null;
1515
}

src/Elastic.Markdown/Slices/HtmlWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
107107

108108
var siteName = DocumentationSet.Tree.Index?.Title ?? "Elastic Documentation";
109109

110-
var legacyUrl = HistoryMapper.MapLegacyUrl(markdown.YamlFrontMatter?.MappedPages?.FirstOrDefault());
110+
var legacyUrl = HistoryMapper.MapLegacyUrl(markdown.YamlFrontMatter?.MappedPages);
111111

112112
var slice = Index.Create(new IndexViewModel
113113
{

src/docs-assembler/Mapping/PageHistoryMapper.cs

+13-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ public record PageHistoryMapper : IHistoryMapper
1212

1313
public PageHistoryMapper(IReadOnlyDictionary<string, string> previousUrls) => PreviousUrls = previousUrls;
1414

15-
public string? MapLegacyUrl(string? currentUrl)
15+
public string? MapLegacyUrl(IReadOnlyCollection<string>? mappedPages)
1616
{
17-
if (currentUrl is null)
17+
if (mappedPages is null)
1818
return null;
1919

20-
var versionMarker = PreviousUrls.FirstOrDefault(x => currentUrl.Contains(x.Key));
21-
if (versionMarker.Key == string.Empty)
22-
return null;
20+
foreach (var mappedPage in mappedPages)
21+
{
22+
var versionMarker = PreviousUrls.FirstOrDefault(x => mappedPage.Contains(x.Key));
23+
if (versionMarker.Key != string.Empty && versionMarker.Value != "undefined")
24+
{
25+
return mappedPage.Contains("current")
26+
? mappedPage.Replace($"{versionMarker.Key}current/", $"{versionMarker.Key}{versionMarker.Value}/")
27+
: null;
28+
}
29+
}
2330

24-
return !currentUrl.Contains("current") ? null : currentUrl.Replace($"{versionMarker.Key}/current/", $"{versionMarker.Key}/{versionMarker.Value}/");
31+
return mappedPages.FirstOrDefault();
2532
}
2633
}

src/docs-assembler/historymapping.yml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ mappings:
6161
en/logstash-versioned-plugins: undefined
6262
en/search-ui: undefined
6363
en/security: stack
64+
en/serverless: undefined
6465
en/starting-with-the-elasticsearch-platform-and-its-solutions: stack
6566
en/observability: stack
6667
en/elasticsearch/painless: stack

0 commit comments

Comments
 (0)