🐛 Fix some stupid bugs

This commit is contained in:
2025-11-22 18:22:53 +08:00
parent af0a2ff493
commit fd6e9c9780
4 changed files with 23 additions and 15 deletions

View File

@@ -144,7 +144,7 @@
@if (Model.Post.Categories.Any() || (Model.Post.Tags.Any())) @if (Model.Post.Categories.Any() || (Model.Post.Tags.Any()))
{ {
<div> <div class="flex flex-wrap gap-2">
@foreach (var category in Model.Post.Categories) @foreach (var category in Model.Post.Categories)
{ {
<span class="badge badge-primary"> <span class="badge badge-primary">

View File

@@ -1,16 +1,18 @@
using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Proto; using DysonNetwork.Shared.Proto;
using DysonNetwork.Zone.Publication; using DysonNetwork.Zone.Publication;
// Add this using statement
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using PostType = DysonNetwork.Shared.Proto.PostType;
namespace DysonNetwork.Zone.Pages.Posts; namespace DysonNetwork.Zone.Pages.Posts;
public class DetailsModel(PostService.PostServiceClient postClient, MarkdownConverter markdownConverter) : PageModel public class DetailsModel(
PostService.PostServiceClient postClient,
MarkdownConverter markdownConverter
) : PageModel
{ {
[FromRoute] public string Slug { get; set; } = null!; [FromRoute]
public string Slug { get; set; } = null!;
public SnPublicationSite? Site { get; set; } public SnPublicationSite? Site { get; set; }
public SnPost? Post { get; set; } public SnPost? Post { get; set; }
@@ -23,8 +25,10 @@ public class DetailsModel(PostService.PostServiceClient postClient, MarkdownConv
return NotFound(); return NotFound();
var request = new GetPostRequest { PublisherId = Site!.PublisherId.ToString() }; var request = new GetPostRequest { PublisherId = Site!.PublisherId.ToString() };
if (Guid.TryParse(Slug, out var guid)) request.Id = guid.ToString(); if (Guid.TryParse(Slug, out var guid))
else request.Slug = Slug; request.Id = guid.ToString();
else
request.Slug = Slug;
var response = await postClient.GetPostAsync(request); var response = await postClient.GetPostAsync(request);
if (response == null) if (response == null)
@@ -35,10 +39,13 @@ public class DetailsModel(PostService.PostServiceClient postClient, MarkdownConv
Post = SnPost.FromProtoValue(response); Post = SnPost.FromProtoValue(response);
// Convert the markdown content to HTML // Convert the markdown content to HTML
if (Post != null && !string.IsNullOrEmpty(Post.Content)) if (Post is not null && !string.IsNullOrEmpty(Post.Content))
Post.Content = markdownConverter.ToHtml(Post.Content, Post.Content = markdownConverter.ToHtml(
softBreaks: Post.Type != DysonNetwork.Shared.Models.PostType.Article); Post.Content,
softBreaks: Post.Type != DysonNetwork.Shared.Models.PostType.Article
);
return Page(); return Page();
} }
} }

View File

@@ -58,7 +58,7 @@
@if (Model.Categories.Any() || Model.Tags.Any()) @if (Model.Categories.Any() || Model.Tags.Any())
{ {
<div> <div class="flex flex-wrap gap-2">
@foreach (var category in Model.Categories) @foreach (var category in Model.Categories)
{ {
<span class="badge badge-primary"> <span class="badge badge-primary">
@@ -86,4 +86,4 @@
</a> </a>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -18,6 +18,7 @@ public class MarkdownConverter
var procMarkdown = markdown.Replace("solian://files/", "/drive/files"); var procMarkdown = markdown.Replace("solian://files/", "/drive/files");
return string.IsNullOrEmpty(procMarkdown) return string.IsNullOrEmpty(procMarkdown)
? string.Empty ? string.Empty
: Markdown.ToHtml(markdown, softBreaks ? _pipelineSoftBreak : _pipeline); : Markdown.ToHtml(procMarkdown, softBreaks ? _pipelineSoftBreak : _pipeline);
} }
} }