Oliver Booth
0a9c2e82d5
CORS was "cors"ing some issues (heh). But also it is easier to maintain this way. Development was made much more difficult when I separated it. Combining it all also improves SEO
59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using OliverBooth.Data.Blog;
|
|
using OliverBooth.Services;
|
|
|
|
namespace OliverBooth.Pages.Blog;
|
|
|
|
/// <summary>
|
|
/// Represents the page model for the <c>Article</c> page.
|
|
/// </summary>
|
|
[Area("blog")]
|
|
public class Article : PageModel
|
|
{
|
|
private readonly IBlogPostService _blogPostService;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="Article" /> class.
|
|
/// </summary>
|
|
/// <param name="blogPostService">The <see cref="IBlogPostService" />.</param>
|
|
public Article(IBlogPostService blogPostService)
|
|
{
|
|
_blogPostService = blogPostService;
|
|
}
|
|
|
|
/*
|
|
/// <summary>
|
|
/// Gets a value indicating whether the post is a legacy WordPress post.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <see langword="true" /> if the post is a legacy WordPress post; otherwise, <see langword="false" />.
|
|
/// </value>
|
|
public bool IsWordPressLegacyPost => Post.WordPressId.HasValue;
|
|
*/
|
|
|
|
/// <summary>
|
|
/// Gets the requested blog post.
|
|
/// </summary>
|
|
/// <value>The requested blog post.</value>
|
|
public IBlogPost Post { get; private set; } = null!;
|
|
|
|
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))
|
|
{
|
|
Response.StatusCode = 404;
|
|
return NotFound();
|
|
}
|
|
|
|
if (post.IsRedirect)
|
|
{
|
|
return Redirect(post.RedirectUrl!.ToString());
|
|
}
|
|
|
|
Post = post;
|
|
return Page();
|
|
}
|
|
}
|