Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public record PublishEnvironment

[YamlMember(Alias = "google_tag_manager")]
public GoogleTagManager GoogleTagManager { get; set; } = new();

[YamlMember(Alias = "feature_flags")]
public Dictionary<string, bool> FeatureFlags { get; set; } = [];
}
27 changes: 23 additions & 4 deletions src/Elastic.Documentation.Configuration/Builder/FeatureFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@

namespace Elastic.Documentation.Configuration.Builder;

public class FeatureFlags(Dictionary<string, bool> featureFlags)
public class FeatureFlags(Dictionary<string, bool> initFeatureFlags)
{
public bool IsPrimaryNavEnabled => IsEnabled("primary-nav");
public bool IsVersionDropdownEnabled => IsEnabled("version-dropdown");
private readonly Dictionary<string, bool> _featureFlags = new(initFeatureFlags);

public void Set(string key, bool value)
{
var normalizedKey = key.ToLowerInvariant().Replace('_', '-');
_featureFlags[normalizedKey] = value;
}

public bool PrimaryNavEnabled
{
get => IsEnabled("primary-nav");
set => _featureFlags["primary-nav"] = value;
}

public bool VersionDropdownEnabled
{
get => IsEnabled("version-dropdown");
set => _featureFlags["version-dropdown"] = value;
}

private bool IsEnabled(string key)
{
var envKey = $"FEATURE_{key.ToUpperInvariant().Replace('-', '_')}";
Expand All @@ -18,6 +36,7 @@ private bool IsEnabled(string key)
// if the env var is set but not a bool, we treat it as enabled
return true;
}
return featureFlags.TryGetValue(key, out var value) && value;

return _featureFlags.TryGetValue(key, out var value) && value;
}
}
52 changes: 26 additions & 26 deletions src/Elastic.Documentation.Site/Layout/_Footer.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@

<footer class="py-12 px-6 w-full mx-auto bg-ink-dark">
<div class="max-w-(--max-layout-width) w-full mx-auto">
<div class="text-grey-20 text-[12px]">
<a href="https://www.elastic.co/">
<img class="block" alt="Elastic logo" src="@Model.Static("logo-elastic-horizontal-white.svg")" width="120"/>
</a>
</div>
<div class="text-grey-20 text-[12px] bg-ink-dark grid grid-cols-1 md:grid-cols-2 gap-2 items-center">
<div>
<ul class="mt-4 flex gap-3">
<li>
<a class="underline hover:text-white" href="https://www.elastic.co/legal/trademarks">Trademarks</a>
</li>
<li>
<a class="underline hover:text-white" href="https://www.elastic.co/legal/terms-of-use">Terms of Use</a>
</li>
<li>
<a class="underline hover:text-white" href="https://www.elastic.co/legal/privacy-statement">Privacy</a>
</li>
<li>
<a class="underline hover:text-white" href="https://www.elastic.co/sitemap">Sitemap</a>
</li>
</ul>
<div class="text-grey-20 text-[12px]">
<a href="https://www.elastic.co/">
<img class="block" alt="Elastic logo" src="@Model.Static("logo-elastic-horizontal-white.svg")" width="120"/>
</a>
</div>
<div class="text-grey-20 text-[12px] bg-ink-dark grid grid-cols-1 md:grid-cols-2 gap-2 items-center">
<div>
<ul class="mt-4 flex gap-3">
<li>
<a class="underline hover:text-white" href="https://www.elastic.co/legal/trademarks">Trademarks</a>
</li>
<li>
<a class="underline hover:text-white" href="https://www.elastic.co/legal/terms-of-use">Terms of Use</a>
</li>
<li>
<a class="underline hover:text-white" href="https://www.elastic.co/legal/privacy-statement">Privacy</a>
</li>
<li>
<a class="underline hover:text-white" href="https://www.elastic.co/sitemap">Sitemap</a>
</li>
</ul>
<p class="mt-4">
© @(DateTime.Today.Year) Elasticsearch B.V. All Rights Reserved.
</p>
</div>
<p class="mt-4">
© @(DateTime.Today.Year) Elasticsearch B.V. All Rights Reserved.
Elasticsearch is a trademark of Elasticsearch B.V., registered in the U.S. and in other countries. Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change related?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, what?

Thank you for noticing.

