Skip to content

Commit

Permalink
Add "alternative words" to filter items in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
realLiangshiwei committed Feb 3, 2025
1 parent defab9c commit 0c17d37
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
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 dataKeywords = node.Keywords.IsNullOrEmpty() ? "" : "data-keywords=\"" + node.Keywords.JoinAsString(",") + "\"";
listInnerItem = string.Format(ListItemAnchor, NormalizePath(node.Path), dataKeywords ,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

0 comments on commit 0c17d37

Please sign in to comment.