Skip to content

Commit 2d12246

Browse files
authored
Introduce a "Report an issue" link on documentation pages. (#817)
* Introduce a "Report an issue" link on documentation pages * Add source:web label to the issue report shortcut * Infer current page being reported via Razor Model * Provide default value for CanonicalBaseUrl * Remove link arrows on TableOfContents
1 parent 02e77c3 commit 2d12246

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

src/Elastic.Markdown/Assets/styles.css

+10-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@
9393
inline-flex
9494
justify-center
9595
items-center;
96-
96+
97+
.link-icon {
98+
@apply
99+
shrink-0
100+
size-4
101+
ml-0
102+
mr-1
103+
}
104+
97105
.link-arrow {
98106
@apply
99107
shrink-0
@@ -104,7 +112,7 @@
104112
}
105113

106114
&:hover{
107-
svg {
115+
svg:not(.link-icon) {
108116
@apply translate-x-2;
109117
}
110118
}

src/Elastic.Markdown/Slices/HtmlWriter.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
9999
editUrl = $"https://github.com/elastic/{remote}/edit/{branch}/{path}";
100100
}
101101

102+
Uri? reportLinkParameter = null;
103+
if (DocumentationSet.Build.CanonicalBaseUrl is not null)
104+
reportLinkParameter = new Uri(DocumentationSet.Build.CanonicalBaseUrl, Path.Combine(DocumentationSet.Build.UrlPathPrefix ?? string.Empty, markdown.Url));
105+
var reportUrl = $"https://github.com/elastic/docs-content/issues/new?template=issue-report.yaml&link={reportLinkParameter}&labels=source:web";
106+
102107
var siteName = DocumentationSet.Tree.Index?.Title ?? "Elastic Documentation";
103108

104109
var slice = Index.Create(new IndexViewModel
@@ -122,7 +127,8 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
122127
CanonicalBaseUrl = DocumentationSet.Build.CanonicalBaseUrl,
123128
EnableGoogleTagManager = DocumentationSet.Build.EnableGoogleTagManager,
124129
Features = DocumentationSet.Configuration.Features,
125-
StaticFileContentHashProvider = StaticFileContentHashProvider
130+
StaticFileContentHashProvider = StaticFileContentHashProvider,
131+
ReportIssueUrl = reportUrl
126132
});
127133
return await slice.RenderAsync(cancellationToken: ctx);
128134
}

src/Elastic.Markdown/Slices/Index.cshtml

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
CanonicalBaseUrl = Model.CanonicalBaseUrl,
1919
EnableGoogleTagManager = Model.EnableGoogleTagManager,
2020
Features = Model.Features,
21-
StaticFileContentHashProvider = Model.StaticFileContentHashProvider
21+
StaticFileContentHashProvider = Model.StaticFileContentHashProvider,
22+
ReportIssueUrl = Model.ReportIssueUrl
2223
};
2324
}
2425
<section id="elastic-docs-v3">

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,22 @@
2626
@if (Model.GithubEditUrl is not null)
2727
{
2828
<div class="edit-this-page">
29-
<a href="@Model.GithubEditUrl" class="link">
29+
<a href="@Model.GithubEditUrl" class="link" target="_blank">
30+
<svg class="link-icon"
31+
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" stroke-width="1" stroke="currentColor">
32+
<path d="M13.488 2.513a1.75 1.75 0 0 0-2.475 0L6.75 6.774a2.75 2.75 0 0 0-.596.892l-.848 2.047a.75.75 0 0 0 .98.98l2.047-.848a2.75 2.75 0 0 0 .892-.596l4.261-4.262a1.75 1.75 0 0 0 0-2.474Z" />
33+
<path d="M4.75 3.5c-.69 0-1.25.56-1.25 1.25v6.5c0 .69.56 1.25 1.25 1.25h6.5c.69 0 1.25-.56 1.25-1.25V9A.75.75 0 0 1 14 9v2.25A2.75 2.75 0 0 1 11.25 14h-6.5A2.75 2.75 0 0 1 2 11.25v-6.5A2.75 2.75 0 0 1 4.75 2H7a.75.75 0 0 1 0 1.5H4.75Z" />
34+
</svg>
3035
Edit this page
31-
<svg class="link-arrow"
32-
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
33-
<path stroke-linecap="round" stroke-linejoin="round" d="M17.25 8.25 21 12m0 0-3.75 3.75M21 12H3"/>
36+
</a>
37+
</div>
38+
<div class="report-an-issue">
39+
<a href="@Model.ReportIssueUrl" class="link" target="_blank">
40+
<svg class="link-icon"
41+
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" stroke="currentColor">
42+
<path fill-rule="evenodd" d="M1 8.74c0 .983.713 1.825 1.69 1.943.904.108 1.817.19 2.737.243.363.02.688.231.85.556l1.052 2.103a.75.75 0 0 0 1.342 0l1.052-2.103c.162-.325.487-.535.85-.556.92-.053 1.833-.134 2.738-.243.976-.118 1.689-.96 1.689-1.942V4.259c0-.982-.713-1.824-1.69-1.942a44.45 44.45 0 0 0-10.62 0C1.712 2.435 1 3.277 1 4.26v4.482Zm3-3.49a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 0 1.5h-6.5A.75.75 0 0 1 4 5.25ZM4.75 7a.75.75 0 0 0 0 1.5h2.5a.75.75 0 0 0 0-1.5h-2.5Z" clip-rule="evenodd" />
3443
</svg>
44+
Report an issue
3545
</a>
3646
</div>
3747
}

