Skip to content

Commit 23b38d7

Browse files
committed
Hide functionality behind the LAZY_LOAD_NAVIGATION feature flag
1 parent bc3a153 commit 23b38d7

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

src/Elastic.Documentation.Configuration/Builder/FeatureFlags.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public bool PrimaryNavEnabled
2020
set => _featureFlags["primary-nav"] = value;
2121
}
2222

23+
public bool LazyLoadNavigation
24+
{
25+
get => IsEnabled("LAZY_LOAD_NAVIGATION");
26+
set => _featureFlags["LAZY_LOAD_NAVIGATION"] = value;
27+
}
28+
2329
private bool IsEnabled(string key)
2430
{
2531
var envKey = $"FEATURE_{key.ToUpperInvariant().Replace('-', '_')}";

src/Elastic.Documentation.Site/Layout/_PagesNav.cshtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
@inherits RazorSlice<Elastic.Documentation.Site.GlobalLayoutViewModel>
22
<aside class="sidebar bg-white fixed md:sticky shadow-2xl md:shadow-none left-[100%] group-has-[#pages-nav-hamburger:checked]/body:left-0 bottom-0 md:left-auto pl-6 md:pl-2 top-[calc(var(--offset-top)+1px)] w-[80%] md:w-auto shrink-0 border-r-1 border-r-grey-20 z-40 md:z-auto">
3-
<div hx-get="@(Model.CurrentNavigationItem.Url + (Model.CurrentNavigationItem.Url.EndsWith('/') ? "index.nav.html" : "/index.nav.html"))" hx-trigger="load" hx-params="nav" hx-push-url="false" hx-swap="innerHTML" hx-target="#pages-nav"></div>
3+
4+
@if (Model.Features.LazyLoadNavigation)
5+
{
6+
<div hx-get="@(Model.CurrentNavigationItem.Url + (Model.CurrentNavigationItem.Url.EndsWith('/') ? "index.nav.html" : "/index.nav.html"))" hx-trigger="load" hx-params="nav" hx-push-url="false" hx-swap="innerHTML" hx-target="#pages-nav"></div>
7+
}
48
<nav
59
id="pages-nav"
610
class="sidebar-nav h-full">

src/Elastic.Markdown/DocumentationGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private async Task GenerateDocumentationState(Cancel ctx)
334334
await DocumentationSet.OutputDirectory.FileSystem.File.WriteAllBytesAsync(stateFile.FullName, bytes, ctx);
335335
}
336336

337-
public async Task<(string, string)> RenderLayout(MarkdownFile markdown, Cancel ctx)
337+
public async Task<RenderResult> RenderLayout(MarkdownFile markdown, Cancel ctx)
338338
{
339339
await DocumentationSet.Tree.Resolve(ctx);
340340
return await HtmlWriter.RenderLayout(markdown, ctx);

src/Elastic.Markdown/HtmlWriter.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ public string Render(string markdown, IFileInfo? source)
4444
return MarkdownFile.CreateHtml(parsed);
4545
}
4646

47-
public async Task<(string, string)> RenderLayout(MarkdownFile markdown, Cancel ctx = default)
47+
public async Task<RenderResult> RenderLayout(MarkdownFile markdown, Cancel ctx = default)
4848
{
4949
var document = await markdown.ParseFullAsync(ctx);
5050
return await RenderLayout(markdown, document, ctx);
5151
}
5252

