From e25b844aca39345d275984255d0d14676870b978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ak=C4=B1n=20Sabri=20=C3=87am?= Date: Mon, 6 Apr 2020 16:46:14 +0300 Subject: [PATCH 1/2] added description method and description tag --- .../Themes/Basic/Layouts/Empty.cshtml | 5 ++++- .../Pages/Documents/Project/Index.cshtml | 1 + .../Pages/Documents/Project/Index.cshtml.cs | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml index 1fe4639d25..0f0fd43fa0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml @@ -39,7 +39,10 @@ @pageTitle - + @if (ViewBag.Description!=null) + { + + } @await Component.InvokeAsync(typeof(WidgetStylesViewComponent)) 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 6fcf402d70..b7db40f1fe 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 @@ -19,6 +19,7 @@ ViewBag.FluidLayout = true; Layout = ThemeManager.CurrentTheme.GetEmptyLayout(); PageLayout.Content.Title = Model.DocumentName?.Replace("-", " "); + ViewBag.Description = Model.GetDescription(); } @section styles { 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 b5bfbf0a8c..44bdb3e632 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 @@ -2,7 +2,9 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; +using System.Web; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Extensions.Logging; @@ -64,7 +66,7 @@ namespace Volo.Docs.Pages.Documents.Project public DocumentParametersDto DocumentPreferences { get; set; } public DocumentRenderParameters UserPreferences { get; set; } = new DocumentRenderParameters(); - + public bool FullSearchEnabled { get; set; } private readonly IDocumentAppService _documentAppService; @@ -591,5 +593,17 @@ namespace Volo.Docs.Pages.Documents.Project } } } + + public string GetDescription() + { + var startIndex = Document.Content.IndexOf("

", StringComparison.Ordinal); + var lastIndex = Document.Content.IndexOf("

", StringComparison.Ordinal); + var description = Document.Content.Substring(startIndex,lastIndex); + + Regex rx = new Regex("<[^>]*>"); + description = rx.Replace(description, ""); + + return description.Truncate(200); + } } } From d6a0caf16fff462d8bc4678c42eb299dae88e272 Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Tue, 7 Apr 2020 11:45:50 +0300 Subject: [PATCH 2/2] Refactor getting description field --- .../Pages/Documents/Project/Index.cshtml.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 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 44bdb3e632..b3eceffdef 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 @@ -69,6 +69,7 @@ namespace Volo.Docs.Pages.Documents.Project public bool FullSearchEnabled { get; set; } + private const int MaxDescriptionMetaTagLength = 200; private readonly IDocumentAppService _documentAppService; private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory; private readonly IProjectAppService _projectAppService; @@ -596,14 +597,19 @@ namespace Volo.Docs.Pages.Documents.Project public string GetDescription() { - var startIndex = Document.Content.IndexOf("

", StringComparison.Ordinal); - var lastIndex = Document.Content.IndexOf("

", StringComparison.Ordinal); - var description = Document.Content.Substring(startIndex,lastIndex); + var firstParagraph = new Regex(@"

(.*?)

"); + var match = firstParagraph.Match(Document.Content); + if (!match.Success) + { + return null; + } + + var description = HttpUtility.HtmlDecode(match.Value); - Regex rx = new Regex("<[^>]*>"); - description = rx.Replace(description, ""); + var htmlTagReplacer = new Regex(@"<[^>]*>", RegexOptions.IgnoreCase); + description = htmlTagReplacer.Replace(description, m => string.Empty); - return description.Truncate(200); + return description.Truncate(MaxDescriptionMetaTagLength); } } }