42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using Markdig;
|
|
using DysonNetwork.Shared.Models;
|
|
using DysonNetwork.Shared.Proto;
|
|
using DysonNetwork.Zone.Publication;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace DysonNetwork.Zone.Pages.Posts;
|
|
|
|
public class DetailsModel(PostService.PostServiceClient postClient) : PageModel
|
|
{
|
|
[FromRoute] public string Slug { get; set; } = null!;
|
|
|
|
public SnPublicationSite? Site { get; set; }
|
|
public SnPost? Post { get; set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
Site = HttpContext.Items[PublicationSiteMiddleware.SiteContextKey] as SnPublicationSite;
|
|
|
|
if (string.IsNullOrEmpty(Slug))
|
|
return NotFound();
|
|
|
|
var request = new GetPostRequest { PublisherId = Site!.PublisherId.ToString() };
|
|
if (Guid.TryParse(Slug, out var guid)) request.Id = guid.ToString();
|
|
else request.Slug = Slug;
|
|
var response = await postClient.GetPostAsync(request);
|
|
|
|
if (response == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
Post = SnPost.FromProtoValue(response);
|
|
|
|
// Convert markdown content to HTML
|
|
if (Post != null && !string.IsNullOrEmpty(Post.Content))
|
|
Post.Content = Markdown.ToHtml(Post.Content);
|
|
|
|
return Page();
|
|
}
|
|
} |