Browse Source

Removed duplication and moved to the domain

pull/13082/head
malik masis 4 years ago
parent
commit
7b3442ae5f
  1. 4
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs
  2. 5
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs
  3. 4
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs
  4. 4
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs
  5. 5
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs
  6. 9
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs
  7. 4
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs
  8. 8
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs
  9. 7
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs
  10. 19
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs
  11. 1
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs
  12. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs
  13. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs
  14. 20
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs
  15. 27
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs
  16. 7
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs
  17. 63
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json
  18. 27
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs
  19. 18
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
  20. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs
  21. 14
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs
  22. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml
  23. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
  24. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs
  25. 1
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs
  26. 18
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs
  27. 1
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
  28. 12
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs
  29. 96
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs
  30. 10
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs

4
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs

@ -1,6 +1,4 @@
using Volo.CmsKit.GlobalFeatures;
namespace Volo.CmsKit.Blogs;
namespace Volo.CmsKit.Blogs;
public static class BlogPostConsts
{

5
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs

@ -0,0 +1,5 @@
namespace Volo.CmsKit.Polls;
public abstract class ContentFragment
{
}

4
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs → modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
namespace Volo.CmsKit.Polls;
public interface IContentParser
{

4
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs → modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs

@ -1,6 +1,6 @@
namespace Volo.CmsKit.Public.Blogs;
namespace Volo.CmsKit.Polls;
public class MarkdownContentFragment : ContentFragment
{
public string Content { get; set; }
}
}

5
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs

@ -0,0 +1,5 @@
namespace Volo.CmsKit.Polls;
public static class PollConsts
{
public static string Delimeter { get; } = "----";
}

9
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs → modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs

@ -1,11 +1,10 @@
using System.Collections.Generic;
namespace Volo.CmsKit.Public.Blogs;
using System.Collections.Generic;
namespace Volo.CmsKit.Polls;
public class WidgetContentFragment : ContentFragment
{
public string Name { get; }
public string ViewComponentName { get; set; }
public IDictionary<string, object> Properties { get; }
@ -15,4 +14,4 @@ public class WidgetContentFragment : ContentFragment
Name = name;
Properties = new Dictionary<string, object>();
}
}
}

4
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs → modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs

@ -1,10 +1,10 @@
using System.Collections.Generic;
namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
namespace Volo.CmsKit.Polls;
public class CmsKitContentWidgetOptions
{
public Dictionary<string, ContentWidgetConfig> WidgetConfigs { get; }
public Dictionary<string, ContentWidgetConfig> WidgetConfigs { get; }
public CmsKitContentWidgetOptions()
{

8
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs → modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs

@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
namespace Volo.CmsKit.Polls;
public class ContentParser : IContentParser, ITransientDependency
{
@ -62,8 +62,8 @@ public class ContentParser : IContentParser, ITransientDependency
}
}
var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList();
var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList();
var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Cast<Match>().Select(p => p.Value).ToList();
var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Cast<Match>().Select(p => p.Value).ToList();
var contentFragments = new List<ContentFragment>();

7
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs → modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs

@ -1,13 +1,12 @@
using System;
using System;
namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
namespace Volo.CmsKit.Polls;
public class ContentWidgetConfig
{
public string Name { get; }
public Type ViewComponentType { get; set; }
public ContentWidgetConfig(string name)
{
Name = name;

19
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs

@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
namespace Volo.CmsKit.Polls;
public class PollViewComponentManager : DomainService
{
protected IContentParser ContentParser { get; set; }
public PollViewComponentManager(IContentParser contentParser)
{
ContentParser = contentParser;
}
public virtual async Task<List<ContentFragment>> ParseAsync(string content)
{
return await ContentParser.ParseAsync(content);
}
}

1
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
using Volo.CmsKit.Polls;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Public.Blogs;

6
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs

@ -1,6 +0,0 @@
namespace Volo.CmsKit.Public.Blogs;
public abstract class ContentFragment
{
}

11
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs

@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.CmsKit.Polls;
namespace Volo.CmsKit.Public.Polls;
public interface IPollViewComponentAppService : IApplicationService
{
Task<List<ContentFragment>> ParseAsync(string content);
}

20
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs

@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.CmsKit.Polls;
namespace Volo.CmsKit.Public.Polls;
public class PollViewComponentAppService : CmsKitPublicAppServiceBase, IPollViewComponentAppService
{
protected PollViewComponentManager PollViewComponentManager { get; set; }
public PollViewComponentAppService(PollViewComponentManager pollViewComponentManager)
{
PollViewComponentManager = pollViewComponentManager;
}
public virtual async Task<List<ContentFragment>> ParseAsync(string content)
{
return await PollViewComponentManager.ParseAsync(content);
}
}

27
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs

@ -0,0 +1,27 @@
// This file is automatically generated by ABP framework to use MVC Controllers from CSharp
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Http.Client;
using Volo.Abp.Http.Modeling;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Client.ClientProxying;
using Volo.CmsKit.Public.Polls;
using System.Collections.Generic;
using Volo.CmsKit.Polls;
// ReSharper disable once CheckNamespace
namespace Volo.CmsKit.Public.Polls.ClientProxies;
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IPollViewComponentAppService), typeof(PollViewComponentClientProxy))]
public partial class PollViewComponentClientProxy : ClientProxyBase<IPollViewComponentAppService>, IPollViewComponentAppService
{
public virtual async Task<List<ContentFragment>> ParseAsync(string content)
{
return await RequestAsync<List<ContentFragment>>(nameof(ParseAsync), new ClientProxyRequestTypeValue
{
{ typeof(string), content }
});
}
}

