Skip to content
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

Add "alternative words" to filter items in docs #22065

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion docs/en/docs-nav.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@
},
{
"text": "Exception Handling",
"path": "framework/fundamentals/exception-handling.md"
"path": "framework/fundamentals/exception-handling.md",
"keywords": ["Error"]
},
{
"text": "Localization",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class NavigationNode

[JsonPropertyName("isIndex")]
public bool IsIndex { get; set; }

[JsonPropertyName("keywords")]
public string[] Keywords { get; set; }

public bool IsLeaf => !HasChildItems;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Razor.TagHelpers;
Expand All @@ -23,7 +24,7 @@ public class TreeTagHelper : TagHelper

private const string LiItemTemplateWithLink = @"<li class='{0}'><span class='plus-icon'><i class='fa fa-{1}'></i></span>{2}{3}</li>";

private const string ListItemAnchor = @"<a href='{0}' class='{1}'>{2}</a>";
private const string ListItemAnchor = @"<a href='{0}' {1} class='{2}'>{3}</a>";

private const string ListItemSpan = @"<span class='{0}'>{1}</span>";

Expand Down Expand Up @@ -155,7 +156,8 @@ private string GetLeafNode(NavigationNode node, string content)

sb.Clear();

listInnerItem = string.Format(ListItemAnchor, NormalizePath(node.Path), textCss,
var additionalAttributes = node.Keywords.IsNullOrEmpty() ? "" : "data-keywords=\"" + node.Keywords.JoinAsString(",") + "\"";
listInnerItem = string.Format(ListItemAnchor, NormalizePath(node.Path), additionalAttributes ,textCss,
node.Text.IsNullOrEmpty()
? "?"
: sb.Append(node.Text).Append(badgeStringBuilder.ToString()).ToString());
Expand Down
20 changes: 13 additions & 7 deletions modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var doc = doc || {};
var $ul = $(`<ul class="nav nav-list tree" ${uiCss}></ul>`);
var $li = $(`<li class="${node.hasChildItems ? 'nav-header' : 'last-link'}"></li>`);

$li.append(`<span class="plus-icon"> <i class="fa fa-${node.hasChildItems ? 'chevron-right' : node.path === "javascript:;" ? 'has-link' : 'no-link'}"></i></span><a href="${node.path}" class="${textCss}">${node.text}</a>`)
var dataKeywords = node.keywords ? `data-keywords="${node.keywords}"` : "";
$li.append(`<span class="plus-icon"> <i class="fa fa-${node.hasChildItems ? 'chevron-right' : node.path === "javascript:;" ? 'has-link' : 'no-link'}"></i></span><a href="${node.path}" ${dataKeywords} class="${textCss}">${node.text}</a>`)

if(node.isLazyExpandable){
$li.addClass("lazy-expand");
Expand Down Expand Up @@ -111,12 +112,17 @@ var doc = doc || {};
var filteredItems = $navigation
.find('li > a')
.filter(function () {
return (
$(this)
.text()
.toUpperCase()
.indexOf(filterText.toUpperCase()) > -1
);
var keywords = ($(this).data('keywords') || "").split(",");
var text = $(this).text();

if(text.toUpperCase().indexOf(filterText.toUpperCase()) > -1)
{
return true;
}

return keywords.some(function(keyword){
return keyword.toUpperCase().indexOf(filterText.toUpperCase()) > -1;
});
});

filteredItems.each(function () {
Expand Down
Loading