Post web view

This commit is contained in:
2025-07-10 15:15:20 +08:00
parent fc6edd7378
commit b8fcd0d94f
5 changed files with 83 additions and 9 deletions

View File

@ -1,17 +1,62 @@
@page "/posts/{PostId:guid}"
@model DysonNetwork.Sphere.Pages.Posts.PostDetailModel
@using Markdig
@{
ViewData["Title"] = Model.Post?.Title + " | Solar Network";
var imageUrl = Model.Post?.Attachments?.FirstOrDefault(a => a.MimeType.StartsWith("image/"))?.Id;
}
@section Head {
<meta property="og:title" content="@Model.Post?.Title" />
<meta property="og:type" content="article" />
@if (imageUrl != null)
{
<meta property="og:image" content="/api/files/@imageUrl" />
}
<meta property="og:url" content="@Request.Scheme://@Request.Host@Request.Path" />
<meta property="og:description" content="@Model.Post?.Description" />
}
<div class="container mx-auto p-4">
@if (Model.Post != null)
{
<h1 class="text-3xl font-bold mb-4">@Model.Post.Title</h1>
<p class="text-gray-600 mb-2">Created at: @Model.Post.CreatedAt</p>
<div class="prose lg:prose-xl">
<p>@Model.Post.Content</p>
<p class="text-gray-600 mb-2">
Created at: @Model.Post.CreatedAt
@if (Model.Post.Publisher?.Account != null)
{
<span>by <a href="#" class="text-blue-500">@@@Model.Post.Publisher.Name</a></span>
}
</p>
<div class="prose lg:prose-xl mb-4">
@Html.Raw(Markdown.ToHtml(Model.Post.Content ?? string.Empty))
</div>
@if (Model.Post.Attachments != null && Model.Post.Attachments.Any())
{
<h2 class="text-2xl font-bold mb-2">Attachments</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
@foreach (var attachment in Model.Post.Attachments)
{
<div class="border p-2 rounded-md">
@if (attachment.MimeType != null && attachment.MimeType.StartsWith("image/"))
{
<img src="/api/files/@attachment.Id" alt="@attachment.Name" class="w-full h-auto object-cover mb-2" />
}
else if (attachment.MimeType != null && attachment.MimeType.StartsWith("video/"))
{
<video controls class="w-full h-auto object-cover mb-2">
<source src="/api/files/@attachment.Id" type="@attachment.MimeType">
Your browser does not support the video tag.
</video>
}
<a href="/api/files/@attachment.Id" target="_blank" class="text-blue-500 hover:underline">
@attachment.Name
</a>
</div>
}
</div>
}
}
else
{

View File

@ -29,12 +29,13 @@ public class PostDetailModel(
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
Post = await db.Posts
.Where(e => e.Id == PostId)
.Include(e => e.Publisher)
.Include(e => e.Tags)
.Include(e => e.Categories)
.FilterWithVisibility(currentUser, userFriends, userPublishers)
.FirstOrDefaultAsync();
.Where(e => e.Id == PostId)
.Include(e => e.Publisher)
.ThenInclude(p => p.Account)
.Include(e => e.Tags)
.Include(e => e.Categories)
.FilterWithVisibility(currentUser, userFriends, userPublishers)
.FirstOrDefaultAsync();
if (Post == null)
return NotFound();

View File

@ -15,6 +15,8 @@
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200"
rel="stylesheet"
/>
@await RenderSectionAsync("Head", required: false)
</head>
<body class="h-full bg-base-200">
<header class="navbar bg-base-100/35 backdrop-blur-md shadow-xl fixed left-0 right-0 top-0 z-50 px-5">