Skip to content

Remove Uri sources from navigation rendering. #1546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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.ApiExplorer/OpenApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private async Task<IFileInfo> Render<T>(INavigationItem current, T page, ApiRend
if (!outputFile.Directory!.Exists)
outputFile.Directory.Create();

var navigationRenderResult = await navigationRenderer.RenderNavigation(current.NavigationRoot, new Uri("http://ignored.example"), INavigationHtmlWriter.AllLevels, ctx);
var navigationRenderResult = await navigationRenderer.RenderNavigation(current.NavigationRoot, INavigationHtmlWriter.AllLevels, ctx);
renderContext = renderContext with
{
CurrentNavigation = current,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public interface INavigationHtmlWriter
{
const int AllLevels = -1;

Task<NavigationRenderResult> RenderNavigation(IRootNavigationItem<INavigationModel, INavigationItem> currentRootNavigation, Uri navigationSource,
int maxLevel, Cancel ctx = default);
Task<NavigationRenderResult> RenderNavigation(IRootNavigationItem<INavigationModel, INavigationItem> currentRootNavigation, int maxLevel, Cancel ctx = default);

async Task<string> Render(NavigationViewModel model, Cancel ctx)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public class IsolatedBuildNavigationHtmlWriter(BuildContext context, IRootNaviga
{
private readonly ConcurrentDictionary<(string, int), string> _renderedNavigationCache = [];

public async Task<NavigationRenderResult> RenderNavigation(IRootNavigationItem<INavigationModel, INavigationItem> currentRootNavigation,
Uri navigationSource, int maxLevel, Cancel ctx = default)
public async Task<NavigationRenderResult> RenderNavigation(
IRootNavigationItem<INavigationModel, INavigationItem> currentRootNavigation, int maxLevel, Cancel ctx = default
)
{
var navigation = context.Configuration.Features.PrimaryNavEnabled || currentRootNavigation.IsUsingNavigationDropdown
? currentRootNavigation
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Markdown/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
var html = MarkdownFile.CreateHtml(document);
await DocumentationSet.Tree.Resolve(ctx);

var fullNavigationRenderResult = await NavigationHtmlWriter.RenderNavigation(markdown.NavigationRoot, markdown.NavigationSource, INavigationHtmlWriter.AllLevels, ctx);
var miniNavigationRenderResult = await NavigationHtmlWriter.RenderNavigation(markdown.NavigationRoot, markdown.NavigationSource, 1, ctx);
var fullNavigationRenderResult = await NavigationHtmlWriter.RenderNavigation(markdown.NavigationRoot, INavigationHtmlWriter.AllLevels, ctx);
var miniNavigationRenderResult = await NavigationHtmlWriter.RenderNavigation(markdown.NavigationRoot, 1, ctx);

var navigationHtmlRenderResult = DocumentationSet.Context.Configuration.Features.LazyLoadNavigation
? miniNavigationRenderResult
Expand Down
3 changes: 0 additions & 3 deletions src/Elastic.Markdown/IO/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ DocumentationSet set
ScopeDirectory = build.Configuration.ScopeDirectory;

NavigationRoot = set.Tree;
NavigationSource = set.Source;
}

public bool PartOfNavigation { get; set; }
Expand All @@ -66,8 +65,6 @@ DocumentationSet set

public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot { get; set; }

public Uri NavigationSource { get; set; }

private IDiagnosticsCollector Collector { get; }

public string? UrlPathPrefix { get; }
Expand Down
3 changes: 1 addition & 2 deletions src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Elastic.Markdown.IO.Navigation;

[DebuggerDisplay("Group >{Depth} {FolderName} ({NavigationItems.Count} items)")]
[DebuggerDisplay("Toc: {Depth} {NavigationSource} > ({NavigationItems.Count} items)")]
public class DocumentationGroup : INodeNavigationItem<MarkdownFile, INavigationItem>
{
private readonly TableOfContentsTreeCollector _treeCollector;
Expand Down Expand Up @@ -138,7 +138,6 @@ void AddToNavigationItems(INavigationItem item, ref int fileIndex)
// TODO these have to be refactor to be pure navigational properties
md.ScopeDirectory = file.TableOfContentsScope.ScopeDirectory;
md.NavigationRoot = rootNavigationItem;
md.NavigationSource = NavigationSource;

foreach (var extension in lookups.EnabledExtensions)
extension.Visit(d, tocItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Elastic.Markdown.IO.Navigation;

[DebuggerDisplay("Toc >{Depth} {FolderName} ({NavigationItems.Count} items)")]
[DebuggerDisplay("Toc: {Depth} {NavigationSource} > ({NavigationItems.Count} items)")]
public class TableOfContentsTree : DocumentationGroup, IRootNavigationItem<MarkdownFile, INavigationItem>
{
public Uri Source { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ public class TableOfContentsTreeCollector
{
private Dictionary<Uri, TableOfContentsTree> NestedTableOfContentsTrees { get; } = [];

public void Collect(Uri source, TableOfContentsTree tree) =>
NestedTableOfContentsTrees[source] = tree;

public void Collect(TocReference tocReference, TableOfContentsTree tree) =>
NestedTableOfContentsTrees[tocReference.Source] = tree;
public void Collect(Uri source, TableOfContentsTree tree) => NestedTableOfContentsTrees[source] = tree;

public bool TryGetTableOfContentsTree(Uri source, [NotNullWhen(true)] out TableOfContentsTree? tree) =>
NestedTableOfContentsTrees.TryGetValue(source, out tree);
Expand Down
27 changes: 14 additions & 13 deletions src/tooling/docs-assembler/AssembleSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
using YamlDotNet.RepresentationModel;

namespace Documentation.Assembler;
public record TocTopLevelMapping

public record NavigationTocMapping
{
public required Uri Source { get; init; }
public required string SourcePathPrefix { get; init; }
Expand All @@ -30,7 +31,7 @@ public record TocTopLevelMapping

public record TocConfigurationMapping
{
public required TocTopLevelMapping TopLevel { get; init; }
public required NavigationTocMapping TopLevel { get; init; }
public required ConfigurationFile RepositoryConfigurationFile { get; init; }
public required TableOfContentsConfiguration TableOfContentsConfiguration { get; init; }
}
Expand All @@ -40,7 +41,7 @@ public class AssembleSources
public AssembleContext AssembleContext { get; }
public FrozenDictionary<string, AssemblerDocumentationSet> AssembleSets { get; }

public FrozenDictionary<Uri, TocTopLevelMapping> TocTopLevelMappings { get; }
public FrozenDictionary<Uri, NavigationTocMapping> NavigationTocMappings { get; }

public FrozenDictionary<string, IReadOnlyCollection<string>> HistoryMappings { get; }

Expand All @@ -61,19 +62,19 @@ public static async Task<AssembleSources> AssembleAsync(ILoggerFactory logger, A
private AssembleSources(ILoggerFactory logger, AssembleContext assembleContext, Checkout[] checkouts, VersionsConfiguration versionsConfiguration)
{
AssembleContext = assembleContext;
TocTopLevelMappings = GetConfiguredSources(assembleContext);
NavigationTocMappings = GetTocMappings(assembleContext);
HistoryMappings = GetHistoryMapping(assembleContext);
var linkIndexProvider = Aws3LinkIndexReader.CreateAnonymous();
var crossLinkFetcher = new AssemblerCrossLinkFetcher(logger, assembleContext.Configuration, assembleContext.Environment, linkIndexProvider);
UriResolver = new PublishEnvironmentUriResolver(TocTopLevelMappings, assembleContext.Environment);
UriResolver = new PublishEnvironmentUriResolver(NavigationTocMappings, assembleContext.Environment);
var crossLinkResolver = new CrossLinkResolver(crossLinkFetcher, UriResolver);
AssembleSets = checkouts
.Where(c => c.Repository is { Skip: false })
.Select(c => new AssemblerDocumentationSet(logger, assembleContext, c, crossLinkResolver, TreeCollector, versionsConfiguration))
.ToDictionary(s => s.Checkout.Repository.Name, s => s)
.ToFrozenDictionary();

TocConfigurationMapping = TocTopLevelMappings
TocConfigurationMapping = NavigationTocMappings
.Select(kv =>
{
var repo = kv.Value.Source.Scheme;
Expand Down Expand Up @@ -148,11 +149,11 @@ static void ReadHistoryMappings(IDictionary<string, IReadOnlyCollection<string>>
}


public static FrozenDictionary<Uri, TocTopLevelMapping> GetConfiguredSources(AssembleContext context)
public static FrozenDictionary<Uri, NavigationTocMapping> GetTocMappings(AssembleContext context)
{
var dictionary = new Dictionary<Uri, TocTopLevelMapping>();
var dictionary = new Dictionary<Uri, NavigationTocMapping>();
var reader = new YamlStreamReader(context.NavigationPath, context.Collector);
var entries = new List<KeyValuePair<Uri, TocTopLevelMapping>>();
var entries = new List<KeyValuePair<Uri, NavigationTocMapping>>();
foreach (var entry in reader.Read())
{
switch (entry.Key)
Expand All @@ -167,7 +168,7 @@ public static FrozenDictionary<Uri, TocTopLevelMapping> GetConfiguredSources(Ass
return dictionary.ToFrozenDictionary();

static void ReadTocBlocks(
List<KeyValuePair<Uri, TocTopLevelMapping>> entries,
List<KeyValuePair<Uri, NavigationTocMapping>> entries,
YamlStreamReader reader,
KeyValuePair<YamlNode, YamlNode> entry,
string? parent,
Expand Down Expand Up @@ -196,7 +197,7 @@ static void ReadTocBlocks(
}
}
static void ReadBlock(
List<KeyValuePair<Uri, TocTopLevelMapping>> entries,
List<KeyValuePair<Uri, NavigationTocMapping>> entries,
YamlStreamReader reader,
YamlMappingNode tocEntry,
string? parent,
Expand Down Expand Up @@ -259,14 +260,14 @@ static void ReadBlock(
topLevelSource ??= sourceUri;
parentSource ??= sourceUri;

var tocTopLevelMapping = new TocTopLevelMapping
var tocTopLevelMapping = new NavigationTocMapping
{
Source = sourceUri,
SourcePathPrefix = pathPrefix,
TopLevelSource = topLevelSource,
ParentSource = parentSource
};
entries.Add(new KeyValuePair<Uri, TocTopLevelMapping>(sourceUri, tocTopLevelMapping));
entries.Add(new KeyValuePair<Uri, NavigationTocMapping>(sourceUri, tocTopLevelMapping));

foreach (var entry in tocEntry.Children)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace Documentation.Assembler.Building;

public class PublishEnvironmentUriResolver : IUriEnvironmentResolver
{
private readonly FrozenDictionary<Uri, TocTopLevelMapping> _topLevelMappings;
private readonly FrozenDictionary<Uri, NavigationTocMapping> _topLevelMappings;
private Uri BaseUri { get; }

private PublishEnvironment PublishEnvironment { get; }

private IReadOnlyList<string> TableOfContentsPrefixes { get; }

public PublishEnvironmentUriResolver(FrozenDictionary<Uri, TocTopLevelMapping> topLevelMappings, PublishEnvironment environment)
public PublishEnvironmentUriResolver(FrozenDictionary<Uri, NavigationTocMapping> topLevelMappings, PublishEnvironment environment)
{
_topLevelMappings = topLevelMappings;
PublishEnvironment = environment;
Expand Down
2 changes: 1 addition & 1 deletion src/tooling/docs-assembler/Cli/RepositoryCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task<int> BuildAll(
var navigation = new GlobalNavigation(assembleSources, navigationFile);

var pathProvider = new GlobalNavigationPathProvider(navigationFile, assembleSources, assembleContext);
var htmlWriter = new GlobalNavigationHtmlWriter(navigationFile, assembleContext, navigation, assembleSources);
var htmlWriter = new GlobalNavigationHtmlWriter(logger, navigation);
var legacyPageChecker = new LegacyPageChecker();
var historyMapper = new PageLegacyUrlMapper(legacyPageChecker, assembleSources.HistoryMappings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public NavigationPrefixChecker(ILoggerFactory logger, AssembleContext context)
_logger = logger.CreateLogger<NavigationPrefixChecker>();
_loggerFactory = logger;

var tocTopLevelMappings = AssembleSources.GetConfiguredSources(context);
var tocTopLevelMappings = AssembleSources.GetTocMappings(context);
_uriResolver = new PublishEnvironmentUriResolver(tocTopLevelMappings, context.Environment);
}

Expand Down
Loading
Loading