oliverbooth.dev/OliverBooth/Pages/Blog/RawArticle.cshtml.cs

51 lines
1.5 KiB
C#
Raw Normal View History

2023-08-11 15:51:20 +01:00
using Cysharp.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using OliverBooth.Common.Data.Blog;
using OliverBooth.Common.Services;
namespace OliverBooth.Pages.Blog;
/// <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();
}
2024-03-02 01:29:01 +00:00
Response.Headers.Append("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)
2024-02-25 14:11:33 +00:00
{
builder.AppendLine($"Updated: {post.Updated:R}");
2024-02-25 14:11:33 +00:00
}
builder.AppendLine();
builder.AppendLine(post.Body);
return Content(builder.ToString());
}
}