-
Notifications
You must be signed in to change notification settings - Fork 27
Add crosslinks to toc: in docset.yml #1615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
theletterf
wants to merge
31
commits into
main
Choose a base branch
from
crosslinks-in-toc-take-three
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bf5747a
Add crosslinks to toc
theletterf c1bb57d
Fix errors
theletterf c92fb38
Update docs
theletterf d4bd6ca
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf b78c2c3
Add title validation
theletterf 04920ab
Add ctx for Cancel
theletterf effe888
FileNavigationItem can be ignored
theletterf 03ec234
Remove redundant code
theletterf d3a8574
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf 134b86d
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf 081d4c4
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf ca8bc40
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf db1db5e
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf 2567bf4
Move routine
theletterf cb1d64a
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf a19d49b
Fix resolution
theletterf 4f4ebbe
Merge branch 'crosslinks-in-toc-take-three' of github.com:elastic/doc…
theletterf 30ed149
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf 37a224f
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf ac0284b
Fix hx-select-oob for nav crosslinks
theletterf f52e66e
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf b0e6ec3
Merge branch 'main' into crosslinks-in-toc-take-three
Mpdreamz 0a52f75
Add validation and title as mandatory
theletterf 05c8f8c
Add utility class for crosslink validation
theletterf f51258d
Remove redundant file
theletterf 7d3d364
Refactor NavCrossLinkValidator
theletterf e0ea3bb
Merge branch 'main' into crosslinks-in-toc-take-three
theletterf 10e8a52
Merge branch 'main' into crosslinks-in-toc-take-three
Mpdreamz 05cc209
Ensure we inject docs-builder on CI for integration tests as well
Mpdreamz 4f9ca60
allow docs-builder to have local checkout folder on CI
Mpdreamz cca7d09
Ensure we hadnle CrossLinkNavigationItem when building the sitemap by…
Mpdreamz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Collections.Immutable; | ||
|
||
namespace Elastic.Documentation.Links; | ||
|
||
/// <summary> | ||
/// Utility class for validating and identifying cross-repository links | ||
/// </summary> | ||
public static class CrossLinkValidator | ||
{ | ||
/// <summary> | ||
/// URI schemes that are excluded from being treated as cross-repository links. | ||
/// These are standard web/protocol schemes that should not be processed as crosslinks. | ||
/// </summary> | ||
private static readonly ImmutableHashSet<string> ExcludedSchemes = | ||
ImmutableHashSet.Create(StringComparer.OrdinalIgnoreCase, | ||
"http", "https", "ftp", "file", "tel", "jdbc", "mailto"); | ||
|
||
/// <summary> | ||
/// Validates that a URI string is a valid cross-repository link. | ||
/// </summary> | ||
/// <param name="uriString">The URI string to validate</param> | ||
/// <param name="errorMessage">Error message if validation fails</param> | ||
/// <returns>True if valid crosslink, false otherwise</returns> | ||
public static bool IsValidCrossLink(string? uriString, out string? errorMessage) | ||
{ | ||
errorMessage = null; | ||
|
||
if (string.IsNullOrWhiteSpace(uriString)) | ||
{ | ||
errorMessage = "Cross-link entries must specify a non-empty URI"; | ||
return false; | ||
} | ||
|
||
if (!Uri.TryCreate(uriString, UriKind.Absolute, out var uri)) | ||
{ | ||
errorMessage = $"Cross-link URI '{uriString}' is not a valid absolute URI format"; | ||
return false; | ||
} | ||
|
||
if (ExcludedSchemes.Contains(uri.Scheme)) | ||
{ | ||
errorMessage = $"Cross-link URI '{uriString}' cannot use standard web/protocol schemes ({string.Join(", ", ExcludedSchemes)}). Use cross-repository schemes like 'docs-content://', 'kibana://', etc."; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Determines if a URI is a cross-repository link (for identification purposes). | ||
/// This is more permissive than validation and is used by the Markdown parser. | ||
/// </summary> | ||
/// <param name="uri">The URI to check</param> | ||
/// <returns>True if this should be treated as a crosslink</returns> | ||
public static bool IsCrossLink(Uri? uri) => | ||
uri != null | ||
&& !ExcludedSchemes.Contains(uri.Scheme) | ||
&& !uri.IsFile | ||
&& !string.IsNullOrEmpty(uri.Scheme); | ||
|
||
/// <summary> | ||
/// Gets the list of excluded URI schemes for reference | ||
/// </summary> | ||
public static IReadOnlySet<string> GetExcludedSchemes() => ExcludedSchemes; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Elastic.Markdown/IO/Navigation/CrossLinkNavigationItem.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Elastic.Documentation.Site.Navigation; | ||
|
||
namespace Elastic.Markdown.IO.Navigation; | ||
|
||
[DebuggerDisplay("CrossLink: {Url}")] | ||
public record CrossLinkNavigationItem : ILeafNavigationItem<INavigationModel> | ||
{ | ||
// Override Url accessor to use ResolvedUrl if available | ||
string INavigationItem.Url => ResolvedUrl ?? Url; | ||
public CrossLinkNavigationItem(string url, string title, DocumentationGroup group, bool hidden = false) | ||
{ | ||
_url = url; | ||
NavigationTitle = title; | ||
Parent = group; | ||
NavigationRoot = group.NavigationRoot; | ||
Hidden = hidden; | ||
} | ||
|
||
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; } | ||
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot { get; } | ||
// Original URL from the cross-link | ||
private readonly string _url; | ||
|
||
// Store resolved URL for rendering | ||
public string? ResolvedUrl { get; set; } | ||
|
||
// Implement the INavigationItem.Url property to use ResolvedUrl if available | ||
public string Url => ResolvedUrl ?? _url; public string NavigationTitle { get; } | ||
public int NavigationIndex { get; set; } | ||
public bool Hidden { get; } | ||
public bool IsCrossLink => true; // This is always a cross-link | ||
public INavigationModel Model => null!; // Cross-link has no local model | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.