From febc1297263eda3c9b8fd68b797362a3980581d1 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 15 Aug 2024 18:25:56 +0800 Subject: [PATCH 1/2] Show H1 tag value for page titles --- .../Pages/Documents/Project/Index.cshtml.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 c80b81bf713..3458015560c 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 @@ -197,7 +197,6 @@ private async Task SetPageAsync() await SetNavigationAsync(); SetLanguageSelectListItems(); - SetDocumentPageTitle(); return Page(); } @@ -472,7 +471,12 @@ private async Task SetNavigationAsync() private void SetDocumentPageTitle() { - DocumentPageTitle = Navigation.FindNavigation(DocumentNameWithExtension)?.Text ?? DocumentName?.Replace("-", " "); + DocumentPageTitle = DocumentName?.Replace("-", " "); + var match = Regex.Match(Document.Content, @"#(?.+)"); + if (match.Success && match.Groups.TryGetValue("PageTitle", out var group)) + { + DocumentPageTitle = Regex.Replace(group.Value, "<.*?>", string.Empty); + } } public string CreateVersionLink(VersionInfoViewModel latestVersion, string version, string documentName = null) @@ -508,6 +512,7 @@ private async Task TrySetDocumentAsync() Document = await GetSpecificDocumentOrDefaultAsync(language); DocumentLanguageCode = language; DocumentNameWithExtension = Document.Name; + SetDocumentPageTitle(); await ConvertDocumentContentToHtmlAsync(); return true; } From 478e102777934f94b4647a886381690ce818708c Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 15 Aug 2024 18:53:22 +0800 Subject: [PATCH 2/2] Update Index.cshtml.cs --- .../src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3458015560c..a5fcd7ea0e0 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 @@ -475,7 +475,7 @@ private void SetDocumentPageTitle() var match = Regex.Match(Document.Content, @"#(?.+)"); if (match.Success && match.Groups.TryGetValue("PageTitle", out var group)) { - DocumentPageTitle = Regex.Replace(group.Value, "<.*?>", string.Empty); + DocumentPageTitle = Regex.Replace(group.Value, "<.*?>", string.Empty).Trim(); } }