Skip to content

Commit 9bfedf7

Browse files
committed
stage
1 parent e7418d4 commit 9bfedf7

File tree

3 files changed

+25
-36
lines changed

3 files changed

+25
-36
lines changed

src/Elastic.Documentation.Navigation/Isolated/DocumentationSetNavigation.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -399,35 +399,24 @@ int depth
399399
context.ReadFileSystem.Path.Combine(context.DocumentationSourceDirectory.FullName, fullTocPath)
400400
);
401401

402-
// TODO: Add validation for TOCs with children in parent YAML
403-
// This is a known limitation - TOCs should not have children defined in parent YAML
404-
405-
// According to url-building.md line 19-21: "We are not actually changing the PathPrefix,
406-
// we create the scope to be able to rehome during Assembler builds."
407-
// So TOC uses the SAME PathPrefix as its parent - it only creates a scope for rehoming
408-
var scopedPathPrefix = homeProvider.PathPrefix;
409-
410402
// Create the TOC navigation with empty children initially
411403
// We use null parent temporarily - we'll set it properly at the end using the public setter
404+
// Pass tocHomeProvider so the TOC uses parent's NavigationRoot (enables dynamic URL updates)
412405
var tocNavigation = new TableOfContentsNavigation(
413406
tocDirectory,
414407
depth + 1,
415408
fullTocPath,
416409
null, // Temporary null parent
417-
scopedPathPrefix,
410+
homeProvider.PathPrefix,
418411
[],
419412
Git,
420-
_tableOfContentNodes
413+
_tableOfContentNodes,
414+
homeProvider
421415
)
422416
{
423417
NavigationIndex = index
424418
};
425419

426-
// Create a scoped HomeProvider for TOC children
427-
// According to url-building.md: "In isolated builds the NavigationRoot is always the DocumentationSetNavigation"
428-
// So we use the parent's NavigationRoot, not the TOC itself
429-
var tocHomeProvider = new NavigationHomeProvider(scopedPathPrefix, homeProvider.NavigationRoot);
430-
431420
// Convert children - pass tocNavigation as parent and tocHomeProvider as HomeProvider (TOC creates new scope)
432421
var children = new List<INavigationItem>();
433422
var childIndex = 0;
@@ -441,7 +430,7 @@ int depth
441430
childIndex++,
442431
context,
443432
tocNavigation,
444-
tocHomeProvider, // Use the scoped HomeProvider with correct NavigationRoot
433+
homeProvider, // Use the scoped HomeProvider with correct NavigationRoot
445434
depth + 1
446435
);
447436

