🐛 Serval bug fixes in hosted page

This commit is contained in:
2025-11-22 17:43:52 +08:00
parent 7b7a6c9218
commit ec21a94921
5 changed files with 35 additions and 43 deletions

View File

@@ -3,10 +3,10 @@
@model DysonNetwork.Zone.Pages.Posts.DetailsModel
@{
Layout = "_LayoutContained";
var post = Model.Post;
var pageTitle = post?.Title ?? "Post";
var pageDescription = post?.Description;
var pageDescription = post?.Description;
string? ogImageUrl = null;
var canonicalUrl = $"{Request.Scheme}://{Request.Host}{Request.Path}{Request.QueryString}";
@@ -24,6 +24,7 @@
ogImageUrl = $"{Request.Scheme}://{Request.Host}/drive/files/{imageAttachment.Id}";
}
}
ViewData["Title"] = pageTitle;
}
@@ -31,43 +32,39 @@
@if (!string.IsNullOrWhiteSpace(pageDescription))
{
<meta name="description" content="@pageDescription" />
<meta property="og:description" content="@pageDescription" />
<meta name="twitter:description" content="@pageDescription" />
<meta name="description" content="@pageDescription"/>
<meta property="og:description" content="@pageDescription"/>
<meta name="twitter:description" content="@pageDescription"/>
}
<link rel="canonical" href="@canonicalUrl" />
<link rel="canonical" href="@canonicalUrl"/>
<meta property="og:title" content="@pageTitle" />
<meta property="og:type" content="article" />
<meta property="og:url" content="@canonicalUrl" />
<meta property="og:title" content="@pageTitle"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="@canonicalUrl"/>
@if (!string.IsNullOrEmpty(ogImageUrl))
{
<meta property="og:image" content="@ogImageUrl" />
<meta property="og:image" content="@ogImageUrl"/>
}
@if(post != null)
@if (post != null)
{
<meta property="article:published_time" content="@post.CreatedAt.ToString()" />
<meta property="article:published_time" content="@post.CreatedAt.ToString()"/>
@if (post.EditedAt.HasValue)
{
<meta property="article:modified_time" content="@post.EditedAt.Value.ToString()" />
<meta property="article:modified_time" content="@post.EditedAt.Value.ToString()"/>
}
@foreach (var tag in post.Tags)
@foreach (var tagName in post.Tags.Select(tag => !string.IsNullOrEmpty(tag.Name) ? tag.Name : tag.Slug).Where(tagName => !string.IsNullOrEmpty(tagName)))
{
var tagName = !string.IsNullOrEmpty(tag.Name) ? tag.Name : tag.Slug;
if(!string.IsNullOrEmpty(tagName))
{
<meta property="article:tag" content="@tagName" />
}
<meta property="article:tag" content="@tagName"/>
}
}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="@pageTitle" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:title" content="@pageTitle"/>
@if (!string.IsNullOrEmpty(ogImageUrl))
{
<meta name="twitter:image" content="@ogImageUrl" />
<meta name="twitter:image" content="@ogImageUrl"/>
}
}
@@ -84,7 +81,7 @@
{
<p>@Model.Post.Description</p>
}
<div class="mt-2 flex gap-3 flex-wrap text-sm text-base-content/60">
<div class="flex gap-1">
<span class="mdi mdi-history"></span>
@@ -92,7 +89,7 @@
Posted on @Model.Post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd HH:mm")
</span>
</div>
@if (Model.Post.EditedAt.HasValue)
{
<div class="flex gap-1">
@@ -109,10 +106,6 @@
<div class="card bg-base-200 shadow-md">
<div class="card-body flex flex-col gap-5">
<div class="prose max-w-none">
@if (!string.IsNullOrWhiteSpace(Model.Post.Description))
{
<p>@Model.Post.Description</p>
}
@Html.Raw(Model.Post.Content)
</div>

View File

@@ -4,21 +4,21 @@ using DysonNetwork.Zone.Publication;
// Add this using statement
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using PostType = DysonNetwork.Shared.Proto.PostType;
namespace DysonNetwork.Zone.Pages.Posts;
public class DetailsModel(PostService.PostServiceClient postClient, MarkdownConverter markdownConverter) : PageModel
{
private readonly MarkdownConverter _markdownConverter = markdownConverter;
[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();
@@ -33,10 +33,11 @@ public class DetailsModel(PostService.PostServiceClient postClient, MarkdownConv
}
Post = SnPost.FromProtoValue(response);
// Convert markdown content to HTML
// Convert the markdown content to HTML
if (Post != null && !string.IsNullOrEmpty(Post.Content))
Post.Content = _markdownConverter.ToHtml(Post.Content);
Post.Content = markdownConverter.ToHtml(Post.Content,
softBreaks: Post.Type != DysonNetwork.Shared.Models.PostType.Article);
return Page();
}