Merge pull request #3488 from abpframework/akin/added-meta-description-for-docs

added description method and description tag
pull/3509/head
Alper Ebicoglu 6 years ago committed by GitHub
commit e6a45b6133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,7 +39,10 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>@pageTitle</title>
@if (ViewBag.Description!=null)
{
<meta name="description" content="@ViewBag.Description" />
}
<abp-style-bundle name="@BasicThemeBundles.Styles.Global" />
@await Component.InvokeAsync(typeof(WidgetStylesViewComponent))

@ -19,6 +19,7 @@
ViewBag.FluidLayout = true;
Layout = ThemeManager.CurrentTheme.GetEmptyLayout();
PageLayout.Content.Title = Model.DocumentName?.Replace("-", " ");
ViewBag.Description = Model.GetDescription();
}
@section styles {
<abp-style-bundle name="@typeof(IndexModel).FullName">

@ -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,9 +66,10 @@ namespace Volo.Docs.Pages.Documents.Project
public DocumentParametersDto DocumentPreferences { get; set; }
public DocumentRenderParameters UserPreferences { get; set; } = new DocumentRenderParameters();
public bool FullSearchEnabled { get; set; }
private const int MaxDescriptionMetaTagLength = 200;
private readonly IDocumentAppService _documentAppService;
private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory;
private readonly IProjectAppService _projectAppService;
@ -591,5 +594,22 @@ namespace Volo.Docs.Pages.Documents.Project
}
}
}
public string GetDescription()
{
var firstParagraph = new Regex(@"<p>(.*?)</p>");
var match = firstParagraph.Match(Document.Content);
if (!match.Success)
{
return null;
}
var description = HttpUtility.HtmlDecode(match.Value);
var htmlTagReplacer = new Regex(@"<[^>]*>", RegexOptions.IgnoreCase);
description = htmlTagReplacer.Replace(description, m => string.Empty);
return description.Truncate(MaxDescriptionMetaTagLength);
}
}
}

Loading…
Cancel
Save