Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
70ac046
Mount floating sections in the table of contents
Mpdreamz Nov 5, 2026
d927819
Keep floating sections in site assembly and reject extra keys on api …
Mpdreamz Nov 5, 2026
76b05ef
Fill floating sections after the navigation tree is built
Mpdreamz Nov 5, 2026
33f7e71
Keep floating sections mounted by the narrative repository root
Mpdreamz Nov 5, 2026
c439ce8
Resolve floating sections in the build path
Mpdreamz Nov 5, 2026
1a8af60
Mount API pages in the navigation of isolated builds
Mpdreamz Nov 5, 2026
f4251e1
Hide an API section when the build skips the API Explorer
Mpdreamz Nov 5, 2026
3b5425f
Keep a failed or skipped API out of navigation and invalidate on --sk…
Mpdreamz Nov 5, 2026
3845e5c
Report a failed API once and test the --skip-api cache invalidation
Mpdreamz Nov 5, 2026
16af516
Publish API pages in links.json and resolve cross-links to them
Mpdreamz Nov 5, 2026
c363da2
Keep API link aliases per version and the anchor of floating links
Mpdreamz Nov 5, 2026
4f4f8af
Test that API link aliases keep their target per version
Mpdreamz Nov 5, 2026
1f80469
Say that API cross-links keep their fragment unchecked
Mpdreamz Nov 5, 2026
5955bbd
State each version's root in links.json instead of deriving it
Mpdreamz Nov 5, 2026
201628a
Let a page win over a version of the same name in floating links
Mpdreamz Nov 5, 2026
06d12cb
Start every copy of a floating link section with fresh lookups
Mpdreamz Nov 5, 2026
c3a5fed
Put the APIs in the assembler navigation tree
Mpdreamz Nov 5, 2026
2e2118c
Keep the API hub out of the sitemap, on its own tab and out of non-HT…
Mpdreamz Nov 5, 2026
265c244
Test that a build without the HTML export lists no API links
Mpdreamz Nov 5, 2026
358423d
Keep the APIs out of the previous and next links of the docs
Mpdreamz Nov 5, 2026
7d99725
Merge main into feature/floating-assembler
Mpdreamz Nov 5, 2026
545fff5
List floating among the valid navigation keys in the unknown key test
Mpdreamz Nov 5, 2026
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
8 changes: 8 additions & 0 deletions config/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,11 @@ toc:
# CONTRIBUTE 2 DOCS #
#############
- toc: contribute-docs

########
# APIs #
########
# Every API that a content repository declares, when the build renders the API Explorer (the
# assembler-api-explorer feature flag). Without those APIs this entry adds nothing.
- section: APIs
floating: api
3 changes: 3 additions & 0 deletions config/navigation_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ toc:
# APIs #
########
# A path that starts with / is a link within the site, so the site prefix is added and the tab is active on pages under it.
# `floating: api` also puts the APIs in the navigation tree, for the sitemap and llms.txt, when the build renders them.
# Without that the section stays this external link.
- section: APIs
external: /api/
floating: api

###########
# PRODUCTS #
Expand Down
2 changes: 1 addition & 1 deletion docs/data/openapi/api-explorer.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ The value is the key in the URL of the API, as in `/api/doc/elasticsearch/`. The
The section is an island. The sidebar of your pages shows a link to the API, and the API pages keep their own sidebar and URLs. Every version of the API is part of the section, and only the current version is visible. The API Explorer does not move: the pages still render at the same URLs whether or not the table of contents mounts them.

:::{note}
Only the isolated `build` command accepts `api:` entries for now. The assembler, `serve` and Codex builds report an error for an `api:` entry, so don't add one to a docset those builds load.
Only the isolated `build` command accepts `api:` entries for now. The assembler, `serve` and Codex builds report an error for an `api:` entry, so don't add one to a docset those builds load. The assembler mounts every declared API through a `floating: api` section in [`navigation.yml`](../../documentation/assembler/navigation.md#navigation-floating).
:::

### Link to an API page from Markdown [api-cross-links]
Expand Down
20 changes: 20 additions & 0 deletions docs/documentation/assembler/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ The location of the table of contents file.

