🐛 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

@@ -12,10 +12,9 @@ public class IndexModel(
PostService.PostServiceClient postClient,
RemotePublisherService rps,
RemoteAccountService ras,
MarkdownConverter markdownConverter // Inject MarkdownConverter
MarkdownConverter markdownConverter
) : PageModel
{
private readonly MarkdownConverter _markdownConverter = markdownConverter; // Store the injected service
public SnPublicationSite? Site { get; set; }
public SnPublisher? Publisher { get; set; }
public Account? UserAccount { get; set; }
@@ -62,7 +61,7 @@ public class IndexModel(
foreach (
var post in FeaturedPosts.Where(post => !string.IsNullOrEmpty(post.Content))
)
post.Content = _markdownConverter.ToHtml(post.Content!);
post.Content = markdownConverter.ToHtml(post.Content!);
}
}
}

View File

@@ -12,7 +12,7 @@
if (Model.Publisher != null)
{
pageTitle = $"Posts";
pageTitle = "Posts";
pageDescription = $"Browse posts written by {Model.Publisher.Nick}.";
if (Model.Publisher.Background != null)
ogImageUrl = $"{Request.Scheme}://{Request.Host}/drive/files/{Model.Publisher.Background.Id}";
@@ -74,7 +74,7 @@
<div class="flex justify-center mt-8">
<div class="join">
@{
var maxPagesToShow = 5; // e.g., 2 before, current, 2 after
const int maxPagesToShow = 5; // e.g., 2 before, current, 2 after
var startPage = Math.Max(1, Model.CurrentPage - (maxPagesToShow / 2));
var endPage = Math.Min(Model.TotalPages, Model.CurrentPage + (maxPagesToShow / 2));

View File

@@ -11,10 +11,9 @@ namespace DysonNetwork.Zone.Pages;
public class PostsModel(
PostService.PostServiceClient postClient,
RemotePublisherService rps,
MarkdownConverter markdownConverter // Inject MarkdownConverter
MarkdownConverter markdownConverter
) : PageModel
{
private readonly MarkdownConverter _markdownConverter = markdownConverter; // Store the injected service
public SnPublicationSite? Site { get; set; }
public SnPublisher? Publisher { get; set; }
public List<SnPost> Posts { get; set; } = [];
@@ -49,7 +48,7 @@ public class PostsModel(
// Convert the markdown content to HTML
foreach (var post in Posts.Where(post => !string.IsNullOrEmpty(post.Content)))
post.Content = _markdownConverter.ToHtml(post.Content!, softBreaks: post.Type != PostType.Article);
post.Content = markdownConverter.ToHtml(post.Content!, softBreaks: post.Type != PostType.Article);
}
}
}

View File

@@ -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"/>
}
}
@@ -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,12 +4,12 @@ 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; }
@@ -34,9 +34,10 @@ 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();
}