diff --git a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/Rendering/ScribanDocumentSectionRenderer.cs b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/Rendering/ScribanDocumentSectionRenderer.cs index 53a8aea6fc..b52e0d2b46 100644 --- a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/Rendering/ScribanDocumentSectionRenderer.cs +++ b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/Rendering/ScribanDocumentSectionRenderer.cs @@ -22,6 +22,7 @@ public class ScribanDocumentSectionRenderer : IDocumentSectionRenderer protected const string DocsParam = "//[doc-params]"; protected const string DocsTemplates = "//[doc-template]"; protected const string DocsNav = "//[doc-nav]"; + protected const string DocsSeo = "//[doc-seo]"; public ILogger Logger { get; set; } @@ -49,7 +50,7 @@ public class ScribanDocumentSectionRenderer : IDocumentSectionRenderer var result = await scribanTemplate.RenderAsync(parameters); - return RemoveOptionsJson(result, DocsParam, DocsNav); + return RemoveOptionsJson(result, DocsParam, DocsNav, DocsSeo); } public Task>> GetAvailableParametersAsync(string document) diff --git a/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSeoDto.cs b/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSeoDto.cs new file mode 100644 index 0000000000..e1848c1cfc --- /dev/null +++ b/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSeoDto.cs @@ -0,0 +1,6 @@ +namespace Volo.Docs.HtmlConverting; + +public class DocumentSeoDto +{ + public string Description { get; set; } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Web/HtmlConverting/IWebDocumentSectionRenderer.cs b/modules/docs/src/Volo.Docs.Web/HtmlConverting/IWebDocumentSectionRenderer.cs index b485c7b132..acc2974c9d 100644 --- a/modules/docs/src/Volo.Docs.Web/HtmlConverting/IWebDocumentSectionRenderer.cs +++ b/modules/docs/src/Volo.Docs.Web/HtmlConverting/IWebDocumentSectionRenderer.cs @@ -10,5 +10,7 @@ namespace Volo.Docs.HtmlConverting Task> GetPartialTemplatesInDocumentAsync(string documentContent); Task GetDocumentNavigationsAsync(string documentContent); + + Task GetDocumentSeoAsync(string documentContent); } } diff --git a/modules/docs/src/Volo.Docs.Web/HtmlConverting/ScribanWebDocumentSectionRenderer.cs b/modules/docs/src/Volo.Docs.Web/HtmlConverting/ScribanWebDocumentSectionRenderer.cs index 48379765ec..ae76924d2a 100644 --- a/modules/docs/src/Volo.Docs.Web/HtmlConverting/ScribanWebDocumentSectionRenderer.cs +++ b/modules/docs/src/Volo.Docs.Web/HtmlConverting/ScribanWebDocumentSectionRenderer.cs @@ -11,6 +11,11 @@ namespace Volo.Docs.HtmlConverting return GetSectionAsync(documentContent, DocsNav); } + public Task GetDocumentSeoAsync(string documentContent) + { + return GetSectionAsync(documentContent, DocsSeo); + } + public async Task> GetPartialTemplatesInDocumentAsync( string documentContent) { 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 319d5f1b63..35e3c05f15 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 @@ -99,6 +99,8 @@ namespace Volo.Docs.Pages.Documents.Project public bool HasDownloadPdf { get; set; } public DocumentNavigationsDto DocumentNavigationsDto { get; private set; } + + public DocumentSeoDto DocumentSeoDto { get; private set; } private const int MaxDescriptionMetaTagLength = 200; private const int TocLevelCount = 2; @@ -542,7 +544,7 @@ namespace Volo.Docs.Pages.Documents.Project DocumentNameWithExtension = Document.Name; SetDocumentPageTitle(); - await ConvertDocumentContentToHtmlAsync(); + await ConvertDocumentContentToHtmlAsync(); return true; } @@ -587,6 +589,7 @@ namespace Volo.Docs.Pages.Documents.Project var partialTemplates = await GetDocumentPartialTemplatesAsync(); DocumentNavigationsDto = await _webDocumentSectionRenderer.GetDocumentNavigationsAsync(Document.Content); + DocumentSeoDto = await _webDocumentSectionRenderer.GetDocumentSeoAsync(Document.Content); try { @@ -600,11 +603,12 @@ namespace Volo.Docs.Pages.Documents.Project else { DocumentNavigationsDto = new DocumentNavigationsDto(); - } - - if (Document != null && !Document.Content.IsNullOrEmpty()) - { - TocItems = _tocGeneratorService.GenerateTocItems(Document.Content, TocLevelCount); + DocumentSeoDto = new DocumentSeoDto(); + } + + if (Document != null && !Document.Content.IsNullOrEmpty()) + { + TocItems = _tocGeneratorService.GenerateTocItems(Document.Content, TocLevelCount); } var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? Project.Format); @@ -888,6 +892,11 @@ namespace Volo.Docs.Pages.Documents.Project return null; } + if (DocumentSeoDto?.Description.IsNullOrWhiteSpace() == false) + { + return DocumentSeoDto.Description; + } + var firstParagraph = new Regex(@"

(.*?)

", RegexOptions.IgnoreCase); var match = firstParagraph.Match(Document.Content); if (!match.Success) diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js index 0bddcf844c..eaa57a31d8 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js @@ -63,10 +63,13 @@ var $myNav = $('#docs-sticky-index'); - $('body').scrollspy({ - target: $myNav, - offset:100 - }); + try { + $('body').scrollspy({ + target: $myNav, + offset:100 + }); + } catch { + } $('#docs-sticky-index a').on('click', function (event) { if (this.hash !== '') {