diff --git a/DysonNetwork.Zone/Pages/Posts.cshtml b/DysonNetwork.Zone/Pages/Posts.cshtml index 752a767..da4f5f3 100644 --- a/DysonNetwork.Zone/Pages/Posts.cshtml +++ b/DysonNetwork.Zone/Pages/Posts.cshtml @@ -6,7 +6,7 @@ }
-

+

Posts

@@ -36,7 +36,7 @@ } } -

@post.Content

+

@Html.Raw(post.Content)

@if (post.Attachments.Any()) diff --git a/DysonNetwork.Zone/Pages/Posts.cshtml.cs b/DysonNetwork.Zone/Pages/Posts.cshtml.cs index b45985e..de7e3eb 100644 --- a/DysonNetwork.Zone/Pages/Posts.cshtml.cs +++ b/DysonNetwork.Zone/Pages/Posts.cshtml.cs @@ -1,3 +1,4 @@ +using Markdig; using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Proto; using DysonNetwork.Shared.Registry; @@ -12,7 +13,7 @@ public class PostsModel(PostService.PostServiceClient postClient, RemotePublishe public SnPublisher? Publisher { get; set; } public List Posts { get; set; } = []; public int TotalCount { get; set; } - + public int CurrentPage { get; set; } public int PageSize { get; set; } = 10; public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize); @@ -21,7 +22,7 @@ public class PostsModel(PostService.PostServiceClient postClient, RemotePublishe { Site = HttpContext.Items[PublicationSiteMiddleware.SiteContextKey] as SnPublicationSite; CurrentPage = currentPage; - + Publisher = await rps.GetPublisher(id: Site!.PublisherId.ToString()); var request = new ListPostsRequest @@ -39,6 +40,10 @@ public class PostsModel(PostService.PostServiceClient postClient, RemotePublishe { Posts = response.Posts.Select(SnPost.FromProtoValue).ToList(); TotalCount = response.TotalSize; + + // Convert the markdown content to HTML + foreach (var post in Posts.Where(post => !string.IsNullOrEmpty(post.Content))) + post.Content = Markdown.ToHtml(post.Content!); } } } \ No newline at end of file diff --git a/DysonNetwork.Zone/Pages/Posts/Details.cshtml b/DysonNetwork.Zone/Pages/Posts/Details.cshtml index f5ddf87..e9bf302 100644 --- a/DysonNetwork.Zone/Pages/Posts/Details.cshtml +++ b/DysonNetwork.Zone/Pages/Posts/Details.cshtml @@ -2,102 +2,113 @@ @model DysonNetwork.Zone.Pages.Posts.DetailsModel @{ Layout = "_LayoutContained"; - const string defaultAvatar = "https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp"; }
- @if (Model.Post != null) - { -
-

- @(Model.Post.Title ?? "Post Details") -

- @if (!string.IsNullOrWhiteSpace(Model.Post.Description)) - { -

@Model.Post.Description

- } -
- -
-
-
-
- @if (!string.IsNullOrWhiteSpace(Model.Post.Description)) - { -

@Model.Post.Description

- } - @Model.Post.Content +
+ @if (Model.Post != null) + { +
+

+ @(Model.Post.Title ?? "Post Details") +

+ @if (!string.IsNullOrWhiteSpace(Model.Post.Description)) + { +

@Model.Post.Description

+ } + +
+
+ + + Posted on @Model.Post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd HH:mm") +
- - @if (Model.Post.Attachments.Any()) + + @if (Model.Post.EditedAt.HasValue) { -
- @foreach (var attachment in Model.Post.Attachments) - { -
- @if (attachment.MimeType!.StartsWith("image")) - { -
- @attachment.Name -
- } - else if (attachment.MimeType!.StartsWith("video")) - { - - } - else if (attachment.MimeType!.StartsWith("audio")) - { - - } - else - { - @attachment.Name - } -
- } +
+ + + Updated on @Model.Post.EditedAt.Value.ToDateTimeOffset().ToString("yyyy-MM-dd HH:mm") +
} +
+
- @if (Model.Post.Categories.Any() || (Model.Post.Tags != null && Model.Post.Tags.Any())) - { -
- @foreach (var category in Model.Post.Categories) +
+
+
+
+ @if (!string.IsNullOrWhiteSpace(Model.Post.Description)) { - - - @(!string.IsNullOrEmpty(category.Name) ? category.Name : category.Slug) - +

@Model.Post.Description

} - @if (Model.Post.Tags != null) - { + @Html.Raw(Model.Post.Content) +
+ + @if (Model.Post.Attachments.Any()) + { +
+ @foreach (var attachment in Model.Post.Attachments) + { +
+ @if (attachment.MimeType!.StartsWith("image")) + { +
+ @attachment.Name +
+ } + else if (attachment.MimeType!.StartsWith("video")) + { + + } + else if (attachment.MimeType!.StartsWith("audio")) + { + + } + else + { + @attachment.Name + } +
+ } +
+ } + + @if (Model.Post.Categories.Any() || (Model.Post.Tags.Any())) + { +
+ @foreach (var category in Model.Post.Categories) + { + + + @(!string.IsNullOrEmpty(category.Name) ? category.Name : category.Slug) + + } @foreach (var tag in Model.Post.Tags) { - + @(!string.IsNullOrEmpty(tag.Name) ? tag.Name : tag.Slug) - + } - } -
- } - -
-
- Posted on @Model.Post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd") -
+
+ }
-
- } - else - { -
-

Post not found.

-
- } + } + else + { +
+

Post not found.

+
+ } +
diff --git a/DysonNetwork.Zone/Pages/Posts/Details.cshtml.cs b/DysonNetwork.Zone/Pages/Posts/Details.cshtml.cs index ec9a978..a3aaac0 100644 --- a/DysonNetwork.Zone/Pages/Posts/Details.cshtml.cs +++ b/DysonNetwork.Zone/Pages/Posts/Details.cshtml.cs @@ -1,3 +1,4 @@ +using Markdig; using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Proto; using DysonNetwork.Zone.Publication; @@ -31,6 +32,10 @@ public class DetailsModel(PostService.PostServiceClient postClient) : PageModel } Post = SnPost.FromProtoValue(response); + + // Convert markdown content to HTML + if (Post != null && !string.IsNullOrEmpty(Post.Content)) + Post.Content = Markdown.ToHtml(Post.Content); return Page(); }