From b8fcd0d94feaa957e14fcf7c2b3ed684c0aeb037 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 10 Jul 2025 15:15:20 +0800 Subject: [PATCH] :sparkles: Post web view --- .../DysonNetwork.Sphere.csproj | 1 + .../Pages/Posts/PostDetail.cshtml | 51 +++++++++++++++++-- .../Pages/Posts/PostDetail.cshtml.cs | 13 ++--- .../Pages/Shared/_Layout.cshtml | 2 + DysonNetwork.Sphere/wwwroot/css/styles.css | 25 +++++++++ 5 files changed, 83 insertions(+), 9 deletions(-) diff --git a/DysonNetwork.Sphere/DysonNetwork.Sphere.csproj b/DysonNetwork.Sphere/DysonNetwork.Sphere.csproj index 0f39fb9..d1c90df 100644 --- a/DysonNetwork.Sphere/DysonNetwork.Sphere.csproj +++ b/DysonNetwork.Sphere/DysonNetwork.Sphere.csproj @@ -26,6 +26,7 @@ + diff --git a/DysonNetwork.Sphere/Pages/Posts/PostDetail.cshtml b/DysonNetwork.Sphere/Pages/Posts/PostDetail.cshtml index 07442c1..0fee10e 100644 --- a/DysonNetwork.Sphere/Pages/Posts/PostDetail.cshtml +++ b/DysonNetwork.Sphere/Pages/Posts/PostDetail.cshtml @@ -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 { + + + @if (imageUrl != null) + { + + } + + }
@if (Model.Post != null) {

@Model.Post.Title

-

Created at: @Model.Post.CreatedAt

-
-

@Model.Post.Content

+

+ Created at: @Model.Post.CreatedAt + @if (Model.Post.Publisher?.Account != null) + { + by @@@Model.Post.Publisher.Name + } +

+
+ @Html.Raw(Markdown.ToHtml(Model.Post.Content ?? string.Empty))
+ + @if (Model.Post.Attachments != null && Model.Post.Attachments.Any()) + { +

Attachments

+
+ @foreach (var attachment in Model.Post.Attachments) + { +
+ @if (attachment.MimeType != null && attachment.MimeType.StartsWith("image/")) + { + @attachment.Name + } + else if (attachment.MimeType != null && attachment.MimeType.StartsWith("video/")) + { + + } + + @attachment.Name + +
+ } +
+ } } else { diff --git a/DysonNetwork.Sphere/Pages/Posts/PostDetail.cshtml.cs b/DysonNetwork.Sphere/Pages/Posts/PostDetail.cshtml.cs index 825a2e6..15d2ba8 100644 --- a/DysonNetwork.Sphere/Pages/Posts/PostDetail.cshtml.cs +++ b/DysonNetwork.Sphere/Pages/Posts/PostDetail.cshtml.cs @@ -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(); diff --git a/DysonNetwork.Sphere/Pages/Shared/_Layout.cshtml b/DysonNetwork.Sphere/Pages/Shared/_Layout.cshtml index cb7893f..d229ef9 100644 --- a/DysonNetwork.Sphere/Pages/Shared/_Layout.cshtml +++ b/DysonNetwork.Sphere/Pages/Shared/_Layout.cshtml @@ -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)