From 5a0d03d4132140849d1f06747a0feef16832395d Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 7 Aug 2024 16:20:52 +0800 Subject: [PATCH] Show Document navigation text for page title --- .../Volo/Docs/Documents/NavigationNode.cs | 21 ++++++++++++------- .../Pages/Documents/Project/Index.cshtml | 2 +- .../Pages/Documents/Project/Index.cshtml.cs | 9 ++++++++ 3 files changed, 23 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 6ecf7eb204..2f1afce342 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 @@ -29,12 +29,17 @@ namespace Volo.Docs.Documents public DateTime? LastSignificantUpdateTime { get; set; } public bool IsSelected(string documentName) + { + return FindNavigation(documentName) != null; + } + + public NavigationNode FindNavigation(string documentName) { if (documentName == null) { - return false; + return null; } - + var path = Path ?? string.Empty; var pathHasExtension = System.IO.Path.HasExtension(path); @@ -44,26 +49,26 @@ namespace Volo.Docs.Documents path = path.EnsureEndsWith('/') + "index" + extension; } - if (string.Equals(documentName, path, StringComparison.OrdinalIgnoreCase)) { - return true; + return this; } if (Items == null) { - return false; + return null; } foreach (var childItem in Items) { - if (childItem.IsSelected(documentName)) + var node = childItem.FindNavigation(documentName); + if (node != null) { - return true; + return node; } } - return false; + return null; } } 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 b60ad9507f..9507da66ce 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 @@ -28,7 +28,7 @@ @{ ViewBag.FluidLayout = true; Layout = ThemeManager.CurrentTheme.GetEmptyLayout(); - PageLayout.Content.Title = Model.DocumentName?.Replace("-", " "); + PageLayout.Content.Title = Model.DocumentPageTitle; ViewBag.Description = Model.GetDescription(); ViewBag.CanonicalUrl = Model.IsLatestVersion ? null : Model.GetFullUrlOfTheLatestDocument(); //issue #12355 } 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 c3c1ae9643..95619ccb91 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 @@ -55,6 +55,8 @@ namespace Volo.Docs.Pages.Documents.Project public List LanguageSelectListItems { get; set; } public string DocumentNameWithExtension { get; private set; } + + public string DocumentPageTitle { get; private set; } public DocumentWithDetailsDto Document { get; private set; } @@ -191,6 +193,7 @@ namespace Volo.Docs.Pages.Documents.Project await SetNavigationAsync(); SetLanguageSelectListItems(); + SetDocumentPageTitle(); return Page(); } @@ -455,12 +458,18 @@ namespace Volo.Docs.Pages.Documents.Project Version = Version } ); + } catch (DocumentNotFoundException) //TODO: What if called on a remote service which may return 404 { return; } } + + private void SetDocumentPageTitle() + { + DocumentPageTitle = Navigation.FindNavigation(DocumentNameWithExtension)?.Text ?? DocumentName?.Replace("-", " "); + } public string CreateVersionLink(VersionInfoViewModel latestVersion, string version, string documentName = null) {