Browse Source

Add "alternative words" to filter items in docs

pull/22065/head
liangshiwei 2 years ago
parent
commit
0c17d379ef
  1. 3
      docs/en/docs-nav.json
  2. 3
      modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs
  3. 6
      modules/docs/src/Volo.Docs.Web/Areas/Documents/TagHelpers/TreeTagHelper.cs
  4. 20
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js

3
docs/en/docs-nav.json

@ -487,7 +487,8 @@
},
{
"text": "Exception Handling",
"path": "framework/fundamentals/exception-handling.md"
"path": "framework/fundamentals/exception-handling.md",
"keywords": ["error"]
},
{
"text": "Localization",

3
modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs

@ -21,6 +21,9 @@ namespace Volo.Docs.Documents
[JsonPropertyName("isIndex")]
public bool IsIndex { get; set; }
[JsonPropertyName("keywords")]
public string[] Keywords { get; set; }
public bool IsLeaf => !HasChildItems;

6
modules/docs/src/Volo.Docs.Web/Areas/Documents/TagHelpers/TreeTagHelper.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Razor.TagHelpers;
@ -23,7 +24,7 @@ namespace Volo.Docs.Areas.Documents.TagHelpers
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>";
@ -155,7 +156,8 @@ namespace Volo.Docs.Areas.Documents.TagHelpers
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());

20
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js

@ -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");
@ -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 () {

Loading…
Cancel
Save