2023-08-11 15:51:20 +01:00
|
|
|
using Cysharp.Text;
|
2023-08-09 23:17:16 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
2024-03-02 00:43:56 +00:00
|
|
|
using OliverBooth.Common.Data.Blog;
|
|
|
|
using OliverBooth.Common.Services;
|
2023-08-09 23:17:16 +01:00
|
|
|
|
2023-08-13 17:33:54 +01:00
|
|
|
namespace OliverBooth.Pages.Blog;
|
2023-08-09 23:17:16 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Represents the page model for the <c>RawArticle</c> page.
|
|
|
|
/// </summary>
|
2023-08-11 14:26:21 +01:00
|
|
|
[Area("blog")]
|
2023-08-09 23:17:16 +01:00
|
|
|
public class RawArticle : PageModel
|
|
|
|
{
|
2023-08-12 20:13:47 +01:00
|
|
|
private readonly IBlogPostService _blogPostService;
|
2023-08-09 23:17:16 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="RawArticle" /> class.
|
|
|
|
/// </summary>
|
2023-08-12 20:13:47 +01:00
|
|
|
/// <param name="blogPostService">The <see cref="IBlogPostService" />.</param>
|
|
|
|
public RawArticle(IBlogPostService blogPostService)
|
2023-08-09 23:17:16 +01:00
|
|
|
{
|
2023-08-12 20:13:47 +01:00
|
|
|
_blogPostService = blogPostService;
|
2023-08-09 23:17:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public IActionResult OnGet(int year, int month, int day, string slug)
|
|
|
|
{
|
2023-08-12 20:13:47 +01:00
|
|
|
var date = new DateOnly(year, month, day);
|
|
|
|
if (!_blogPostService.TryGetPost(date, slug, out IBlogPost? post))
|
2023-08-09 23:17:16 +01:00
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
2023-08-11 16:42:12 +01:00
|
|
|
|
|
|
|
Response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
|
|
|
|
|
2023-08-09 23:17:16 +01:00
|
|
|
using Utf8ValueStringBuilder builder = ZString.CreateUtf8StringBuilder();
|
|
|
|
builder.AppendLine("# " + post.Title);
|
2023-08-12 20:13:47 +01:00
|
|
|
builder.AppendLine($"Author: {post.Author.DisplayName}");
|
2023-08-11 16:42:12 +01:00
|
|
|
|
2023-08-09 23:17:16 +01:00
|
|
|
builder.AppendLine($"Published: {post.Published:R}");
|
|
|
|
if (post.Updated.HasValue)
|
2024-02-25 14:11:33 +00:00
|
|
|
{
|
2023-08-09 23:17:16 +01:00
|
|
|
builder.AppendLine($"Updated: {post.Updated:R}");
|
2024-02-25 14:11:33 +00:00
|
|
|
}
|
2023-08-11 16:42:12 +01:00
|
|
|
|
2023-08-09 23:17:16 +01:00
|
|
|
builder.AppendLine();
|
|
|
|
builder.AppendLine(post.Body);
|
2023-08-11 16:42:12 +01:00
|
|
|
return Content(builder.ToString());
|
2023-08-09 23:17:16 +01:00
|
|
|
}
|
|
|
|
}
|