Skip to content

Commit 1fe5bd6

Browse files
committed
Allow pages to override their navigational header
1 parent f86d89e commit 1fe5bd6

File tree

9 files changed

+33
-8
lines changed

9 files changed

+33
-8
lines changed

docs/source/elastic/semantic-search/amazon-bedrock.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: "Semantic search with the inference API"
3+
navigation_title: "Amazon Bedrock"
34
---
45

56
Semantic search helps you find data based on the intent and contextual meaning of a search query, instead of a match on query terms (lexical search).

docs/source/elastic/semantic-search/azure-ai-studio.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: "Semantic search with the inference API"
3+
navigation_title: "Azure AI Studio"
34
---
45

56
Semantic search helps you find data based on the intent and contextual meaning of a search query, instead of a match on query terms (lexical search).

docs/source/elastic/semantic-search/azure-openai.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: "Semantic search with the inference API"
3+
navigation_title: "Azure OpenAI"
34
---
45

56
Semantic search helps you find data based on the intent and contextual meaning of a search query, instead of a match on query terms (lexical search).

docs/source/elastic/semantic-search/cohere.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: "Semantic search with the inference API"
3+
navigation_title: "Cohere"
34
---
45

56
Semantic search helps you find data based on the intent and contextual meaning of a search query, instead of a match on query terms (lexical search).

docs/source/elastic/semantic-search/elser.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: "Semantic search with the inference API"
3+
navigation_title: "ELSER"
34
---
45

56
Semantic search helps you find data based on the intent and contextual meaning of a search query, instead of a match on query terms (lexical search).

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Elastic.Markdown.IO;
1616
public class MarkdownFile : DocumentationFile
1717
{
1818
private readonly SlugHelper _slugHelper = new();
19-
private string? _tocTitle;
19+
private string? _navigationTitle;
2020

2121
public MarkdownFile(IFileInfo sourceFile, IDirectoryInfo rootPath, MarkdownParser parser, BuildContext context)
2222
: base(sourceFile, rootPath)
@@ -32,10 +32,10 @@ public MarkdownFile(IFileInfo sourceFile, IDirectoryInfo rootPath, MarkdownParse
3232
private FrontMatterParser FrontMatterParser { get; } = new();
3333
public YamlFrontMatter? YamlFrontMatter { get; private set; }
3434
public string? Title { get; private set; }
35-
public string? TocTitle
35+
public string? NavigationTitle
3636
{
37-
get => !string.IsNullOrEmpty(_tocTitle) ? _tocTitle : Title;
38-
set => _tocTitle = value;
37+
get => !string.IsNullOrEmpty(_navigationTitle) ? _navigationTitle : Title;
38+
private set => _navigationTitle = value;
3939
}
4040

4141
public List<PageTocItem> TableOfContents { get; } = new();
@@ -53,6 +53,7 @@ public async Task<MarkdownDocument> ParseFullAsync(Cancel ctx)
5353
var raw = string.Join(Environment.NewLine, yaml.Lines.Lines);
5454
YamlFrontMatter = FrontMatterParser.Deserialize(raw);
5555
Title = YamlFrontMatter.Title;
56+
NavigationTitle = YamlFrontMatter.NavigationTitle;
5657
}
5758

5859
var contents = document

src/Elastic.Markdown/Myst/FrontMatterParser.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ public partial class YamlFrontMatterStaticContext;
1212
[YamlSerializable]
1313
public class YamlFrontMatter
1414
{
15+
[YamlMember(Alias = "title")]
1516
public string? Title { get; set; }
17+
18+
[YamlMember(Alias = "navigation_title")]
19+
public string? NavigationTitle { get; set; }
20+
1621
[YamlMember(Alias = "sub")]
1722
public Dictionary<string, string>? Properties { get; set; }
1823
}
@@ -25,7 +30,6 @@ public YamlFrontMatter Deserialize(string yaml)
2530

2631
var deserializer = new StaticDeserializerBuilder(new YamlFrontMatterStaticContext())
2732
.IgnoreUnmatchedProperties()
28-
.WithNamingConvention(CamelCaseNamingConvention.Instance)
2933
.Build();
3034

3135
var frontMatter = deserializer.Deserialize<YamlFrontMatter>(input);

src/Elastic.Markdown/Slices/Layout/_TocTreeNav.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
@foreach (var file in Model.SubTree.FilesInOrder)
33
{
44
var current = file == Model.CurrentDocument ? " current" : string.Empty;
5-
<li class="toctree-l@(Model.SubTree.Level + 1)@current"><a class="@(current.Trim()) reference internal" href="@file.Url">@file.TocTitle</a></li>
5+
<li class="toctree-l@(Model.SubTree.Level + 1)@current"><a class="@(current.Trim()) reference internal" href="@file.Url">@file.NavigationTitle</a></li>
66
}
77
@foreach (var g in Model.SubTree.GroupsInOrder)
88
{
99
var current = g.HoldsCurrent(Model.CurrentDocument) ? " current" : string.Empty;
1010
var currentFile = g.Index == Model.CurrentDocument ? " current" : string.Empty;
11-
<li class="toctree-l@(g.Level)@current"><a class="reference internal@(currentFile)" href="@g.Index?.Url">@g.Index?.TocTitle</a>@if (@g.FilesInOrder.Count > 0 || g.GroupsInOrder.Count > 0) {<ul class="@(current.Trim())">@await RenderPartialAsync(Elastic.Markdown.Slices.Layout._TocTreeNav.Create(new NavigationTreeItem
11+
<li class="toctree-l@(g.Level)@current"><a class="reference internal@(currentFile)" href="@g.Index?.Url">@g.Index?.NavigationTitle</a>@if (@g.FilesInOrder.Count > 0 || g.GroupsInOrder.Count > 0) {<ul class="@(current.Trim())">@await RenderPartialAsync(Elastic.Markdown.Slices.Layout._TocTreeNav.Create(new NavigationTreeItem
1212
{
1313
Level = g.Level,
1414
CurrentDocument = Model.CurrentDocument,

tests/Elastic.Markdown.Tests/Directives/YamlFrontMatterTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ public class YamlFrontMatterTests(ITestOutputHelper output) : DirectiveTest(outp
1010
"""
1111
---
1212
title: Elastic Docs v3
13+
navigation_title: "Documentation Guide"
14+
sub:
15+
key: "value"
1316
---
1417
"""
1518
)
1619
{
1720
[Fact]
18-
public void Test1() => File.Title.Should().Be("Elastic Docs v3");
21+
public void ReadsTitle() => File.Title.Should().Be("Elastic Docs v3");
22+
23+
[Fact]
24+
public void ReadsNavigationTitle() => File.NavigationTitle.Should().Be("Documentation Guide");
25+
26+
[Fact]
27+
public void ReadsSubstitutions()
28+
{
29+
File.YamlFrontMatter.Should().NotBeNull();
30+
File.YamlFrontMatter!.Properties.Should().NotBeEmpty()
31+
.And.HaveCount(1)
32+
.And.ContainKey("key");
33+
}
1934
}

0 commit comments

Comments
 (0)