Oliver Booth
e8bc50bbdf
I'd ideally like to keep the blog. subdomain the same, and while there are a few ways to achieve this it is much simpler to just dedicate a separate application for the subdomain. This change also adjusts the webhost builder extensions to default to ports 443/80, and each app now explicitly sets the port it needs.
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using Cysharp.Text;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using OliverBooth.Blog.Data;
|
|
using OliverBooth.Blog.Services;
|
|
|
|
namespace OliverBooth.Blog.Pages;
|
|
|
|
/// <summary>
|
|
/// Represents the page model for the <c>RawArticle</c> page.
|
|
/// </summary>
|
|
[Area("blog")]
|
|
public class RawArticle : PageModel
|
|
{
|
|
private readonly IBlogPostService _blogPostService;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="RawArticle" /> class.
|
|
/// </summary>
|
|
/// <param name="blogPostService">The <see cref="IBlogPostService" />.</param>
|
|
public RawArticle(IBlogPostService blogPostService)
|
|
{
|
|
_blogPostService = blogPostService;
|
|
}
|
|
|
|
public IActionResult OnGet(int year, int month, int day, string slug)
|
|
{
|
|
var date = new DateOnly(year, month, day);
|
|
if (!_blogPostService.TryGetPost(date, slug, out IBlogPost? post))
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
Response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
|
|
|
|
using Utf8ValueStringBuilder builder = ZString.CreateUtf8StringBuilder();
|
|
builder.AppendLine("# " + post.Title);
|
|
builder.AppendLine($"Author: {post.Author.DisplayName}");
|
|
|
|
builder.AppendLine($"Published: {post.Published:R}");
|
|
if (post.Updated.HasValue)
|
|
builder.AppendLine($"Updated: {post.Updated:R}");
|
|
|
|
builder.AppendLine();
|
|
builder.AppendLine(post.Body);
|
|
return Content(builder.ToString());
|
|
}
|
|
}
|