diff --git a/src/Elastic.Documentation/Legacy/ILegacyUrlMapper.cs b/src/Elastic.Documentation/Legacy/ILegacyUrlMapper.cs index d92b3f96b..390d7d3eb 100644 --- a/src/Elastic.Documentation/Legacy/ILegacyUrlMapper.cs +++ b/src/Elastic.Documentation/Legacy/ILegacyUrlMapper.cs @@ -11,7 +11,7 @@ public record LegacyPageMapping(string RawUrl, string Version, bool Exists) public interface ILegacyUrlMapper { - IReadOnlyCollection MapLegacyUrl(IReadOnlyCollection? mappedPages); + IReadOnlyCollection? MapLegacyUrl(IReadOnlyCollection? mappedPages); } public record NoopLegacyUrlMapper : ILegacyUrlMapper diff --git a/src/Elastic.Markdown/Slices/HtmlWriter.cs b/src/Elastic.Markdown/Slices/HtmlWriter.cs index 9570bfe05..c3b02c3b5 100644 --- a/src/Elastic.Markdown/Slices/HtmlWriter.cs +++ b/src/Elastic.Markdown/Slices/HtmlWriter.cs @@ -110,9 +110,9 @@ private async Task RenderLayout(MarkdownFile markdown, MarkdownDocument Features = DocumentationSet.Configuration.Features, StaticFileContentHashProvider = StaticFileContentHashProvider, ReportIssueUrl = reportUrl, - CurrentVersion = legacyPages.Count > 0 ? legacyPages.ElementAt(0).Version : "9.0+", - LegacyPages = legacyPages.Skip(1).ToArray(), - VersionDropdownItems = VersionDrownDownItemViewModel.FromLegacyPageMappings(legacyPages.Skip(1).ToArray()), + CurrentVersion = legacyPages?.Count > 0 ? legacyPages.ElementAt(0).Version : "9.0+", + LegacyPages = legacyPages?.Skip(1).ToArray(), + VersionDropdownItems = VersionDrownDownItemViewModel.FromLegacyPageMappings(legacyPages?.Skip(1).ToArray()), Products = allProducts }); return await slice.RenderAsync(cancellationToken: ctx); diff --git a/src/Elastic.Markdown/Slices/IndexViewModel.cs b/src/Elastic.Markdown/Slices/IndexViewModel.cs index 56424123e..582285721 100644 --- a/src/Elastic.Markdown/Slices/IndexViewModel.cs +++ b/src/Elastic.Markdown/Slices/IndexViewModel.cs @@ -33,9 +33,9 @@ public class IndexViewModel public required INavigationItem[] Parents { get; init; } public required string NavigationHtml { get; init; } - public required string? CurrentVersion { get; init; } - public required LegacyPageMapping[] LegacyPages { get; init; } - public required VersionDrownDownItemViewModel[] VersionDropdownItems { get; init; } + public required string CurrentVersion { get; init; } + public required LegacyPageMapping[]? LegacyPages { get; init; } + public required VersionDrownDownItemViewModel[]? VersionDropdownItems { get; init; } public required string? UrlPathPrefix { get; init; } public required string? GithubEditUrl { get; init; } public required string? ReportIssueUrl { get; init; } @@ -63,8 +63,12 @@ public class VersionDrownDownItemViewModel public required VersionDrownDownItemViewModel[]? Children { get; init; } // This logic currently only handles one level of children. Although the model supports multiple levels, it is not currently used. - public static VersionDrownDownItemViewModel[] FromLegacyPageMappings(LegacyPageMapping[] legacyPageMappings) + public static VersionDrownDownItemViewModel[]? FromLegacyPageMappings(LegacyPageMapping[]? legacyPageMappings) { + if (legacyPageMappings is null) + { + return null; + } var groupedVersions = GroupByMajorVersion(legacyPageMappings); return groupedVersions.Select(m => { diff --git a/src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml b/src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml index 6b9545f99..649641a72 100644 --- a/src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml +++ b/src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml @@ -47,7 +47,7 @@ } - @foreach (var legacyPage in Model.LegacyPages) + @foreach (var legacyPage in Model.LegacyPages ?? []) {
  • @if (legacyPage.Exists) @@ -68,13 +68,20 @@
  • } - @if (Model.LegacyPages.Length == 0) + @if (Model.LegacyPages is null) // This means there is no mapping because the page is new in v3 {
  • There is no previous version of this page.
  • + } else if (Model.LegacyPages.Length == 0) // This means there is a legacy page mapping with 0 entries, which means the page was fully migrated and is also redirecting to the new system. + { +
  • +
    + This page was fully migrated to the current version. +
    +
  • } diff --git a/src/Elastic.Markdown/Slices/MarkdownLayoutViewModel.cs b/src/Elastic.Markdown/Slices/MarkdownLayoutViewModel.cs index eb4e62bea..6ca38949a 100644 --- a/src/Elastic.Markdown/Slices/MarkdownLayoutViewModel.cs +++ b/src/Elastic.Markdown/Slices/MarkdownLayoutViewModel.cs @@ -18,7 +18,7 @@ public class MarkdownLayoutViewModel : GlobalLayoutViewModel public required string? CurrentVersion { get; init; } - public required LegacyPageMapping[] LegacyPages { get; init; } + public required LegacyPageMapping[]? LegacyPages { get; init; } public required IReadOnlyCollection PageTocItems { get; init; }