Skip to content

Commit ad363e3

Browse files
authored
Add "View as markdown" link (#1686)
* Add "View as markdown" button * Add `link rel="alternative"`
1 parent 259723a commit ad363e3

File tree

5 files changed

+14
-0
lines changed

5 files changed

+14
-0
lines changed

src/Elastic.Markdown/HtmlWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
138138
UrlPathPrefix = markdown.UrlPathPrefix,
139139
AppliesTo = markdown.YamlFrontMatter?.AppliesTo,
140140
GithubEditUrl = editUrl,
141+
MarkdownUrl = markdown.Url.TrimEnd('/') + ".md",
141142
AllowIndexing = DocumentationSet.Context.AllowIndexing && (markdown.CrossLink.Equals("docs-content://index.md", StringComparison.OrdinalIgnoreCase) || markdown is DetectionRuleFile || !current.Hidden),
142143
CanonicalBaseUrl = DocumentationSet.Context.CanonicalBaseUrl,
143144
GoogleTagManager = DocumentationSet.Context.GoogleTagManager,

src/Elastic.Markdown/Layout/_TableOfContents.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
</version-dropdown>
88
</div>
99
<ul class="mt-6 hidden md:flex items-center lg:block gap-4">
10+
<li class="view-as-markdown lg:not-first:mt-1">
11+
<a href="@Model.MarkdownUrl" class="link text-sm" target="_blank">
12+
<svg class="link-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 -1 24 24">
13+
<path fill="currentColor" d="M22.131725 19.247H1.9386225C1.0239525 19.247 0.25 18.47305 0.25 17.558375v-11.11675c0 -0.914675 0.7739525 -1.688625 1.6886225 -1.688625H22.061375c0.914675 0 1.688625 0.77395 1.688625 1.688625v11.11675c0 0.914675 -0.7036 1.688625 -1.618275 1.688625ZM1.9386225 5.87875c-0.2814375 0 -0.562875 0.281425 -0.562875 0.562875v11.11675c0 0.3518 0.2814375 0.562875 0.562875 0.562875H22.061375c0.3518 0 0.562875 -0.281425 0.562875 -0.562875v-11.11675c0 -0.3518 -0.281425 -0.562875 -0.562875 -0.562875l-20.1227525 0ZM3.62725 15.86975V8.130225h2.2515l2.2515 2.814375 2.251475 -2.814375h2.2515V15.86975h-2.2515V11.437125L8.13025 14.2515l-2.2515 -2.814375V15.86975h-2.2515Zm14.1422 0L14.392225 12.140725h2.251475v-4.0105h2.2515v3.940125h2.2515L17.76945 15.86975Z" stroke-width="0.25"></path>
14+
</svg>
15+
View as markdown
16+
</a>
17+
</li>
1018
@if (!string.IsNullOrEmpty(Model.GithubEditUrl))
1119
{
1220
<li class="edit-this-page lg:not-first:mt-1 @(Model.HideEditThisPage ? "hidden" : string.Empty)">

src/Elastic.Markdown/MarkdownLayoutViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public record MarkdownLayoutViewModel : GlobalLayoutViewModel
1212
{
1313
public required string? GithubEditUrl { get; init; }
1414

15+
public required string MarkdownUrl { get; init; }
16+
1517
public required bool HideEditThisPage { get; init; }
1618
public required string? ReportIssueUrl { get; init; }
1719

src/Elastic.Markdown/Page/Index.cshtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
NavigationFileName = Model.NavigationFileName,
3030
UrlPathPrefix = Model.UrlPathPrefix,
3131
GithubEditUrl = Model.GithubEditUrl,
32+
MarkdownUrl = Model.MarkdownUrl,
3233
HideEditThisPage = Model.Features.DisableGitHubEditLink && Model.IsAssemblerBuild,
3334
AllowIndexing = Model.AllowIndexing,
3435
CanonicalBaseUrl = Model.CanonicalBaseUrl,
@@ -48,6 +49,7 @@
4849
{
4950
<meta class="elastic" name="product_version" content="@(new HtmlString(Model.CurrentVersion))"/>
5051
<meta name="DC.identifier" content="@(new HtmlString(Model.CurrentVersion))"/>
52+
<link rel="alternate" type="text/markdown" href="@(Model.MarkdownUrl)" title="Markdown export"/>
5153
}
5254
if (name == GlobalSections.Head && Model.Products is { Count: > 0 })
5355
{

src/Elastic.Markdown/Page/IndexViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class IndexViewModel
4343
public required VersionDrownDownItemViewModel[]? VersionDropdownItems { get; init; }
4444
public required string? UrlPathPrefix { get; init; }
4545
public required string? GithubEditUrl { get; init; }
46+
public required string MarkdownUrl { get; init; }
4647
public required string? ReportIssueUrl { get; init; }
4748
public required ApplicableTo? AppliesTo { get; init; }
4849
public required bool AllowIndexing { get; init; }

0 commit comments

Comments
 (0)