src/Elastic.Markdown/Slices/_ViewModels.cs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class IndexViewModel
2525
public required string NavigationHtml { get; init; }
2626
public required string? UrlPathPrefix { get; init; }
2727
public required string? GithubEditUrl { get; init; }
28+
public required string? ReportIssueUrl { get; init; }
2829
public required ApplicableTo? Applies { get; init; }
2930
public required bool AllowIndexing { get; init; }
3031
public required Uri? CanonicalBaseUrl { get; init; }
@@ -50,6 +51,7 @@ public class LayoutViewModel
5051
public required string NavigationHtml { get; init; }
5152
public required string? UrlPathPrefix { get; init; }
5253
public required string? GithubEditUrl { get; init; }
54+
public required string? ReportIssueUrl { get; init; }
5355
public required bool AllowIndexing { get; init; }
5456
public required Uri? CanonicalBaseUrl { get; init; }
5557
public required bool EnableGoogleTagManager { get; init; }

src/docs-builder/Cli/Commands.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public async Task<int> Generate(
104104

105105
Uri? canonicalBaseUri = null;
106106

107-
if (canonicalBaseUrl != null && !Uri.TryCreate(canonicalBaseUrl, UriKind.Absolute, out canonicalBaseUri))
107+
if (canonicalBaseUrl is null)
108+
canonicalBaseUri = new Uri("https://docs-v3-preview.elastic.dev");
109+
else if (!Uri.TryCreate(canonicalBaseUrl, UriKind.Absolute, out canonicalBaseUri))
108110
throw new ArgumentException($"The canonical base url '{canonicalBaseUrl}' is not a valid absolute uri");
109111

110112
try

src/docs-builder/Http/DocumentationWebHost.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ public DocumentationWebHost(string? path, int port, ILoggerFactory logger, IFile
3636
.AddFilter("Microsoft.Hosting.Lifetime", LogLevel.Information);
3737

3838
var collector = new LiveModeDiagnosticsCollector(logger);
39-
_context = new BuildContext(collector, fileSystem, fileSystem, path, null);
39+
40+
var hostUrl = $"http://localhost:{port}";
41+
42+
_context = new BuildContext(collector, fileSystem, fileSystem, path, null)
43+
{
44+
CanonicalBaseUrl = new Uri(hostUrl),
45+
};
4046
_ = builder.Services
4147
.AddAotLiveReload(s =>
4248
{
@@ -51,7 +57,7 @@ public DocumentationWebHost(string? path, int port, ILoggerFactory logger, IFile
5157
if (IsDotNetWatchBuild())
5258
_ = builder.Services.AddHostedService<ParcelWatchService>();
5359

54-
_ = builder.WebHost.UseUrls($"http://localhost:{port}");
60+
_ = builder.WebHost.UseUrls(hostUrl);
5561

5662
_webApplication = builder.Build();
5763
SetUpRoutes();

0 commit comments

Comments
 (0)