✨ Extend the ability of the hosted page markdown parser
This commit is contained in:
@@ -2,14 +2,14 @@ using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using DysonNetwork.Zone.Publication;
|
||||
using Markdig;
|
||||
// Add this using statement
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using NodaTime;
|
||||
|
||||
|
||||
namespace DysonNetwork.Zone.Pages;
|
||||
|
||||
public class AboutModel(RemoteAccountService ras) : PageModel
|
||||
public class AboutModel(RemoteAccountService ras, MarkdownConverter markdownConverter) : PageModel
|
||||
{
|
||||
public SnPublicationSite? Site { get; set; }
|
||||
public Account? UserAccount { get; set; }
|
||||
@@ -32,8 +32,7 @@ public class AboutModel(RemoteAccountService ras) : PageModel
|
||||
|
||||
if (UserAccount?.Profile?.Bio != null)
|
||||
{
|
||||
var pipeline = new MarkdownPipelineBuilder().Build();
|
||||
HtmlBio = Markdown.ToHtml(UserAccount.Profile.Bio, pipeline);
|
||||
HtmlBio = markdownConverter.ToHtml(UserAccount.Profile.Bio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using DysonNetwork.Zone.Publication;
|
||||
using Markdig;
|
||||
// Add this using statement
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using NodaTime;
|
||||
|
||||
@@ -11,9 +11,11 @@ namespace DysonNetwork.Zone.Pages;
|
||||
public class IndexModel(
|
||||
PostService.PostServiceClient postClient,
|
||||
RemotePublisherService rps,
|
||||
RemoteAccountService ras
|
||||
RemoteAccountService ras,
|
||||
MarkdownConverter markdownConverter // Inject 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; }
|
||||
@@ -60,7 +62,7 @@ public class IndexModel(
|
||||
foreach (
|
||||
var post in FeaturedPosts.Where(post => !string.IsNullOrEmpty(post.Content))
|
||||
)
|
||||
post.Content = Markdown.ToHtml(post.Content!);
|
||||
post.Content = _markdownConverter.ToHtml(post.Content!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
using Markdig;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using DysonNetwork.Zone.Publication;
|
||||
// Add this using statement
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using PostType = DysonNetwork.Shared.Models.PostType;
|
||||
|
||||
namespace DysonNetwork.Zone.Pages;
|
||||
|
||||
public class PostsModel(PostService.PostServiceClient postClient, RemotePublisherService rps) : PageModel
|
||||
public class PostsModel(
|
||||
PostService.PostServiceClient postClient,
|
||||
RemotePublisherService rps,
|
||||
MarkdownConverter markdownConverter // Inject 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; } = [];
|
||||
@@ -43,7 +49,7 @@ public class PostsModel(PostService.PostServiceClient postClient, RemotePublishe
|
||||
|
||||
// Convert the markdown content to HTML
|
||||
foreach (var post in Posts.Where(post => !string.IsNullOrEmpty(post.Content)))
|
||||
post.Content = Markdown.ToHtml(post.Content!);
|
||||
post.Content = _markdownConverter.ToHtml(post.Content!, softBreaks: post.Type != PostType.Article);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
using Markdig;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Zone.Publication;
|
||||
// Add this using statement
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace DysonNetwork.Zone.Pages.Posts;
|
||||
|
||||
public class DetailsModel(PostService.PostServiceClient postClient) : PageModel
|
||||
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; }
|
||||
@@ -35,7 +36,7 @@ public class DetailsModel(PostService.PostServiceClient postClient) : PageModel
|
||||
|
||||
// Convert markdown content to HTML
|
||||
if (Post != null && !string.IsNullOrEmpty(Post.Content))
|
||||
Post.Content = Markdown.ToHtml(Post.Content);
|
||||
Post.Content = _markdownConverter.ToHtml(Post.Content);
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
23
DysonNetwork.Zone/Publication/MarkdownConverter.cs
Normal file
23
DysonNetwork.Zone/Publication/MarkdownConverter.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Markdig;
|
||||
|
||||
namespace DysonNetwork.Zone.Publication;
|
||||
|
||||
public class MarkdownConverter
|
||||
{
|
||||
private readonly MarkdownPipeline _pipelineSoftBreak = new MarkdownPipelineBuilder()
|
||||
.UseAdvancedExtensions()
|
||||
.UseSoftlineBreakAsHardlineBreak()
|
||||
.Build();
|
||||
|
||||
private readonly MarkdownPipeline _pipeline = new MarkdownPipelineBuilder()
|
||||
.UseAdvancedExtensions()
|
||||
.Build();
|
||||
|
||||
public string ToHtml(string markdown, bool softBreaks = true)
|
||||
{
|
||||
var procMarkdown = markdown.Replace("solian://files/", "/drive/files");
|
||||
return string.IsNullOrEmpty(procMarkdown)
|
||||
? string.Empty
|
||||
: Markdown.ToHtml(markdown, softBreaks ? _pipelineSoftBreak : _pipeline);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,14 @@ using System.ServiceModel.Syndication;
|
||||
using System.Xml;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using Markdig;
|
||||
using DysonNetwork.Zone.Publication;
|
||||
// Add this using statement
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DysonNetwork.Zone.SEO;
|
||||
|
||||
[ApiController]
|
||||
public class RssController(PostService.PostServiceClient postClient) : ControllerBase
|
||||
public class RssController(PostService.PostServiceClient postClient, MarkdownConverter markdownConverter) : ControllerBase
|
||||
{
|
||||
[HttpGet("rss")]
|
||||
[Produces("application/rss+xml")]
|
||||
@@ -42,7 +43,7 @@ public class RssController(PostService.PostServiceClient postClient) : Controlle
|
||||
|
||||
var item = new SyndicationItem(
|
||||
post.Title,
|
||||
post.Content is not null ? Markdown.ToHtml(post.Content!) : "No content", // Convert Markdown to HTML
|
||||
post.Content is not null ? markdownConverter.ToHtml(post.Content!) : "No content", // Convert Markdown to HTML
|
||||
new Uri(postUrl),
|
||||
post.Id.ToString(),
|
||||
post.EditedAt?.ToDateTimeOffset() ??
|
||||
|
||||
@@ -7,6 +7,8 @@ using DysonNetwork.Zone.Publication;
|
||||
using NodaTime;
|
||||
using NodaTime.Serialization.SystemTextJson;
|
||||
|
||||
// Add this using statement
|
||||
|
||||
namespace DysonNetwork.Zone.Startup;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
@@ -19,6 +21,7 @@ public static class ServiceCollectionExtensions
|
||||
services.AddSingleton<IClock>(SystemClock.Instance);
|
||||
services.AddHttpContextAccessor();
|
||||
services.AddSingleton<ICacheService, CacheServiceRedis>();
|
||||
services.AddSingleton<MarkdownConverter>();
|
||||
|
||||
services.AddHttpClient();
|
||||
|
||||
|
||||
@@ -103,6 +103,8 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALivekitRoom_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F82666257d5ad47354add7af860f66dd85df55ec93e92e8a45891b9bff7bf80ac_003FLivekitRoom_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALocalDate_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F9bab6c3f4ee252ba1a9d0707f963a846da4f248fa52e9ff43e789149728a4_003FLocalDate_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMailboxAddress_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8e03e47c46b7469f97abc40667cbcf9b133000_003Fa6_003F83324248_003FMailboxAddress_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMarkdownExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F941558ce147e451baff49677c95dde8d75000_003F67_003F8c0cc1a5_003FMarkdownExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMarkdownExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FSourcesCache_003F5cf0a036d23b7f3f04eba9a3fe5c9b5dfb37a2b8c23602bc5176317374cb1c_003FMarkdownExtensions_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMediaAnalysis_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffef366b36a224d469ff150d30f9a866d23c00_003Fd7_003F5c138865_003FMediaAnalysis_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMicrosoftDependencyInjectionJobFactory_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F1edbd6e24d7b430fabce72177269baa19200_003Fa8_003F91b091de_003FMicrosoftDependencyInjectionJobFactory_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANodaExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F472c5156daf14d04a5b30e00cd80dbf85ac0_003Ff4_003F9e841463_003FNodaExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
|
||||
Reference in New Issue
Block a user