diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
index 8c6a6a01e9..3ce3c3457a 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
using Volo.CmsKit.Users;
@@ -15,6 +16,8 @@ public class BlogPostPublicDto : AuditedEntityDto
public string ShortDescription { get; set; }
+ public List ContentFragments { get; set; }
+
public string Content { get; set; }
public Guid? CoverImageMediaId { get; set; }
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
new file mode 100644
index 0000000000..e46316399c
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
@@ -0,0 +1,6 @@
+namespace Volo.CmsKit.Public.Blogs;
+
+public abstract class ContentFragment
+{
+
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs
new file mode 100644
index 0000000000..79cacf4575
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs
@@ -0,0 +1,6 @@
+namespace Volo.CmsKit.Public.Blogs;
+
+public class MarkdownContentFragment : ContentFragment
+{
+ public string Content { get; set; }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs
new file mode 100644
index 0000000000..11acbf4324
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+
+namespace Volo.CmsKit.Public.Blogs;
+
+public class WidgetContentFragment : ContentFragment
+{
+ public string Name { get; }
+
+ public string ViewComponentName { get; set; }
+
+ public IDictionary Properties { get; }
+
+ public WidgetContentFragment(string name)
+ {
+ Name = name;
+ Properties = new Dictionary();
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
index 9d8680e96c..2347e1cfc4 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
@@ -1,5 +1,6 @@
@page
+@using Volo.CmsKit.Public.Blogs
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment
@using Volo.CmsKit.Public.Web.Pages
@using Volo.Abp.GlobalFeatures
@@ -65,11 +66,18 @@
@Model.BlogPost.CreationTime
- @if (!Model.BlogPost.Content.IsNullOrEmpty())
+ @foreach (var contentFragment in Model.BlogPost.ContentFragments)
{
- @Html.Raw(await MarkdownRenderer.RenderAsync(Model.BlogPost.Content))
+ if (contentFragment is MarkdownContentFragment markdownContentFragment)
+ {
+ @Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content))
+ }
+ else if (contentFragment is WidgetContentFragment widgetContentFragment)
+ {
+ @await Component.InvokeAsync(widgetContentFragment.Name, widgetContentFragment.Properties)
+ }
}
-
+
@if (Model.BlogPost.LastModificationTime != null)
{
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
index dcefb976a4..e1eda83bb7 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
@@ -1,11 +1,5 @@
-using Markdig;
+using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography.X509Certificates;
-using System.Text;
-using System.Threading.Tasks;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.GlobalFeatures;
@@ -37,17 +31,24 @@ public class BlogPostModel : CmsKitPublicPageModelBase
protected IBlogFeatureAppService BlogFeatureAppService { get; }
+ private readonly IContentParser _contentParser;
+
+
public BlogPostModel(
IBlogPostPublicAppService blogPostPublicAppService,
- IBlogFeatureAppService blogFeaturePublicAppService)
+ IBlogFeatureAppService blogFeaturePublicAppService
+,
+ IContentParser contentParser)
{
BlogPostPublicAppService = blogPostPublicAppService;
BlogFeatureAppService = blogFeaturePublicAppService;
+ _contentParser = contentParser;
}
public virtual async Task OnGetAsync()
{
BlogPost = await BlogPostPublicAppService.GetAsync(BlogSlug, BlogPostSlug);
+ BlogPost.ContentFragments = await _contentParser.ParseAsync(BlogPost.Content);
if (GlobalFeatureManager.Instance.IsEnabled())
{
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs
new file mode 100644
index 0000000000..7a8cc195be
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+
+namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+
+public class CmsKitContentWidgetOptions
+{
+ public Dictionary WidgetConfigs { get; }
+
+ public CmsKitContentWidgetOptions()
+ {
+ WidgetConfigs = new();
+ }
+
+ public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig)
+ {
+ WidgetConfigs.Add(name, contentWidgetConfig);
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
new file mode 100644
index 0000000000..56439d9d7b
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
@@ -0,0 +1,96 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Options;
+using Volo.Abp.DependencyInjection;
+using Volo.CmsKit.Public.Blogs;
+
+namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+
+public class ContentParser : IContentParser, ITransientDependency
+{
+ private const string delimeter = "----";
+ private readonly CmsKitContentWidgetOptions _options;
+ public ContentParser(IOptions options)
+ {
+ _options = options.Value;
+ }
+
+ public async Task> ParseAsync(string content)
+ {
+ if (!_options.WidgetConfigs.Any())
+ {
+ return new List()
+ {
+ new MarkdownContentFragment() { Content = content }
+ };
+ }
+
+ var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter);
+
+ var parsedList = new List();
+
+ if (!replacedText.Contains(delimeter))
+ {
+ parsedList.Add(replacedText);
+ }
+
+ while (replacedText.Contains(delimeter))
+ {
+ //For parsing delimeter
+ var index = replacedText.IndexOf(delimeter);
+ if (index != 0)
+ {
+ parsedList.Add(replacedText.Substring(0, index));
+ replacedText = replacedText.Substring(index, replacedText.Length - index);
+ index = 0;
+ }
+
+ parsedList.Add(replacedText.Substring(index, delimeter.Length));
+ replacedText = replacedText.Substring(delimeter.Length, replacedText.Length - delimeter.Length);
+
+ //for parsing the other side
+ index = replacedText.IndexOf(delimeter);
+ if (index != -1)
+ {
+ parsedList.Add(replacedText.Substring(0, index));
+ replacedText = replacedText.Substring(index, replacedText.Length - index);
+ }
+ else
+ {
+ parsedList.Add(replacedText);
+ }
+ }
+
+ var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList();
+ var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList();
+
+ var contentFragments = new List();
+
+ for (int i = 0, k = 0; i < parsedList.Count; i++)
+ {
+ if (parsedList[i] == delimeter)
+ {
+ var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault();
+ if (name is not null)
+ {
+ contentFragments.Add(new WidgetContentFragment(name)
+ {
+ Properties =
+ {
+ { "Name", pollNames[k]}
+ }
+ });
+ }
+ k++;
+ }
+ else
+ {
+ contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] });
+ }
+ }
+
+ return contentFragments;
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs
new file mode 100644
index 0000000000..7f3e40eac4
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs
@@ -0,0 +1,15 @@
+using System;
+
+
+namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+
+public class ContentWidgetConfig
+{
+ public string Name { get; }
+ public Type ViewComponentType { get; set; }
+
+ public ContentWidgetConfig(string name)
+ {
+ Name = name;
+ }
+}
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs
new file mode 100644
index 0000000000..6ea786f70f
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Volo.CmsKit.Public.Blogs;
+
+namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
+
+public interface IContentParser
+{
+ Task> ParseAsync(string content);
+}
\ No newline at end of file