Going to check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</p>
</div>
<p class="mt-4">
Elasticsearch is a trademark of Elasticsearch B.V., registered in the U.S. and in other countries. Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.
</p>
</div>
</div>
</footer>

Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Documentation.Site/Layout/_Header.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@inherits RazorSlice<Elastic.Documentation.Site.GlobalLayoutViewModel>
@if (Model.Features.IsPrimaryNavEnabled)
@if (Model.Features.PrimaryNavEnabled)
{
<div id="elastic-nav"></div>
<script src="https://www.elastic.co/elastic-nav.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class IsolatedBuildNavigationHtmlWriter(BuildContext context, INodeNaviga

public async Task<string> RenderNavigation(INodeNavigationItem<INavigationModel, INavigationItem> currentRootNavigation, Uri navigationSource, Cancel ctx = default)
{
var navigation = context.Configuration.Features.IsPrimaryNavEnabled
var navigation = context.Configuration.Features.PrimaryNavEnabled
? currentRootNavigation
: siteRoot;

Expand All @@ -33,7 +33,7 @@ private NavigationViewModel CreateNavigationModel(INodeNavigationItem<INavigatio
Title = navigation.NavigationTitle,
TitleUrl = navigation.Url,
Tree = navigation,
IsPrimaryNavEnabled = context.Configuration.Features.IsPrimaryNavEnabled,
IsPrimaryNavEnabled = context.Configuration.Features.PrimaryNavEnabled,
IsGlobalAssemblyBuild = false,
TopLevelItems = siteRoot.NavigationItems.OfType<INodeNavigationItem<INavigationModel, INavigationItem>>().ToList()
};
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/Slices/Layout/_Breadcrumbs.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@inherits RazorSlice<MarkdownLayoutViewModel>
@{
var targets =
Model.Features.IsPrimaryNavEnabled
Model.Features.PrimaryNavEnabled
? Model.Parents.Reverse()
: Model.Parents.Reverse().Skip(1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@inherits RazorSlice<MarkdownLayoutViewModel>
<aside class="sidebar hidden lg:block max-w-65 md:hidden">
<nav id="toc-nav" class="sidebar-nav h-full">
@if (Model.Features.IsVersionDropdownEnabled)
@if (Model.Features.VersionDropdownEnabled)
{
<div class="mt-6">
<version-dropdown all-versions-url="@Model.AllVersionsUrl" current-version='@(Model.CurrentVersion)' items='@(new HtmlString(Model.VersionDropdownSerializedModel))' />
Expand Down
13 changes: 13 additions & 0 deletions src/tooling/docs-assembler/Building/AssemblerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class AssemblerBuilder(
ILegacyUrlMapper? legacyUrlMapper
)
{
private readonly ILogger<AssemblerBuilder> _logger = logger.CreateLogger<AssemblerBuilder>();

private GlobalNavigationHtmlWriter HtmlWriter { get; } = writer;

private ILegacyUrlMapper? LegacyUrlMapper { get; } = legacyUrlMapper;
Expand Down Expand Up @@ -118,6 +120,7 @@ string Resolve(string relativeMarkdownPath)

private async Task<GenerationResult> BuildAsync(AssemblerDocumentationSet set, bool noop, IMarkdownExporter[]? markdownExporters, Cancel ctx)
{
SetFeatureFlags(set);
var generator = new DocumentationGenerator(
set.DocumentationSet,
logger, HtmlWriter,
Expand All @@ -130,4 +133,14 @@ private async Task<GenerationResult> BuildAsync(AssemblerDocumentationSet set, b
return await generator.GenerateAll(ctx);
}

private void SetFeatureFlags(AssemblerDocumentationSet set)
{
// Enable primary nav by default
set.DocumentationSet.Configuration.Features.PrimaryNavEnabled = true;
foreach (var configurationFeatureFlag in set.AssembleContext.Environment.FeatureFlags)
{
_logger.LogInformation("Setting feature flag: {ConfigurationFeatureFlagKey}={ConfigurationFeatureFlagValue}", configurationFeatureFlag.Key, configurationFeatureFlag.Value);
set.DocumentationSet.Configuration.Features.Set(configurationFeatureFlag.Key, configurationFeatureFlag.Value);
}
}
}
2 changes: 2 additions & 0 deletions src/tooling/docs-assembler/assembler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ environments:
content_source: next
google_tag_manager:
enabled: false
feature_flags:
VERSION_DROPDOWN: true
dev:
uri: http://localhost:4000
content_source: next
Expand Down
Loading