Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a "Report an issue" link on documentation pages. #817

Merged
merged 12 commits into from
Mar 25, 2025
12 changes: 10 additions & 2 deletions src/Elastic.Markdown/Assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@
inline-flex
justify-center
items-center;


.link-icon {
@apply
shrink-0
size-4
ml-0
mr-1
}

.link-arrow {
@apply
shrink-0
Expand All @@ -104,7 +112,7 @@
}

&:hover{
svg {
svg:not(.link-icon) {
@apply translate-x-2;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/Elastic.Markdown/Slices/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
editUrl = $"https://github.com/elastic/{remote}/edit/{branch}/{path}";
}

Uri? reportLinkParameter = null;
if (DocumentationSet.Build.CanonicalBaseUrl is not null)
reportLinkParameter = new Uri(DocumentationSet.Build.CanonicalBaseUrl, Path.Combine(DocumentationSet.Build.UrlPathPrefix ?? string.Empty, markdown.Url));
var reportUrl = $"https://github.com/elastic/docs-content/issues/new?template=issue-report.yaml&link={reportLinkParameter}&labels=source:web";

var siteName = DocumentationSet.Tree.Index?.Title ?? "Elastic Documentation";

var slice = Index.Create(new IndexViewModel
Expand All @@ -122,7 +127,8 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
CanonicalBaseUrl = DocumentationSet.Build.CanonicalBaseUrl,
EnableGoogleTagManager = DocumentationSet.Build.EnableGoogleTagManager,
Features = DocumentationSet.Configuration.Features,
StaticFileContentHashProvider = StaticFileContentHashProvider
StaticFileContentHashProvider = StaticFileContentHashProvider,
ReportIssueUrl = reportUrl
});
return await slice.RenderAsync(cancellationToken: ctx);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Elastic.Markdown/Slices/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
CanonicalBaseUrl = Model.CanonicalBaseUrl,
EnableGoogleTagManager = Model.EnableGoogleTagManager,
Features = Model.Features,
StaticFileContentHashProvider = Model.StaticFileContentHashProvider
StaticFileContentHashProvider = Model.StaticFileContentHashProvider,
ReportIssueUrl = Model.ReportIssueUrl
};
}
<section id="elastic-docs-v3">
Expand Down
18 changes: 14 additions & 4 deletions src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@
@if (Model.GithubEditUrl is not null)
{
<div class="edit-this-page">
<a href="@Model.GithubEditUrl" class="link">
<a href="@Model.GithubEditUrl" class="link" target="_blank">
<svg class="link-icon"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" stroke-width="1" stroke="currentColor">
<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" />
<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" />
</svg>
Edit this page
<svg class="link-arrow"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M17.25 8.25 21 12m0 0-3.75 3.75M21 12H3"/>
</a>
</div>
<div class="report-an-issue">
<a href="@Model.ReportIssueUrl" class="link" target="_blank">
<svg class="link-icon"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" stroke="currentColor">
<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" />
</svg>
Report an issue
</a>
</div>
}
Expand Down
2 changes: 2 additions & 0 deletions src/Elastic.Markdown/Slices/_ViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class IndexViewModel
public required string NavigationHtml { get; init; }
public required string? UrlPathPrefix { get; init; }
public required string? GithubEditUrl { get; init; }
public required string? ReportIssueUrl { get; init; }
public required ApplicableTo? Applies { get; init; }
public required bool AllowIndexing { get; init; }
public required Uri? CanonicalBaseUrl { get; init; }
Expand All @@ -50,6 +51,7 @@ public class LayoutViewModel
public required string NavigationHtml { get; init; }
public required string? UrlPathPrefix { get; init; }
public required string? GithubEditUrl { get; init; }
public required string? ReportIssueUrl { get; init; }
public required bool AllowIndexing { get; init; }
public required Uri? CanonicalBaseUrl { get; init; }
public required bool EnableGoogleTagManager { get; init; }
Expand Down
4 changes: 3 additions & 1 deletion src/docs-builder/Cli/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public async Task<int> Generate(

Uri? canonicalBaseUri = null;

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

try
Expand Down
10 changes: 8 additions & 2 deletions src/docs-builder/Http/DocumentationWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ public DocumentationWebHost(string? path, int port, ILoggerFactory logger, IFile
.AddFilter("Microsoft.Hosting.Lifetime", LogLevel.Information);

var collector = new LiveModeDiagnosticsCollector(logger);
_context = new BuildContext(collector, fileSystem, fileSystem, path, null);

var hostUrl = $"http://localhost:{port}";

_context = new BuildContext(collector, fileSystem, fileSystem, path, null)
{
CanonicalBaseUrl = new Uri(hostUrl),
};
_ = builder.Services
.AddAotLiveReload(s =>
{
Expand All @@ -51,7 +57,7 @@ public DocumentationWebHost(string? path, int port, ILoggerFactory logger, IFile
if (IsDotNetWatchBuild())
_ = builder.Services.AddHostedService<ParcelWatchService>();

_ = builder.WebHost.UseUrls($"http://localhost:{port}");
_ = builder.WebHost.UseUrls(hostUrl);

_webApplication = builder.Build();
SetUpRoutes();
Expand Down
Loading