`repo_name://path-relative-to-toc.yml`

## `section` with `floating` (optional) [navigation-floating]

A `section:` entry with `floating: api` puts the API pages of the site in the navigation tree:

```yml
toc:
- section: APIs
floating: api
```

When the build renders the API Explorer (the `assembler-api-explorer` feature flag), every API that a content repository declares in the `api:` block of its `docset.yml` becomes a child of the section. The section links to `/api/`, and each API is an island with its own sidebar. Only the current version of each API is visible, so older versions stay out of the sitemap and the `llms.txt` listing. The sitemap and the `llms.txt` listing read the section like any other part of the tree. The section is empty and adds nothing to a build that does not render the API Explorer.

A section can also have an `external:` link, as the `APIs` tab of the navigation preview does. The tab keeps its link, and the tree gets the APIs when the build has any:

```yml
- section: APIs
external: /api/
floating: api
```

## `path_prefix` (optional)

The `path_prefix` configuration key specifies the URL path segment that should be prefixed to all documentation URLs.
Expand Down
62 changes: 51 additions & 11 deletions src/Elastic.ApiExplorer/Floating/ApiFloatingSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ public sealed class ApiFloatingSectionProvider(BuildContext context) : IFloating

public string Kind => "api";

/// <summary>The page that lists every API, <c>/api/</c> under the site prefix.</summary>
public string? HubPath => "api";

public void Attach(OpenApiGenerator generator) => Generator = generator;

public IReadOnlyList<IFloatingSection> GetSections() =>
[
.. OpenApiGenerator.ApiConfigsToRender(context).Select(
c => (IFloatingSection)new ApiFloatingSection(c.Key, c.Value, this, context)
)
];

