From 340486f0a6b3afb925948f7d4d31a7c156e126a0 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 12 Dec 2024 16:10:06 +0800 Subject: [PATCH] Add isIndex to NavigationNode --- .../Volo/Docs/Documents/NavigationNode.cs | 3 +++ .../Pages/Documents/Project/Index.cshtml | 16 ++++++++-------- .../Pages/Documents/Project/Index.cshtml.cs | 1 - 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs index 2f1afce342..231a8cddba 100644 --- a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs +++ b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs @@ -15,6 +15,9 @@ namespace Volo.Docs.Documents [JsonPropertyName("items")] public List Items { get; set; } + + [JsonPropertyName("isIndex")] + public bool IsIndex { get; set; } public bool IsLeaf => !HasChildItems; diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml index fdb974e292..976154c630 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml @@ -323,14 +323,14 @@ } - + previousNode = indexDocument; } - + currentNode = currentNode?.Items?.FirstOrDefault(n => n.IsSelected(Model.DocumentNameWithExtension)); } } - + void PrintNode(NavigationNode node, string text = null) { var extension = System.IO.Path.GetExtension(node.Path); @@ -341,7 +341,7 @@ } - + NavigationNode FindIndexNode(NavigationNode node) { var nextNode = node.Items?.FirstOrDefault(n => n.IsSelected(Model.DocumentNameWithExtension)); @@ -349,15 +349,15 @@ { nextNode = nextNode.Items.FirstOrDefault(n => n.IsSelected(Model.DocumentNameWithExtension)); } - + if(nextNode == null) { - return node.Items?.FirstOrDefault(n => n.Text == "Overview"); + return node.Items?.FirstOrDefault(n => n.IsIndex); } - + var lastSlashIndex = nextNode.Path.LastIndexOf('/'); var path = lastSlashIndex < 0 ? nextNode.Path : nextNode.Path.Substring(0, lastSlashIndex); - return node.Items.FirstOrDefault(n => n.Path != null && (n.IsSelected(path + documentExtension) || n.IsSelected(path + "/index" + documentExtension))) ?? node.Items.FirstOrDefault(n => n.Text == "Overview"); + return node.Items.FirstOrDefault(n => n.Path != null && (n.IsSelected(path + documentExtension) || n.IsSelected(path + "/index" + documentExtension))) ?? node.Items.FirstOrDefault(n => n.IsIndex); } } diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs index 0f59a03a1e..d6acd8c262 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs @@ -461,7 +461,6 @@ namespace Volo.Docs.Pages.Documents.Project Version = Version } ); - } catch (DocumentNotFoundException) //TODO: What if called on a remote service which may return 404 {