Skip to content

Commit

Permalink
Allow pages to override their navigational header (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Nov 13, 2024
1 parent f86d89e commit a488085
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/source/elastic/semantic-search/amazon-bedrock.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "Semantic search with the inference API"
navigation_title: "Amazon Bedrock"
---

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).
Expand Down
1 change: 1 addition & 0 deletions docs/source/elastic/semantic-search/azure-ai-studio.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "Semantic search with the inference API"
navigation_title: "Azure AI Studio"
---

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).
Expand Down
1 change: 1 addition & 0 deletions docs/source/elastic/semantic-search/azure-openai.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "Semantic search with the inference API"
navigation_title: "Azure OpenAI"
---

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).
Expand Down
1 change: 1 addition & 0 deletions docs/source/elastic/semantic-search/cohere.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "Semantic search with the inference API"
navigation_title: "Cohere"
---

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).
Expand Down
1 change: 1 addition & 0 deletions docs/source/elastic/semantic-search/elser.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "Semantic search with the inference API"
navigation_title: "ELSER"
---

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).
Expand Down
9 changes: 5 additions & 4 deletions src/Elastic.Markdown/IO/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Elastic.Markdown.IO;
public class MarkdownFile : DocumentationFile
{
private readonly SlugHelper _slugHelper = new();
private string? _tocTitle;
private string? _navigationTitle;

public MarkdownFile(IFileInfo sourceFile, IDirectoryInfo rootPath, MarkdownParser parser, BuildContext context)
: base(sourceFile, rootPath)
Expand All @@ -32,10 +32,10 @@ public MarkdownFile(IFileInfo sourceFile, IDirectoryInfo rootPath, MarkdownParse
private FrontMatterParser FrontMatterParser { get; } = new();
public YamlFrontMatter? YamlFrontMatter { get; private set; }
public string? Title { get; private set; }
public string? TocTitle
public string? NavigationTitle
{
get => !string.IsNullOrEmpty(_tocTitle) ? _tocTitle : Title;
set => _tocTitle = value;
get => !string.IsNullOrEmpty(_navigationTitle) ? _navigationTitle : Title;
private set => _navigationTitle = value;
}

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

var contents = document
Expand Down
6 changes: 5 additions & 1 deletion src/Elastic.Markdown/Myst/FrontMatterParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public partial class YamlFrontMatterStaticContext;
[YamlSerializable]
public class YamlFrontMatter
{
[YamlMember(Alias = "title")]
public string? Title { get; set; }

[YamlMember(Alias = "navigation_title")]
public string? NavigationTitle { get; set; }

[YamlMember(Alias = "sub")]
public Dictionary<string, string>? Properties { get; set; }
}
Expand All @@ -25,7 +30,6 @@ public YamlFrontMatter Deserialize(string yaml)

var deserializer = new StaticDeserializerBuilder(new YamlFrontMatterStaticContext())
.IgnoreUnmatchedProperties()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();

var frontMatter = deserializer.Deserialize<YamlFrontMatter>(input);
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Markdown/Slices/Layout/_TocTreeNav.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
@foreach (var file in Model.SubTree.FilesInOrder)
{
var current = file == Model.CurrentDocument ? " current" : string.Empty;
<li class="toctree-l@(Model.SubTree.Level + 1)@current"><a class="@(current.Trim()) reference internal" href="@file.Url">@file.TocTitle</a></li>
<li class="toctree-l@(Model.SubTree.Level + 1)@current"><a class="@(current.Trim()) reference internal" href="@file.Url">@file.NavigationTitle</a></li>
}
@foreach (var g in Model.SubTree.GroupsInOrder)
{
var current = g.HoldsCurrent(Model.CurrentDocument) ? " current" : string.Empty;
var currentFile = g.Index == Model.CurrentDocument ? " current" : string.Empty;
<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
<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
{
Level = g.Level,
CurrentDocument = Model.CurrentDocument,
Expand Down
17 changes: 16 additions & 1 deletion tests/Elastic.Markdown.Tests/Directives/YamlFrontMatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@ public class YamlFrontMatterTests(ITestOutputHelper output) : DirectiveTest(outp
"""
---
title: Elastic Docs v3
navigation_title: "Documentation Guide"
sub:
key: "value"
---
"""
)
{
[Fact]
public void Test1() => File.Title.Should().Be("Elastic Docs v3");
public void ReadsTitle() => File.Title.Should().Be("Elastic Docs v3");

[Fact]
public void ReadsNavigationTitle() => File.NavigationTitle.Should().Be("Documentation Guide");

[Fact]
public void ReadsSubstitutions()
{
File.YamlFrontMatter.Should().NotBeNull();
File.YamlFrontMatter!.Properties.Should().NotBeEmpty()
.And.HaveCount(1)
.And.ContainKey("key");
}
}

0 comments on commit a488085

Please sign in to comment.