public bool TryGetSection(string key, [NotNullWhen(true)] out IFloatingSection? section)
{
section = null;
Expand Down Expand Up @@ -65,13 +75,22 @@ BuildContext context
public string UrlRoot => $"api/doc/{urlKey}";

public IFloatingSectionRoot CreateRoot(INodeNavigationItem<INavigationModel, INavigationItem>? parent) =>
_root = new ApiFloatingRoot(ApiUrlBuilder.ProductRoot(context.UrlPathPrefix, urlKey), config.Product.DisplayName ?? urlKey, parent);
_root = new ApiFloatingRoot(
urlKey,
ApiUrlBuilder.ProductRoot(context.UrlPathPrefix, urlKey),
config.Product.DisplayName ?? urlKey,
parent
);

public async Task ResolveAsync(Cancel ctx)
{
// Nothing mounted this section, so there is no root to fill.
if (_root is null)
return;

if (provider.Generator is not { } generator)
{
_root!.Hidden = true;
_root.Hidden = true;
return;
}

Expand All @@ -83,15 +102,15 @@ public async Task ResolveAsync(Cancel ctx)
catch (Exception ex) when (ex is not OperationCanceledException)
{
// The generator awaits the same cached task and reports the failure with its stack trace, so don't report it twice.
_root!.Hidden = true;
_root.Hidden = true;
return;
}

// No main document means no page at the unversioned URL, so the root links nowhere.
// The generator has already reported why a spec could not be loaded.
if (!trees.Resolved.Documents.Any(d => d.Version.Moniker == "main"))
{
_root!.Hidden = true;
_root.Hidden = true;
return;
}

Expand All @@ -100,8 +119,12 @@ public async Task ResolveAsync(Cancel ctx)
for (var i = 0; i < trees.Navigations.Count; i++)
trees.Navigations[i].Hidden = trees.Resolved.Documents[i].Version.Moniker != "main";

// The catalog titles an API the same way, so the navigation and the API hub agree.
var main = trees.Resolved.Documents.First(d => d.Version.Moniker == "main");
_root.Title = main.Document.Info?.Title ?? _root.Title;

_trees = trees;
_root!.SetNavigationItems(trees.Navigations);
_root.SetNavigationItems(trees.Navigations);
}

public FloatingLinkSection? ToLinkSection() => _trees is null ? null : ApiLinkSections.Create(urlKey, _trees);
Expand Down Expand Up @@ -169,24 +192,41 @@ public static FloatingLinkSection Create(string apiKey, ApiProductTrees trees)

internal sealed class ApiFloatingRoot : IFloatingSectionRoot, IAssignableIslandNavigation
{
public ApiFloatingRoot(string url, string title, INodeNavigationItem<INavigationModel, INavigationItem>? parent)
private readonly RootIndexLeaf _index;

public ApiFloatingRoot(string key, string url, string title, INodeNavigationItem<INavigationModel, INavigationItem>? parent)
{
Id = key;
Parent = parent;
Index = new ApiIndexLeafNavigation<ApiLanding>(new ApiLanding(), url, title, this, this);
_index = new RootIndexLeaf(url, title, this);
}

public string Url => Index.Url;
public string NavigationTitle => Index.NavigationTitle;
/// <summary>The title in the navigation. It starts as the product name and becomes the spec title once the spec is read.</summary>
public string Title { get => _index.NavigationTitle; set => _index.NavigationTitle = value; }

public string Url => _index.Url;
public string NavigationTitle => _index.NavigationTitle;
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot => this;
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; }
public bool Hidden { get; set; }
public int NavigationIndex { get; set; }
public bool IsIsland { get; set; }
public string Id => Index.NavigationTitle;
public ILeafNavigationItem<INavigationModel> Index { get; }
public string Id { get; }
public ILeafNavigationItem<INavigationModel> Index => _index;
public IReadOnlyCollection<INavigationItem> NavigationItems { get; private set; } = [];
public bool IsUsingNavigationDropdown => false;
public Uri Identifier => new($"api://{Url}");

public void SetNavigationItems(IReadOnlyCollection<INavigationItem> navigationItems) => NavigationItems = navigationItems;

private sealed class RootIndexLeaf(string url, string title, ApiFloatingRoot root) : ILeafNavigationItem<ApiLanding>
{
public ApiLanding Model { get; } = new();
public string Url { get; } = url;
public string NavigationTitle { get; set; } = title;
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot => root;
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; } = root;
public bool Hidden => false;
public int NavigationIndex { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public record SiteSectionRef(
string Title,
string? ExternalUrl,
IReadOnlyCollection<SiteTableOfContentsRef> Children,
IReadOnlyCollection<SiteDropdownLinkRef> DropdownLinks
IReadOnlyCollection<SiteDropdownLinkRef> DropdownLinks,
string? FloatingKind = null
) : ISiteNavigationEntry
{
public bool IsExternal => ExternalUrl is not null;
Expand Down Expand Up @@ -187,6 +188,7 @@ public SiteTableOfContentsCollectionYamlConverter() : this(new SiteTableOfConten
[
"section",
"external",
"floating",
"children",
"dropdown",
"toc",
Expand Down Expand Up @@ -319,7 +321,12 @@ public override SiteTableOfContents Read(YamlReader reader)
&& childrenObj is List<SiteTableOfContentsRef> refs ? refs : [];
IReadOnlyCollection<SiteDropdownLinkRef> dropdownLinks = dictionary.TryGetValue("dropdown", out var dropdownObj)
&& dropdownObj is List<SiteDropdownLinkRef> dLinks ? dLinks : [];
return new SiteSectionRef(sectionTitle, externalUrl, children, dropdownLinks);
// floating: <kind> mounts the floating sections of that kind (for example every API) as the section's children
// when the build has any. Without them the section keeps its other behaviour, such as an external link.
var floatingKind = dictionary.TryGetValue("floating", out var floatingVal)
&& floatingVal is string f
&& !string.IsNullOrEmpty(f) ? f : null;
return new SiteSectionRef(sectionTitle, externalUrl, children, dropdownLinks, floatingKind);
}

if (dictionary.TryGetValue("toc", out var tocPath) && tocPath is string sourceString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public class SectionNavigation(string title) : IRootNavigationItem<IDocumentatio

public string Title { get; } = title;

/// <summary>
/// True for the section that lists the floating sections of one kind, such as the APIs. It is not part of the reading
/// order of the docs, so the previous and next links skip it and its sections.
/// </summary>
public bool IsFloatingHub { get; init; }

/// Set by <c>SiteNavigation</c> after children are resolved to the first child's index URL.
public string Url { get; internal set; } = "/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ public static class SectionTopNavBuilder
{
// All pages within the section have NavigationRoot = sectionNav,
// so a single SectionId match is sufficient for active-tab detection.
var tabUrl = sectionNav
.NavigationItems
.OfType<IRootNavigationItem<INavigationModel, INavigationItem>>()
.FirstOrDefault()?.Index.Url;
// A floating hub has its own landing URL; the first child is just one of the sections it lists.
var tabUrl = section.FloatingKind is not null
? sectionNav.Url
Comment on lines +64 to +65

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: P3 (Low)

For a floating APIs section without external:, the tab gets the hub URL but is still assigned SectionId: sectionNav.Id below. API pages and the catalog retain their own navigation roots, so that ID never matches; the header's URL-based active-state fallback also excludes links with a section ID. Consequently, the newly supported tab never becomes active on its own pages. Leave the section ID unset for floating hubs or otherwise associate the rendered API roots with the tab, and cover active-state matching in the test.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

: sectionNav
.NavigationItems
.OfType<IRootNavigationItem<INavigationModel, INavigationItem>>()
.FirstOrDefault()?.Index.Url;

if (tabUrl is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public SiteNavigation(
IDocumentationContext context,
IReadOnlyCollection<IDocumentationSetNavigation> documentationSetNavigations,
string? sitePrefix,
bool navigationPreviewEnabled = false
bool navigationPreviewEnabled = false,
FloatingSectionRegistry? floatingSections = null
)
{
_floatingSections = floatingSections ?? FloatingSectionRegistry.Empty;
// Normalize sitePrefix to ensure it has a leading slash and no trailing slash
_sitePrefix = NormalizeSitePrefix(sitePrefix);
// Initialize root properties
Expand Down Expand Up @@ -91,7 +93,14 @@ public SiteNavigation(

foreach (var entry in siteNavigationFile.TableOfContents)
{
if (entry is SiteSectionRef sectionRef && !sectionRef.IsExternal && sectionRef.Children.Count > 0)
if (
entry is SiteSectionRef { FloatingKind: { } floatingKind } floatingRef
&& CreateFloatingHub(floatingRef, floatingKind, ref index) is { } hub
)
{
items.Add(hub);
}
else if (entry is SiteSectionRef sectionRef && !sectionRef.IsExternal && sectionRef.Children.Count > 0)
{
// Section with children becomes a real tree node (island) that groups its
// toc roots. FindIslandRoot() and CreateBackLinks then emit the correct
Expand Down Expand Up @@ -155,6 +164,48 @@ public SiteNavigation(
/// <inheritdoc cref="ISiteNavigationRoot.TopNav"/>
public TopNavRenderModel? TopNav { get; }

private readonly FloatingSectionRegistry _floatingSections;
private readonly List<IFloatingSection> _mountedFloatingSections = [];

/// <summary>The floating sections that <c>navigation.yml</c> mounts, in navigation order.</summary>
public IReadOnlyList<IFloatingSection> FloatingSections => _mountedFloatingSections;

/// <summary>
/// Fills the children of every mounted floating section. The roots exist from construction, so this can run
/// when the content is ready, but it must run before anything walks the children, such as the sitemap.
/// </summary>
public Task ResolveFloatingSectionsAsync(Cancel ctx) =>
Task.WhenAll(_mountedFloatingSections.Select(section => section.ResolveAsync(ctx)));

/// <summary>
/// A <c>floating: &lt;kind&gt;</c> section becomes a node whose children are the roots of every floating section of
/// that kind the build offers. It returns <c>null</c> when there are none, so the section keeps its other
/// behaviour, such as an external link, and a build without those sections is unchanged.
/// </summary>
private SectionNavigation? CreateFloatingHub(SiteSectionRef sectionRef, string kind, ref int index)
{
var sections = _floatingSections.GetSections(kind);
if (sections.Count == 0)
return null;

var hub = new SectionNavigation(sectionRef.Title) { Parent = this, IsFloatingHub = true };
var roots = new List<INavigationItem>(sections.Count);
foreach (var section in sections)
{
var root = section.CreateRoot(hub);
root.NavigationIndex = index++;
if (root is IAssignableIslandNavigation island)
island.IsIsland = true;
_mountedFloatingSections.Add(section);
roots.Add(root);
}

var hubPath = _floatingSections.HubPath(kind);
hub.Url = hubPath is null ? roots[0].Url : $"{Url.TrimEnd('/')}/{hubPath.Trim('/')}";
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
((IAssignableChildrenNavigation)hub).SetNavigationItems(roots);
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
return hub;
}

public HashSet<Uri> DeclaredPhantoms { get; }

/// <summary> All the table of contents explicitly declared in the navigation</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ public interface IFloatingSectionProvider
string Kind { get; }

bool TryGetSection(string key, [NotNullWhen(true)] out IFloatingSection? section);

/// <summary>
/// Every section of this kind the build can offer, in a stable order. A site-level mount, such as an
/// <c>APIs</c> section in <c>navigation.yml</c>, uses this to place all of them without naming each one.
/// </summary>
IReadOnlyList<IFloatingSection> GetSections() => [];

/// <summary>
/// The page that lists the sections of this kind, relative to the site root and without slashes at either end,
/// or <c>null</c> when there is none.
/// </summary>
string? HubPath => null;
}

/// <summary>The providers available to a build, looked up by toc key.</summary>
Expand All @@ -73,4 +85,11 @@ public bool TryGetSection(string kind, string key, [NotNullWhen(true)] out IFloa
section = null;
return _providers.TryGetValue(kind, out var provider) && provider.TryGetSection(key, out section);
}

/// <summary>Every section of <paramref name="kind"/> the build can offer, or none when no provider handles the kind.</summary>
public IReadOnlyList<IFloatingSection> GetSections(string kind) =>
_providers.TryGetValue(kind, out var provider) ? provider.GetSections() : [];

/// <summary>The hub page of <paramref name="kind"/>, relative to the site root, or <c>null</c> when it has none.</summary>
public string? HubPath(string kind) => _providers.TryGetValue(kind, out var provider) ? provider.HubPath : null;
}
14 changes: 12 additions & 2 deletions src/Elastic.Documentation.Navigation/INavigationTraversable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Collections.Frozen;
using System.Runtime.CompilerServices;

using Elastic.Documentation.Navigation.Assembler;
using Elastic.Documentation.Navigation.Floating;

namespace Elastic.Documentation.Navigation;

public static class NavigationExtensions
Expand Down Expand Up @@ -80,7 +83,7 @@ IEnumerable<INavigationItem> YieldAll()
do
{
var previous = NavigationIndexedByOrder.GetValueOrDefault(index - 1);
if (previous is not null && !previous.Hidden && previous.Url != currentNavigation.Url)
if (previous is not null && !previous.Hidden && previous.Url != currentNavigation.Url && InReadingOrder(previous))
return previous;
index--;
}
Expand All @@ -101,7 +104,7 @@ IEnumerable<INavigationItem> YieldAll()
do
{
var next = NavigationIndexedByOrder.GetValueOrDefault(index + 1);
if (next is not null && !next.Hidden && next.Url != currentNavigation.Url)
if (next is not null && !next.Hidden && next.Url != currentNavigation.Url && InReadingOrder(next))
return next;
index++;
}
Expand All @@ -110,6 +113,13 @@ IEnumerable<INavigationItem> YieldAll()
return null;
}

/// <summary>
/// The floating sections, such as the APIs, and the hub that lists them are not pages of the docs, so paging through the
/// docs does not walk into them.
/// </summary>
private static bool InReadingOrder(INavigationItem item) =>
item is not (IFloatingSectionRoot or SectionNavigation { IsFloatingHub: true });

INavigationItem GetNavigationFor(IDocumentationFile file) =>
NavigationDocumentationFileLookup.TryGetValue(file, out var navigation)
? navigation
Expand Down
Loading
Loading