Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Elastic.Documentation/Legacy/ILegacyUrlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record LegacyPageMapping(string RawUrl, string Version, bool Exists)

public interface ILegacyUrlMapper
{
IReadOnlyCollection<LegacyPageMapping> MapLegacyUrl(IReadOnlyCollection<string>? mappedPages);
IReadOnlyCollection<LegacyPageMapping>? MapLegacyUrl(IReadOnlyCollection<string>? mappedPages);
}

public record NoopLegacyUrlMapper : ILegacyUrlMapper
Expand Down
6 changes: 3 additions & 3 deletions src/Elastic.Markdown/Slices/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private async Task<string> 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);
Expand Down
12 changes: 8 additions & 4 deletions src/Elastic.Markdown/Slices/IndexViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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 =>
{
Expand Down
11 changes: 9 additions & 2 deletions src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}
</a>
</li>
@foreach (var legacyPage in Model.LegacyPages)
@foreach (var legacyPage in Model.LegacyPages ?? [])
{
<li class="block">
@if (legacyPage.Exists)
Expand All @@ -68,13 +68,20 @@

</li>
}
@if (Model.LegacyPages.Length == 0)
@if (Model.LegacyPages is null) // This means there is no mapping because the page is new in v3
{
<li class="block border-t-1 border-grey-20">
<div class="py-1 px-4 text-sm">
There is no previous version of this page.
</div>
</li>
} 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.
{
<li class="block border-t-1 border-grey-20">
<div class="py-1 px-4 text-sm">
This page was fully migrated to the current version.
</div>
</li>
}
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/Slices/MarkdownLayoutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PageTocItem> PageTocItems { get; init; }

Expand Down
Loading