@@ -470,10 +459,11 @@ int depth
470459
depth + 1,
471460
fullTocPath,
472461
parent, // Now set the correct parent
473-
scopedPathPrefix,
462+
homeProvider.PathPrefix,
474463
children,
475464
Git,
476-
_tableOfContentNodes
465+
_tableOfContentNodes,
466+
homeProvider // Pass same HomeProvider to final TOC
477467
)
478468
{
479469
NavigationIndex = index

src/Elastic.Documentation.Navigation/Isolated/TableOfContentsNavigation.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public TableOfContentsNavigation(
2626
string pathPrefix,
2727
IReadOnlyCollection<INavigationItem> navigationItems,
2828
GitCheckoutInformation git,
29-
Dictionary<Uri, INodeNavigationItem<IDocumentationFile, INavigationItem>> tocNodes
29+
Dictionary<Uri, INodeNavigationItem<IDocumentationFile, INavigationItem>> tocNodes,
30+
INavigationHomeProvider homeProvider
3031
)
3132
{
3233
TableOfContentsDirectory = tableOfContentsDirectory;
@@ -38,10 +39,11 @@ Dictionary<Uri, INodeNavigationItem<IDocumentationFile, INavigationItem>> tocNod
3839
Id = ShortId.Create(parentPath);
3940
Depth = depth;
4041
ParentPath = parentPath;
41-
_pathPrefix = pathPrefix;
42+
PathPrefix = pathPrefix;
4243

43-
// Initialize _homeProvider to this - it will be updated in assembler builds if needed
44-
_homeProvider = this;
44+
// Initialize _homeProvider from the provided homeProvider
45+
// According to url-building.md: "In isolated builds the NavigationRoot is always the DocumentationSetNavigation"
46+
_homeProvider = homeProvider;
4547

4648
// Create an identifier for this TOC
4749
Identifier = new Uri($"{git.RepositoryName}://{parentPath}");
@@ -51,20 +53,17 @@ Dictionary<Uri, INodeNavigationItem<IDocumentationFile, INavigationItem>> tocNod
5153
Index = this.FindIndex<IDocumentationFile>(new NotFoundModel($"{parentPath}/index.md"));
5254
}
5355

54-
private readonly string _pathPrefix;
55-
5656
/// <summary>
57-
/// Internal HomeProvider - defaults to this, but can be updated in assembler builds.
57+
/// Internal HomeProvider - can be updated in assembler builds for rehoming.
5858
/// </summary>
5959
private INavigationHomeProvider _homeProvider { get; set; }
6060

6161
/// <summary>
62-
/// The composed path prefix for this TOC, which is the parent's prefix + this TOC's parent path.
63-
/// This is used by children to build their URLs.
64-
/// Implements INavigationHomeProvider.PathPrefix
65-
/// When HomeProvider is set (during assembler), this returns the external provider's PathPrefix.
62+
/// The path prefix for this TOC - same as parent per url-building.md.
63+
/// Implements INavigationHomeProvider.PathPrefix.
64+
/// TOC doesn't change PathPrefix from parent.
6665
/// </summary>
67-
public string PathPrefix => _homeProvider == this ? _pathPrefix : _homeProvider.PathPrefix;
66+
public string PathPrefix { get; }
6867

6968
/// <inheritdoc />
7069
public string Url => Index.Url;
@@ -73,11 +72,11 @@ Dictionary<Uri, INodeNavigationItem<IDocumentationFile, INavigationItem>> tocNod
7372
public string NavigationTitle => Index.NavigationTitle;
7473

7574
/// <summary>
76-
/// TableOfContentsNavigation is its own NavigationRoot in isolated builds.
77-
/// In assembler builds, this can be overridden via HomeProvider.
75+
/// TableOfContentsNavigation's NavigationRoot comes from its HomeProvider.
76+
/// According to url-building.md: "In isolated builds the NavigationRoot is always the DocumentationSetNavigation"
7877
/// This satisfies both INavigationItem.NavigationRoot and INavigationHomeProvider.NavigationRoot.
7978
/// </summary>
80-
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot => _homeProvider == this ? this : _homeProvider.NavigationRoot;
79+
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot => _homeProvider.NavigationRoot;
8180

8281
/// <inheritdoc />
8382
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; }

tests/Navigation.Tests/Isolation/NavigationStructureTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,12 @@ void VisitNavigationItems(INavigationItem item)
340340
gettingStarted.NavigationRoot.Should().BeSameAs(navigation);
341341

342342
// According to url-building.md: "In isolated builds the NavigationRoot is always the DocumentationSetNavigation"
343-
// Items in advanced TOC should point to DocumentationSetNavigation, not the TOC
343+
// ALL items including TOCs should point to DocumentationSetNavigation as NavigationRoot
344344
var advancedToc = setupFolder.NavigationItems.ElementAt(1).Should().BeOfType<TableOfContentsNavigation>().Subject;
345-
advancedToc.NavigationRoot.Should().BeSameAs(advancedToc, "TableOfContentsNavigation is its own root when not rehomed");
345+
advancedToc.NavigationRoot.Should().BeSameAs(navigation, "TOC NavigationRoot should be DocumentationSetNavigation in isolated builds");
346346

347347
var advancedIndex = advancedToc.NavigationItems.First();
348-
advancedIndex.NavigationRoot.Should().BeSameAs(navigation, "Items within TOC should point to DocumentationSetNavigation in isolated builds");
348+
advancedIndex.NavigationRoot.Should().BeSameAs(navigation, "TOC children should point to DocumentationSetNavigation in isolated builds");
349349

350350
// Items in file with children should point to DocumentationSetNavigation
351351
var guideFile = navigation.NavigationItems.ElementAt(2).Should().BeOfType<VirtualFileNavigation<TestDocumentationFile>>().Subject;

0 commit comments

Comments
 (0)