Skip to content

Commit c2700a0

Browse files
committed
update url logic to be relative conditionally
1 parent bcaa17f commit c2700a0

File tree

16 files changed

+281
-146
lines changed

16 files changed

+281
-146
lines changed

src/Elastic.Documentation.Configuration/DocSet/DocumentationSetFile.cs

Lines changed: 101 additions & 59 deletions
Large diffs are not rendered by default.

src/Elastic.Documentation.Configuration/DocSet/SiteNavigationFile.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public record SiteTableOfContentsRef(Uri Source, string PathPrefix, IReadOnlyCol
128128
: ITableOfContentsItem
129129
{
130130
// For site-level TOC refs, the Path is the path prefix (where it will be mounted in the site)
131-
public string Path => PathPrefix;
131+
public string PathRelativeToDocumentationSet => PathPrefix;
132+
133+
// For site-level TOC refs, PathRelativeToContainer is the same as PathRelativeToDocumentationSet
134+
// since they're all defined in the same navigation.yml file
135+
public string PathRelativeToContainer => PathPrefix;
132136

133137
// For site-level TOC refs, the Context is the navigation.yml file path
134138
// This will be set during site navigation loading

src/Elastic.Documentation.Configuration/Plugins/DetectionRules/TableOfContents/DetectionRulesReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public record RuleOverviewReference : FileRef
1818
private string TocContext { get; }
1919

2020
public RuleOverviewReference(
21-
string overviewFilePath,
21+
string overviewFilePathRelativeToDocumentationSet,
2222
string parentPath,
2323
ConfigurationFile configuration,
2424
IDocumentationSetContext context,
2525
IReadOnlyCollection<string> detectionRuleFolders,
2626
string tocContext
2727
)
28-
: base(overviewFilePath, false, [], tocContext)
28+
: base(overviewFilePathRelativeToDocumentationSet, overviewFilePathRelativeToDocumentationSet, false, [], tocContext)
2929
{
3030
ParentPath = parentPath;
3131
TocContext = tocContext;
@@ -70,7 +70,7 @@ private IReadOnlyCollection<ITableOfContentsItem> ReadDetectionRuleFolder(IDocum
7070
return new RuleReference(relativePath, detectionRuleFolder, true, [], rule, TocContext);
7171
}
7272

73-
return new FileRef(relativePath, false, [], TocContext);
73+
return new FileRef(relativePath, relativePath, false, [], TocContext);
7474
})
7575
.ToArray();
7676

src/Elastic.Documentation.Configuration/Plugins/DetectionRules/TableOfContents/RuleReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
namespace Elastic.Documentation.Configuration.Plugins.DetectionRules.TableOfContents;
88

99
public record RuleReference(
10-
string RelativePath,
10+
string RelativePathRelativeToDocumentationSet,
1111
string SourceDirectory,
1212
bool Found,
1313
IReadOnlyCollection<ITableOfContentsItem> Children,
1414
DetectionRule Rule,
1515
string Context
1616
)
17-
: FileRef(RelativePath, true, Children, Context);
17+
: FileRef(RelativePathRelativeToDocumentationSet, RelativePathRelativeToDocumentationSet, true, Children, Context);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ INavigationHomeAccessor homeAccessor
236236
)
237237
{
238238
// FileRef.Path already contains the correct path from LoadAndResolve
239-
var fullPath = fileRef.Path;
239+
var fullPath = fileRef.PathRelativeToDocumentationSet;
240240

241241
// Create file info and documentation file
242242
var fileInfo = ResolveFileInfo(context, fullPath);
@@ -247,13 +247,14 @@ INavigationHomeAccessor homeAccessor
247247
// Handle leaf case (no children)
248248
if (fileRef.Children.Count <= 0)
249249
{
250-
var leafNavigationArgs = new FileNavigationArgs(fullPath, fileRef.Hidden, index, parent, homeAccessor);
250+
var leafNavigationArgs = new FileNavigationArgs(fullPath, fileRef.PathRelativeToContainer, fileRef.Hidden, index, parent, homeAccessor);
251251
return DocumentationNavigationFactory.CreateFileNavigationLeaf(documentationFile, fileInfo, leafNavigationArgs);
252252
}
253253

254254
// Create file navigation with empty children initially
255255
var virtualFileNavigationArgs = new VirtualFileNavigationArgs(
256256
fullPath,
257+
fileRef.PathRelativeToContainer,
257258
fileRef.Hidden,
258259
index,
259260
parent?.Depth + 1 ?? 0,
@@ -324,7 +325,7 @@ int depth
324325
)
325326
{
326327
// FolderRef.Path already contains the correct path from LoadAndResolve
327-
var folderPath = folderRef.Path;
328+
var folderPath = folderRef.PathRelativeToDocumentationSet;
328329

329330
// Create folder navigation with null parent initially - we'll pass it to children but set it properly after
330331
var folderNavigation = new FolderNavigation(depth + 1, folderPath, parent, homeAccessor, [])
@@ -372,7 +373,7 @@ int depth
372373
)
373374
{
374375
// tocRef.Path is now the FULL path (e.g., "guides/api" or "setup/advanced") after LoadAndResolve
375-
var fullTocPath = tocRef.Path;
376+
var fullTocPath = tocRef.PathRelativeToDocumentationSet;
376377

377378
var tocDirectory = context.ReadFileSystem.DirectoryInfo.New(
378379
context.ReadFileSystem.Path.Combine(context.DocumentationSourceDirectory.FullName, fullTocPath)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Diagnostics;
66
using System.IO.Abstractions;
7+
using Elastic.Documentation.Navigation.Assembler;
78

89
namespace Elastic.Documentation.Navigation.Isolated;
910

@@ -31,8 +32,10 @@ public string Url
3132
get
3233
{
3334
var rootUrl = args.HomeAccessor.HomeProvider.PathPrefix.TrimEnd('/');
35+
var relativeToContainer = args.HomeAccessor.HomeProvider.NavigationRoot.Parent is SiteNavigation;
36+
3437
// Remove extension while preserving the directory path
35-
var relativePath = args.RelativePathToDocumentationSet;
38+
var relativePath = relativeToContainer ? args.RelativePathToTableOfContents : args.RelativePathToDocumentationSet;
3639
var path = relativePath.EndsWith(".md", StringComparison.OrdinalIgnoreCase)
3740
? relativePath[..^3] // Remove last 3 characters (.md)
3841
: relativePath;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class VirtualFileNavigation<TModel>(TModel model, IFileInfo fileInfo, Vir
5353

5454
/// <inheritdoc />
5555
public ILeafNavigationItem<TModel> Index { get; } =
56-
new FileNavigationLeaf<TModel>(model, fileInfo, new FileNavigationArgs(args.RelativePathToDocumentationSet, args.RelativePathToDocumentationSet, args.Hidden, args.NavigationIndex, args.Parent, args.HomeAccessor));
56+
new FileNavigationLeaf<TModel>(model, fileInfo, new FileNavigationArgs(args.RelativePathToDocumentationSet, args.RelativePathToTableOfContents, args.Hidden, args.NavigationIndex, args.Parent, args.HomeAccessor));
5757

5858
public IReadOnlyCollection<INavigationItem> NavigationItems { get; private set; } = [];
5959

src/Elastic.Markdown/Extensions/DetectionRules/DetectionRuleFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public DetectionRuleOverviewFile(IFileInfo sourceFile, IDirectoryInfo rootPath,
2323

2424
private Dictionary<string, DetectionRuleFile> Files { get; } = [];
2525

26-
public void AddDetectionRuleFile(DetectionRuleFile df, RuleReference ruleReference) => Files[ruleReference.RelativePath] = df;
26+
public void AddDetectionRuleFile(DetectionRuleFile df, RuleReference ruleReference) => Files[ruleReference.RelativePathRelativeToDocumentationSet] = df;
2727

2828
protected override Task<MarkdownDocument> GetMinimalParseDocumentAsync(Cancel ctx)
2929
{

src/Elastic.Markdown/Extensions/DetectionRules/DetectionRulesDocsBuilderExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Func<IFileInfo, IDirectoryInfo, DocumentationFile> defaultFileHandling
7171
var sourceDirectory = Build.ReadFileSystem.DirectoryInfo.New(sourcePath);
7272
return rules.Select(r =>
7373
{
74-
var file = Build.ReadFileSystem.FileInfo.New(Path.Combine(sourceDirectory.FullName, r.RelativePath));
74+
var file = Build.ReadFileSystem.FileInfo.New(Path.Combine(sourceDirectory.FullName, r.RelativePathRelativeToDocumentationSet));
7575
return (file, defaultFileHandling(file, sourceDirectory));
7676

7777
}).ToArray();

0 commit comments

Comments
 (0)