mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add documentation rendering page.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||
<base href="/"/>
|
||||
<link href="bootstrap/bootstrap.min.css" rel="stylesheet"/>
|
||||
<link href="css/prism.css" rel="stylesheet"/>
|
||||
<link href="app.css" rel="stylesheet"/>
|
||||
<link href="Aaru.Server.New.styles.css" rel="stylesheet"/>
|
||||
<link href="favicon.png" rel="icon" type="image/png"/>
|
||||
@@ -15,6 +16,7 @@
|
||||
<body>
|
||||
<Routes/>
|
||||
<script src="_framework/blazor.web.js"></script>
|
||||
<script src="scripts/prism.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
19
Aaru.Server.New/Components/Pages/Documentation.razor
Normal file
19
Aaru.Server.New/Components/Pages/Documentation.razor
Normal file
@@ -0,0 +1,19 @@
|
||||
@page "/{documentCategory}/{documentName}.md"
|
||||
@page "/{documentName}.md"
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IWebHostEnvironment HostEnvironment
|
||||
@inject IConfiguration Configuration
|
||||
|
||||
<PageTitle>Aaru: Documentation</PageTitle>
|
||||
|
||||
@if(_notFound)
|
||||
{
|
||||
<h1 style="color: red; align-content: center; padding: 2rem">The requested document has not been found.</h1>
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
<article class="markdown-section">
|
||||
@((MarkupString)_documentMarkup)
|
||||
</article>
|
||||
58
Aaru.Server.New/Components/Pages/Documentation.razor.cs
Normal file
58
Aaru.Server.New/Components/Pages/Documentation.razor.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Markdig;
|
||||
using Markdig.Prism;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Aaru.Server.New.Components.Pages;
|
||||
|
||||
public partial class Documentation
|
||||
{
|
||||
readonly MarkdownPipeline _pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions()
|
||||
.UseEmojiAndSmiley()
|
||||
.UseBootstrap()
|
||||
.UsePrism()
|
||||
.Build();
|
||||
string? _documentMarkup;
|
||||
bool _notFound = true;
|
||||
[CascadingParameter]
|
||||
HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
[Parameter]
|
||||
public string? DocumentName { get; set; }
|
||||
[Parameter]
|
||||
public string? DocumentCategory { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
|
||||
HttpContext.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
|
||||
DocumentCategory ??= "";
|
||||
|
||||
if(DocumentName is null) return;
|
||||
|
||||
string sanitizedDocumentCategory = Path.GetFileName(DocumentCategory).ToLowerInvariant();
|
||||
string sanitizedDocumentName = Path.GetFileName(DocumentName).ToLowerInvariant() + ".md";
|
||||
|
||||
string? docFolder = Configuration.GetSection("DocumentationFolders").GetValue<string>("Stable");
|
||||
|
||||
if(docFolder is null) return;
|
||||
|
||||
string docPath = Path.Combine(HostEnvironment.ContentRootPath, docFolder, sanitizedDocumentCategory);
|
||||
|
||||
if(!Directory.Exists(docPath)) return;
|
||||
|
||||
string document = Path.Combine(docPath, sanitizedDocumentName);
|
||||
|
||||
if(!File.Exists(document)) return;
|
||||
|
||||
string documentText = File.ReadAllText(document);
|
||||
|
||||
_documentMarkup = Markdown.ToHtml(documentText, _pipeline);
|
||||
|
||||
_notFound = false;
|
||||
HttpContext.Response.StatusCode = StatusCodes.Status200OK;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user