7
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs

@ -0,0 +1,7 @@
// This file is part of PollViewComponentClientProxy, you can customize it here
// ReSharper disable once CheckNamespace
namespace Volo.CmsKit.Public.Polls.ClientProxies;
public partial class PollViewComponentClientProxy
{
}

63
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json

@ -505,6 +505,57 @@
}
}
},
"Volo.CmsKit.Public.Polls.PollViewComponentController": {
"controllerName": "PollViewComponent",
"controllerGroupName": "PollViewComponent",
"isRemoteService": true,
"apiVersion": null,
"type": "Volo.CmsKit.Public.Polls.PollViewComponentController",
"interfaces": [
{
"type": "Volo.CmsKit.Public.Polls.IPollViewComponentAppService"
}
],
"actions": {
"ParseAsyncByContent": {
"uniqueName": "ParseAsyncByContent",
"name": "ParseAsync",
"httpMethod": "GET",
"url": "api/cms-kit-public/polls/{content}",
"supportedVersions": [],
"parametersOnMethod": [
{
"name": "content",
"typeAsString": "System.String, System.Private.CoreLib",
"type": "System.String",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null
}
],
"parameters": [
{
"nameOnMethod": "content",
"name": "content",
"jsonName": null,
"type": "System.String",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null,
"constraintTypes": [],
"bindingSourceId": "Path",
"descriptorName": ""
}
],
"returnValue": {
"type": "System.Collections.Generic.List<Volo.CmsKit.Polls.ContentFragment>",
"typeSimple": "[Volo.CmsKit.Polls.ContentFragment]"
},
"allowAnonymous": null,
"implementFrom": "Volo.CmsKit.Public.Polls.IPollViewComponentAppService"
}
}
},
"Volo.CmsKit.Public.Pages.PagesPublicController": {
"controllerName": "PagesPublic",
"controllerGroupName": "PagesPublic",
@ -989,6 +1040,18 @@
"bindingSourceId": "ModelBinding",
"descriptorName": "input"
},
{
"nameOnMethod": "input",
"name": "TagId",
"jsonName": null,
"type": "System.Guid?",
"typeSimple": "string?",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "ModelBinding",
"descriptorName": "input"
},
{
"nameOnMethod": "input",
"name": "Sorting",

27
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs

@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.CmsKit.Polls;
namespace Volo.CmsKit.Public.Polls;
[RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)]
[Area(CmsKitPublicRemoteServiceConsts.ModuleName)]
[Route("api/cms-kit-public/polls")]
public class PollViewComponentController : CmsKitPublicControllerBase, IPollViewComponentAppService
{
protected IPollViewComponentAppService PollViewComponentAppService { get; }
public PollViewComponentController(IPollViewComponentAppService pollViewComponentAppService)
{
PollViewComponentAppService = pollViewComponentAppService;
}
[HttpGet]
[Route("{content}")]
public virtual Task<List<ContentFragment>> ParseAsync(string content)
{
return PollViewComponentAppService.ParseAsync(content);
}
}

18
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs

@ -1,18 +0,0 @@
using System.Collections.Generic;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class CmsKitContentWidgetOptions
{
public Dictionary<string, ContentWidgetConfig> WidgetConfigs { get; }
public CmsKitContentWidgetOptions()
{
WidgetConfigs = new();
}
public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig)
{
WidgetConfigs.Add(name, contentWidgetConfig);
}
}

6
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs

@ -1,6 +0,0 @@
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public abstract class ContentFragment
{
}

14
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs

@ -1,14 +0,0 @@
using System;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class ContentWidgetConfig
{
public string Name { get; }
public Type ViewComponentType { get; set; }
public ContentWidgetConfig(string name)
{
Name = name;
}
}

2
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml

@ -1,8 +1,8 @@
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@using Volo.CmsKit.Polls
@using Volo.CmsKit.Public.Web.Renderers
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@inject IMarkdownToHtmlRenderer MarkdownRenderer

13
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
using Volo.CmsKit.Public.Polls;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
@ -22,20 +23,20 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
})]
public class DefaultPageViewComponent : AbpViewComponent
{
private readonly IContentParser _contentParser;
protected IPollViewComponentAppService PollViewComponentAppService { get; set; }
public DefaultPageViewComponent(IContentParser contentParser)
public DefaultPageViewComponent(IPollViewComponentAppService pollViewComponentAppService)
{
_contentParser = contentParser;
PollViewComponentAppService = pollViewComponentAppService;
}
public virtual async Task<IViewComponentResult> InvokeAsync(
Guid pageId,
string title,
string content)
{
var contentFragments = await _contentParser.ParseAsync(content);
var contentFragments = await PollViewComponentAppService.ParseAsync(content);
var model = new PageViewModel
{
Id = pageId,

6
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs

@ -1,6 +0,0 @@
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class MarkdownContentFragment : ContentFragment
{
public string Content { get; set; }
}

1
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Volo.CmsKit.Polls;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;

18
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs

@ -1,18 +0,0 @@
using System.Collections.Generic;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class WidgetContentFragment : ContentFragment
{
public string Name { get; }
public string ViewComponentName { get; set; }
public IDictionary<string, object> Properties { get; }
public WidgetContentFragment(string name)
{
Name = name;
Properties = new Dictionary<string, object>();
}
}

1
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml

@ -1,5 +1,6 @@
@page
@using Volo.CmsKit.Polls
@using Volo.CmsKit.Public.Blogs
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment
@using Volo.CmsKit.Public.Web.Pages

12
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs

@ -4,6 +4,7 @@ using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Public.Blogs;
using Volo.CmsKit.Public.Polls;
namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
@ -31,24 +32,23 @@ public class BlogPostModel : CmsKitPublicPageModelBase
protected IBlogFeatureAppService BlogFeatureAppService { get; }
private readonly IContentParser _contentParser;
protected IPollViewComponentAppService PollViewComponentAppService { get; }
public BlogPostModel(
IBlogPostPublicAppService blogPostPublicAppService,
IBlogFeatureAppService blogFeaturePublicAppService
,
IContentParser contentParser)
IBlogFeatureAppService blogFeaturePublicAppService,
IPollViewComponentAppService pollViewComponentAppService)
{
BlogPostPublicAppService = blogPostPublicAppService;
BlogFeatureAppService = blogFeaturePublicAppService;
_contentParser = contentParser;
PollViewComponentAppService = pollViewComponentAppService;
}
public virtual async Task OnGetAsync()
{
BlogPost = await BlogPostPublicAppService.GetAsync(BlogSlug, BlogPostSlug);
BlogPost.ContentFragments = await _contentParser.ParseAsync(BlogPost.Content);
BlogPost.ContentFragments = await PollViewComponentAppService.ParseAsync(BlogPost.Content);
if (GlobalFeatureManager.Instance.IsEnabled<CommentsFeature>())
{

96
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs

@ -1,96 +0,0 @@
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<CmsKitContentWidgetOptions> options)
{
_options = options.Value;
}
public async Task<List<ContentFragment>> ParseAsync(string content)
{
if (!_options.WidgetConfigs.Any())
{
return new List<ContentFragment>()
{
new MarkdownContentFragment() { Content = content }
};
}
var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter);
var parsedList = new List<string>();
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<ContentFragment>();
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;
}
}

10
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs

@ -1,10 +0,0 @@
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<List<ContentFragment>> ParseAsync(string content);
}
Loading…
Cancel
Save