53-
private async Task<(string, string)> RenderLayout(MarkdownFile markdown, MarkdownDocument document, Cancel ctx = default)
53+
private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDocument document, Cancel ctx = default)
5454
{
5555
var html = MarkdownFile.CreateHtml(document);
5656
await DocumentationSet.Tree.Resolve(ctx);
5757

5858
var fullNavigationHtml = await NavigationHtmlWriter.RenderNavigation(markdown.NavigationRoot, markdown.NavigationSource, -1, ctx);
59-
var miniNavigationHtml = await NavigationHtmlWriter.RenderNavigation(markdown.NavigationRoot, markdown.NavigationSource, 1, ctx);
59+
var miniNavigationHtml = DocumentationSet.Context.Configuration.Features.LazyLoadNavigation
60+
? await NavigationHtmlWriter.RenderNavigation(markdown.NavigationRoot, markdown.NavigationSource, 1, ctx)
61+
: "lazy navigation feature disabled";
6062

6163
var current = PositionalNavigation.GetCurrent(markdown);
6264
var previous = PositionalNavigation.GetPrevious(markdown);
@@ -116,7 +118,7 @@ public string Render(string markdown, IFileInfo? source)
116118
PreviousDocument = previous,
117119
NextDocument = next,
118120
Parents = parents,
119-
NavigationHtml = miniNavigationHtml,
121+
NavigationHtml = DocumentationSet.Configuration.Features.LazyLoadNavigation ? miniNavigationHtml : fullNavigationHtml,
120122
UrlPathPrefix = markdown.UrlPathPrefix,
121123
AppliesTo = markdown.YamlFrontMatter?.AppliesTo,
122124
GithubEditUrl = editUrl,
@@ -133,7 +135,12 @@ public string Render(string markdown, IFileInfo? source)
133135
Products = allProducts,
134136
VersionsConfig = DocumentationSet.Context.VersionsConfig
135137
});
136-
return (fullNavigationHtml, await slice.RenderAsync(cancellationToken: ctx));
138+
return new RenderResult
139+
{
140+
Html = await slice.RenderAsync(cancellationToken: ctx),
141+
FullNavigationPartialHtml = fullNavigationHtml
142+
};
143+
137144
}
138145

139146
public async Task<MarkdownDocument> WriteAsync(IFileInfo outputFile, MarkdownFile markdown, IConversionCollector? collector, Cancel ctx = default)
@@ -161,10 +168,20 @@ public async Task<MarkdownDocument> WriteAsync(IFileInfo outputFile, MarkdownFil
161168
var document = await markdown.ParseFullAsync(ctx);
162169

163170
var rendered = await RenderLayout(markdown, document, ctx);
164-
collector?.Collect(markdown, document, rendered.Item2);
165-
await writeFileSystem.File.WriteAllTextAsync(path, rendered.Item2, ctx);
166-
await writeFileSystem.File.WriteAllTextAsync(path.Replace(".html", ".nav.html"), rendered.Item1, ctx);
171+
collector?.Collect(markdown, document, rendered.Html);
172+
await writeFileSystem.File.WriteAllTextAsync(path, rendered.Html, ctx);
173+
174+
if (DocumentationSet.Configuration.Features.LazyLoadNavigation)
175+
{
176+
await writeFileSystem.File.WriteAllTextAsync(path.Replace(".html", ".nav.html"), rendered.FullNavigationPartialHtml, ctx);
177+
}
167178
return document;
168179
}
169180

170181
}
182+
183+
public record RenderResult
184+
{
185+
public required string Html { get; init; }
186+
public required string FullNavigationPartialHtml { get; init; }
187+
}

src/tooling/docs-assembler/assembler.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ environments:
2323
content_source: current
2424
google_tag_manager:
2525
enabled: false
26+
feature_flags:
27+
LAZY_LOAD_NAVIGATION: true
2628
dev:
2729
uri: http://localhost:4000
2830
content_source: next

src/tooling/docs-builder/Http/DocumentationWebHost.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static async Task<IResult> ServeDocumentationFile(ReloadableGeneratorSta
207207
{
208208
case MarkdownFile markdown:
209209
var rendered = await generator.RenderLayout(markdown, ctx);
210-
return Results.Content(isNavPartial ? rendered.Item1 : rendered.Item2, "text/html");
210+
return Results.Content(isNavPartial ? rendered.FullNavigationPartialHtml : rendered.Html, "text/html");
211211

212212
case ImageFile image:
213213
return Results.File(image.SourceFile.FullName, image.MimeType);
@@ -222,7 +222,7 @@ private static async Task<IResult> ServeDocumentationFile(ReloadableGeneratorSta
222222
return Results.NotFound();
223223

224224
var renderedNotFound = await generator.RenderLayout((notFoundDocumentationFile as MarkdownFile)!, ctx);
225-
return Results.Content(renderedNotFound.Item2, "text/html", null, (int)HttpStatusCode.NotFound);
225+
return Results.Content(renderedNotFound.Html, "text/html", null, (int)HttpStatusCode.NotFound);
226226
}
227227
}
228228
}

0 commit comments

Comments
 (0)