From ee01645a39d7f4ee92e57d6f4329cd9633a65c19 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Sun, 23 Mar 2025 11:08:55 +0100 Subject: [PATCH 1/2] SEO optimized title --- src/Elastic.Markdown/Slices/Index.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/Slices/Index.cshtml b/src/Elastic.Markdown/Slices/Index.cshtml index 3ad9d007c..dc8f87173 100644 --- a/src/Elastic.Markdown/Slices/Index.cshtml +++ b/src/Elastic.Markdown/Slices/Index.cshtml @@ -5,7 +5,7 @@ public LayoutViewModel LayoutModel => new() { DocSetName = Model.DocSetName, - Title = $"Elastic Documentation: {Model.Title}", + Title = Model.CurrentDocument.Url.AsSpan().TrimStart(Model.UrlPathPrefix) is "/" ? Model.Title : $"{Model.Title} | Elastic documentation", Description = Model.Description, PageTocItems = Model.PageTocItems.Where(i => i is { Level: 2 or 3 }).ToList(), CurrentDocument = Model.CurrentDocument, From de571141484dbf81eb0a71696d9492b3e06b1df1 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 24 Mar 2025 09:16:51 +0100 Subject: [PATCH 2/2] Use title of root index.md as site name --- src/Elastic.Markdown/Slices/HtmlWriter.cs | 3 +++ src/Elastic.Markdown/Slices/Index.cshtml | 2 +- src/Elastic.Markdown/Slices/_ViewModels.cs | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/Slices/HtmlWriter.cs b/src/Elastic.Markdown/Slices/HtmlWriter.cs index 7f964bdc8..9c2f9b428 100644 --- a/src/Elastic.Markdown/Slices/HtmlWriter.cs +++ b/src/Elastic.Markdown/Slices/HtmlWriter.cs @@ -98,8 +98,11 @@ private async Task RenderLayout(MarkdownFile markdown, MarkdownDocument editUrl = $"https://github.com/elastic/{remote}/edit/{branch}/{path}"; } + var siteName = DocumentationSet.Tree.Index?.Title ?? "Elastic Documentation"; + var slice = Index.Create(new IndexViewModel { + SiteName = siteName, DocSetName = DocumentationSet.Name, Title = markdown.Title ?? "[TITLE NOT SET]", Description = markdown.YamlFrontMatter?.Description ?? descriptionGenerator.GenerateDescription(document), diff --git a/src/Elastic.Markdown/Slices/Index.cshtml b/src/Elastic.Markdown/Slices/Index.cshtml index dc8f87173..a08e29f5f 100644 --- a/src/Elastic.Markdown/Slices/Index.cshtml +++ b/src/Elastic.Markdown/Slices/Index.cshtml @@ -5,7 +5,7 @@ public LayoutViewModel LayoutModel => new() { DocSetName = Model.DocSetName, - Title = Model.CurrentDocument.Url.AsSpan().TrimStart(Model.UrlPathPrefix) is "/" ? Model.Title : $"{Model.Title} | Elastic documentation", + Title = Model.CurrentDocument.Parent == null ? Model.Title : $"{Model.Title} | {Model.SiteName}", Description = Model.Description, PageTocItems = Model.PageTocItems.Where(i => i is { Level: 2 or 3 }).ToList(), CurrentDocument = Model.CurrentDocument, diff --git a/src/Elastic.Markdown/Slices/_ViewModels.cs b/src/Elastic.Markdown/Slices/_ViewModels.cs index 92ac5b5c7..a05cf9470 100644 --- a/src/Elastic.Markdown/Slices/_ViewModels.cs +++ b/src/Elastic.Markdown/Slices/_ViewModels.cs @@ -10,6 +10,7 @@ namespace Elastic.Markdown.Slices; public class IndexViewModel { + public required string SiteName { get; init; } public required string DocSetName { get; init; } public required string Title { get; init; } public required string Description { get; init; }