🐛 Serval bug fixes in hosted page
This commit is contained in:
@@ -12,10 +12,9 @@ public class IndexModel(
|
|||||||
PostService.PostServiceClient postClient,
|
PostService.PostServiceClient postClient,
|
||||||
RemotePublisherService rps,
|
RemotePublisherService rps,
|
||||||
RemoteAccountService ras,
|
RemoteAccountService ras,
|
||||||
MarkdownConverter markdownConverter // Inject MarkdownConverter
|
MarkdownConverter markdownConverter
|
||||||
) : PageModel
|
) : PageModel
|
||||||
{
|
{
|
||||||
private readonly MarkdownConverter _markdownConverter = markdownConverter; // Store the injected service
|
|
||||||
public SnPublicationSite? Site { get; set; }
|
public SnPublicationSite? Site { get; set; }
|
||||||
public SnPublisher? Publisher { get; set; }
|
public SnPublisher? Publisher { get; set; }
|
||||||
public Account? UserAccount { get; set; }
|
public Account? UserAccount { get; set; }
|
||||||
@@ -62,7 +61,7 @@ public class IndexModel(
|
|||||||
foreach (
|
foreach (
|
||||||
var post in FeaturedPosts.Where(post => !string.IsNullOrEmpty(post.Content))
|
var post in FeaturedPosts.Where(post => !string.IsNullOrEmpty(post.Content))
|
||||||
)
|
)
|
||||||
post.Content = _markdownConverter.ToHtml(post.Content!);
|
post.Content = markdownConverter.ToHtml(post.Content!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
if (Model.Publisher != null)
|
if (Model.Publisher != null)
|
||||||
{
|
{
|
||||||
pageTitle = $"Posts";
|
pageTitle = "Posts";
|
||||||
pageDescription = $"Browse posts written by {Model.Publisher.Nick}.";
|
pageDescription = $"Browse posts written by {Model.Publisher.Nick}.";
|
||||||
if (Model.Publisher.Background != null)
|
if (Model.Publisher.Background != null)
|
||||||
ogImageUrl = $"{Request.Scheme}://{Request.Host}/drive/files/{Model.Publisher.Background.Id}";
|
ogImageUrl = $"{Request.Scheme}://{Request.Host}/drive/files/{Model.Publisher.Background.Id}";
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
<div class="flex justify-center mt-8">
|
<div class="flex justify-center mt-8">
|
||||||
<div class="join">
|
<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 startPage = Math.Max(1, Model.CurrentPage - (maxPagesToShow / 2));
|
||||||
var endPage = Math.Min(Model.TotalPages, Model.CurrentPage + (maxPagesToShow / 2));
|
var endPage = Math.Min(Model.TotalPages, Model.CurrentPage + (maxPagesToShow / 2));
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ namespace DysonNetwork.Zone.Pages;
|
|||||||
public class PostsModel(
|
public class PostsModel(
|
||||||
PostService.PostServiceClient postClient,
|
PostService.PostServiceClient postClient,
|
||||||
RemotePublisherService rps,
|
RemotePublisherService rps,
|
||||||
MarkdownConverter markdownConverter // Inject MarkdownConverter
|
MarkdownConverter markdownConverter
|
||||||
) : PageModel
|
) : PageModel
|
||||||
{
|
{
|
||||||
private readonly MarkdownConverter _markdownConverter = markdownConverter; // Store the injected service
|
|
||||||
public SnPublicationSite? Site { get; set; }
|
public SnPublicationSite? Site { get; set; }
|
||||||
public SnPublisher? Publisher { get; set; }
|
public SnPublisher? Publisher { get; set; }
|
||||||
public List<SnPost> Posts { get; set; } = [];
|
public List<SnPost> Posts { get; set; } = [];
|
||||||
@@ -49,7 +48,7 @@ public class PostsModel(
|
|||||||
|
|
||||||
// Convert the markdown content to HTML
|
// Convert the markdown content to HTML
|
||||||
foreach (var post in Posts.Where(post => !string.IsNullOrEmpty(post.Content)))
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,10 @@
|
|||||||
@model DysonNetwork.Zone.Pages.Posts.DetailsModel
|
@model DysonNetwork.Zone.Pages.Posts.DetailsModel
|
||||||
@{
|
@{
|
||||||
Layout = "_LayoutContained";
|
Layout = "_LayoutContained";
|
||||||
|
|
||||||
var post = Model.Post;
|
var post = Model.Post;
|
||||||
var pageTitle = post?.Title ?? "Post";
|
var pageTitle = post?.Title ?? "Post";
|
||||||
var pageDescription = post?.Description;
|
var pageDescription = post?.Description;
|
||||||
string? ogImageUrl = null;
|
string? ogImageUrl = null;
|
||||||
var canonicalUrl = $"{Request.Scheme}://{Request.Host}{Request.Path}{Request.QueryString}";
|
var canonicalUrl = $"{Request.Scheme}://{Request.Host}{Request.Path}{Request.QueryString}";
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
ogImageUrl = $"{Request.Scheme}://{Request.Host}/drive/files/{imageAttachment.Id}";
|
ogImageUrl = $"{Request.Scheme}://{Request.Host}/drive/files/{imageAttachment.Id}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewData["Title"] = pageTitle;
|
ViewData["Title"] = pageTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,43 +32,39 @@
|
|||||||
|
|
||||||
@if (!string.IsNullOrWhiteSpace(pageDescription))
|
@if (!string.IsNullOrWhiteSpace(pageDescription))
|
||||||
{
|
{
|
||||||
<meta name="description" content="@pageDescription" />
|
<meta name="description" content="@pageDescription"/>
|
||||||
<meta property="og:description" content="@pageDescription" />
|
<meta property="og:description" content="@pageDescription"/>
|
||||||
<meta name="twitter: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:title" content="@pageTitle"/>
|
||||||
<meta property="og:type" content="article" />
|
<meta property="og:type" content="article"/>
|
||||||
<meta property="og:url" content="@canonicalUrl" />
|
<meta property="og:url" content="@canonicalUrl"/>
|
||||||
@if (!string.IsNullOrEmpty(ogImageUrl))
|
@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)
|
@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;
|
<meta property="article:tag" content="@tagName"/>
|
||||||
if(!string.IsNullOrEmpty(tagName))
|
|
||||||
{
|
|
||||||
<meta property="article:tag" content="@tagName" />
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
<meta name="twitter:title" content="@pageTitle" />
|
<meta name="twitter:title" content="@pageTitle"/>
|
||||||
@if (!string.IsNullOrEmpty(ogImageUrl))
|
@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>
|
<p>@Model.Post.Description</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="mt-2 flex gap-3 flex-wrap text-sm text-base-content/60">
|
<div class="mt-2 flex gap-3 flex-wrap text-sm text-base-content/60">
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<span class="mdi mdi-history"></span>
|
<span class="mdi mdi-history"></span>
|
||||||
@@ -92,7 +89,7 @@
|
|||||||
Posted on @Model.Post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd HH:mm")
|
Posted on @Model.Post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd HH:mm")
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (Model.Post.EditedAt.HasValue)
|
@if (Model.Post.EditedAt.HasValue)
|
||||||
{
|
{
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
@@ -109,10 +106,6 @@
|
|||||||
<div class="card bg-base-200 shadow-md">
|
<div class="card bg-base-200 shadow-md">
|
||||||
<div class="card-body flex flex-col gap-5">
|
<div class="card-body flex flex-col gap-5">
|
||||||
<div class="prose max-w-none">
|
<div class="prose max-w-none">
|
||||||
@if (!string.IsNullOrWhiteSpace(Model.Post.Description))
|
|
||||||
{
|
|
||||||
<p>@Model.Post.Description</p>
|
|
||||||
}
|
|
||||||
@Html.Raw(Model.Post.Content)
|
@Html.Raw(Model.Post.Content)
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -4,21 +4,21 @@ using DysonNetwork.Zone.Publication;
|
|||||||
// Add this using statement
|
// 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
|
||||||
{
|
{
|
||||||
private readonly MarkdownConverter _markdownConverter = markdownConverter;
|
|
||||||
[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; }
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync()
|
public async Task<IActionResult> OnGetAsync()
|
||||||
{
|
{
|
||||||
Site = HttpContext.Items[PublicationSiteMiddleware.SiteContextKey] as SnPublicationSite;
|
Site = HttpContext.Items[PublicationSiteMiddleware.SiteContextKey] as SnPublicationSite;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(Slug))
|
if (string.IsNullOrEmpty(Slug))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
@@ -33,10 +33,11 @@ public class DetailsModel(PostService.PostServiceClient postClient, MarkdownConv
|
|||||||
}
|
}
|
||||||
|
|
||||||
Post = SnPost.FromProtoValue(response);
|
Post = SnPost.FromProtoValue(response);
|
||||||
|
|
||||||
// Convert markdown content to HTML
|
// Convert the markdown content to HTML
|
||||||
if (Post != null && !string.IsNullOrEmpty(Post.Content))
|
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();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user