✨ Render markdown on hosted pages
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<div class="container mx-auto px-8 py-8">
|
<div class="container mx-auto px-8 py-8">
|
||||||
<h1 class="text-3xl font-bold mb-8">
|
<h1 class="text-3xl font-bold mb-8 px-5">
|
||||||
<span class="mdi mdi-note-text-outline"></span> Posts
|
<span class="mdi mdi-note-text-outline"></span> Posts
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
}
|
}
|
||||||
</section>
|
</section>
|
||||||
}
|
}
|
||||||
<p>@post.Content</p>
|
<p>@Html.Raw(post.Content)</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (post.Attachments.Any())
|
@if (post.Attachments.Any())
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Markdig;
|
||||||
using DysonNetwork.Shared.Models;
|
using DysonNetwork.Shared.Models;
|
||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
using DysonNetwork.Shared.Registry;
|
using DysonNetwork.Shared.Registry;
|
||||||
@@ -12,7 +13,7 @@ public class PostsModel(PostService.PostServiceClient postClient, RemotePublishe
|
|||||||
public SnPublisher? Publisher { get; set; }
|
public SnPublisher? Publisher { get; set; }
|
||||||
public List<SnPost> Posts { get; set; } = [];
|
public List<SnPost> Posts { get; set; } = [];
|
||||||
public int TotalCount { get; set; }
|
public int TotalCount { get; set; }
|
||||||
|
|
||||||
public int CurrentPage { get; set; }
|
public int CurrentPage { get; set; }
|
||||||
public int PageSize { get; set; } = 10;
|
public int PageSize { get; set; } = 10;
|
||||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
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;
|
Site = HttpContext.Items[PublicationSiteMiddleware.SiteContextKey] as SnPublicationSite;
|
||||||
CurrentPage = currentPage;
|
CurrentPage = currentPage;
|
||||||
|
|
||||||
Publisher = await rps.GetPublisher(id: Site!.PublisherId.ToString());
|
Publisher = await rps.GetPublisher(id: Site!.PublisherId.ToString());
|
||||||
|
|
||||||
var request = new ListPostsRequest
|
var request = new ListPostsRequest
|
||||||
@@ -39,6 +40,10 @@ public class PostsModel(PostService.PostServiceClient postClient, RemotePublishe
|
|||||||
{
|
{
|
||||||
Posts = response.Posts.Select(SnPost.FromProtoValue).ToList();
|
Posts = response.Posts.Select(SnPost.FromProtoValue).ToList();
|
||||||
TotalCount = response.TotalSize;
|
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!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,102 +2,113 @@
|
|||||||
@model DysonNetwork.Zone.Pages.Posts.DetailsModel
|
@model DysonNetwork.Zone.Pages.Posts.DetailsModel
|
||||||
@{
|
@{
|
||||||
Layout = "_LayoutContained";
|
Layout = "_LayoutContained";
|
||||||
const string defaultAvatar = "https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="container max-w-4xl mx-auto px-8 py-8">
|
<div class="container max-w-4xl mx-auto px-8 py-8">
|
||||||
@if (Model.Post != null)
|
<article>
|
||||||
{
|
@if (Model.Post != null)
|
||||||
<section class="mb-8 mt-2 px-5">
|
{
|
||||||
<h1 class="text-3xl font-bold">
|
<section class="mb-8 mt-2 px-5">
|
||||||
@(Model.Post.Title ?? "Post Details")
|
<h1 class="text-3xl font-bold">
|
||||||
</h1>
|
@(Model.Post.Title ?? "Post Details")
|
||||||
@if (!string.IsNullOrWhiteSpace(Model.Post.Description))
|
</h1>
|
||||||
{
|
@if (!string.IsNullOrWhiteSpace(Model.Post.Description))
|
||||||
<p>@Model.Post.Description</p>
|
{
|
||||||
}
|
<p>@Model.Post.Description</p>
|
||||||
</section>
|
}
|
||||||
|
|
||||||
<div class="w-full flex flex-col gap-5">
|
<div class="mt-2 flex gap-3 flex-wrap text-sm text-base-content/60">
|
||||||
<div class="card bg-base-200 shadow-md">
|
<div class="flex gap-1">
|
||||||
<div class="card-body flex flex-col gap-5">
|
<span class="mdi mdi-history"></span>
|
||||||
<div class="prose max-w-none">
|
<span>
|
||||||
@if (!string.IsNullOrWhiteSpace(Model.Post.Description))
|
Posted on @Model.Post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd HH:mm")
|
||||||
{
|
</span>
|
||||||
<p>@Model.Post.Description</p>
|
|
||||||
}
|
|
||||||
@Model.Post.Content
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (Model.Post.Attachments.Any())
|
@if (Model.Post.EditedAt.HasValue)
|
||||||
{
|
{
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex gap-1">
|
||||||
@foreach (var attachment in Model.Post.Attachments)
|
<span class="mdi mdi-pencil"></span>
|
||||||
{
|
<span>
|
||||||
<div>
|
Updated on @Model.Post.EditedAt.Value.ToDateTimeOffset().ToString("yyyy-MM-dd HH:mm")
|
||||||
@if (attachment.MimeType!.StartsWith("image"))
|
</span>
|
||||||
{
|
|
||||||
<figure>
|
|
||||||
<img src="/drive/files/@attachment.Id" alt="@attachment.Name"
|
|
||||||
class="max-w-full h-auto rounded-lg"/>
|
|
||||||
</figure>
|
|
||||||
}
|
|
||||||
else if (attachment.MimeType!.StartsWith("video"))
|
|
||||||
{
|
|
||||||
<video controls src="/drive/files/@attachment.Id"
|
|
||||||
class="max-w-full h-auto rounded-lg"></video>
|
|
||||||
}
|
|
||||||
else if (attachment.MimeType!.StartsWith("audio"))
|
|
||||||
{
|
|
||||||
<audio controls src="/drive/files/@attachment.Id"
|
|
||||||
class="max-w-full h-auto rounded-lg"></audio>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<a href="/drive/files/@attachment.Id" target="_blank"
|
|
||||||
class="text-blue-500 hover:underline">@attachment.Name</a>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
@if (Model.Post.Categories.Any() || (Model.Post.Tags != null && Model.Post.Tags.Any()))
|
<div class="w-full flex flex-col gap-5">
|
||||||
{
|
<div class="card bg-base-200 shadow-md">
|
||||||
<div>
|
<div class="card-body flex flex-col gap-5">
|
||||||
@foreach (var category in Model.Post.Categories)
|
<div class="prose max-w-none">
|
||||||
|
@if (!string.IsNullOrWhiteSpace(Model.Post.Description))
|
||||||
{
|
{
|
||||||
<span class="badge badge-primary">
|
<p>@Model.Post.Description</p>
|
||||||
<span class="mdi mdi-shape"></span>
|
|
||||||
@(!string.IsNullOrEmpty(category.Name) ? category.Name : category.Slug)
|
|
||||||
</span>
|
|
||||||
}
|
}
|
||||||
@if (Model.Post.Tags != null)
|
@Html.Raw(Model.Post.Content)
|
||||||
{
|
</div>
|
||||||
|
|
||||||
|
@if (Model.Post.Attachments.Any())
|
||||||
|
{
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
@foreach (var attachment in Model.Post.Attachments)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
@if (attachment.MimeType!.StartsWith("image"))
|
||||||
|
{
|
||||||
|
<figure>
|
||||||
|
<img src="/drive/files/@attachment.Id" alt="@attachment.Name"
|
||||||
|
class="max-w-full h-auto rounded-lg"/>
|
||||||
|
</figure>
|
||||||
|
}
|
||||||
|
else if (attachment.MimeType!.StartsWith("video"))
|
||||||
|
{
|
||||||
|
<video controls src="/drive/files/@attachment.Id"
|
||||||
|
class="max-w-full h-auto rounded-lg"></video>
|
||||||
|
}
|
||||||
|
else if (attachment.MimeType!.StartsWith("audio"))
|
||||||
|
{
|
||||||
|
<audio controls src="/drive/files/@attachment.Id"
|
||||||
|
class="max-w-full h-auto rounded-lg"></audio>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<a href="/drive/files/@attachment.Id" target="_blank"
|
||||||
|
class="text-blue-500 hover:underline">@attachment.Name</a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Model.Post.Categories.Any() || (Model.Post.Tags.Any()))
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
@foreach (var category in Model.Post.Categories)
|
||||||
|
{
|
||||||
|
<span class="badge badge-primary">
|
||||||
|
<span class="mdi mdi-shape"></span>
|
||||||
|
@(!string.IsNullOrEmpty(category.Name) ? category.Name : category.Slug)
|
||||||
|
</span>
|
||||||
|
}
|
||||||
@foreach (var tag in Model.Post.Tags)
|
@foreach (var tag in Model.Post.Tags)
|
||||||
{
|
{
|
||||||
<span class="badge badge-info">
|
<span class="badge badge-info">
|
||||||
<span class="mdi mdi-tag"></span>
|
<span class="mdi mdi-tag"></span>
|
||||||
@(!string.IsNullOrEmpty(tag.Name) ? tag.Name : tag.Slug)
|
@(!string.IsNullOrEmpty(tag.Name) ? tag.Name : tag.Slug)
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
}
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
|
||||||
|
|
||||||
<div class="card-actions justify-end items-center">
|
|
||||||
<div class="text-sm text-base-content/60">
|
|
||||||
Posted on @Model.Post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd")
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
<div class="text-center py-16">
|
||||||
<div class="text-center py-16">
|
<p class="text-lg">Post not found.</p>
|
||||||
<p class="text-lg">Post not found.</p>
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Markdig;
|
||||||
using DysonNetwork.Shared.Models;
|
using DysonNetwork.Shared.Models;
|
||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
using DysonNetwork.Zone.Publication;
|
using DysonNetwork.Zone.Publication;
|
||||||
@@ -31,6 +32,10 @@ public class DetailsModel(PostService.PostServiceClient postClient) : PageModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
Post = SnPost.FromProtoValue(response);
|
Post = SnPost.FromProtoValue(response);
|
||||||
|
|
||||||
|
// Convert markdown content to HTML
|
||||||
|
if (Post != null && !string.IsNullOrEmpty(Post.Content))
|
||||||
|
Post.Content = Markdown.ToHtml(Post.Content);
|
||||||
|
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user