Browse Source

Removed duplication

pull/13082/head
malik masis 4 years ago
parent
commit
3de1f919d8
  1. 23
      modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs
  2. 109
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
  3. 24
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml

23
modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs

@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Dynamic;
namespace Volo.CmsKit.Web.Contents;
public static class Helper
{
public static dynamic ConvertToDynamicObject(this Dictionary<string, object> dict)
{
var eo = new ExpandoObject();
var eoColl = (ICollection<KeyValuePair<string, object>>)eo;
foreach (var kvp in dict)
{
eoColl.Add(kvp);
}
dynamic eoDynamic = eo;
return eoDynamic;
}
}

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

@ -12,6 +12,8 @@
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Tags @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Tags
@using Volo.CmsKit.Public.Web.Renderers @using Volo.CmsKit.Public.Web.Renderers
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs @using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs
@using Volo.CmsKit.Contents
@using Volo.CmsKit.Web.Contents;
@inherits CmsKitPublicPageBase @inherits CmsKitPublicPageBase
@ -26,57 +28,57 @@
} }
@section styles{ @section styles{
@if (isScrollIndexEnabled) @if (isScrollIndexEnabled)
{ {
<abp-abp-style-bundle> <abp-abp-style-bundle>
<abp-style src="/Pages/Public/CmsKit/Blogs/bootstrap-toc.css"/> <abp-style src="/Pages/Public/CmsKit/Blogs/bootstrap-toc.css" />
</abp-abp-style-bundle> </abp-abp-style-bundle>
} }
<abp-abp-style-bundle> <abp-abp-style-bundle>
<abp-style src="/Pages/Public/CmsKit/Blogs/blogPost.css"/> <abp-style src="/Pages/Public/CmsKit/Blogs/blogPost.css" />
<abp-style type="typeof(HighlightJsStyleContributor)"/> <abp-style type="typeof(HighlightJsStyleContributor)" />
</abp-abp-style-bundle> </abp-abp-style-bundle>
} }
@section scripts{ @section scripts{
@if (isScrollIndexEnabled) @if (isScrollIndexEnabled)
{ {
<abp-script-bundle> <abp-script-bundle>
<abp-style src="/Pages/Public/CmsKit/Blogs/bootstrap-toc.js"/> <abp-style src="/Pages/Public/CmsKit/Blogs/bootstrap-toc.js" />
<abp-script src="/Pages/Public/CmsKit/Blogs/blogpost-scroll-index.js"/> <abp-script src="/Pages/Public/CmsKit/Blogs/blogpost-scroll-index.js" />
</abp-script-bundle> </abp-script-bundle>
} }
<abp-script-bundle> <abp-script-bundle>
<abp-script type="typeof(HighlightJsScriptContributor)"/> <abp-script type="typeof(HighlightJsScriptContributor)" />
<abp-script src="/Pages/Public/CmsKit/highlightOnLoad.js"/> <abp-script src="/Pages/Public/CmsKit/highlightOnLoad.js" />
</abp-script-bundle> </abp-script-bundle>
} }
<div class="row"> <div class="row">
<div @Html.Raw(isScrollIndexEnabled ? "class=\"col-md-10 col-sm-12\"" : "class=\"col-md-12\"")> <div @Html.Raw(isScrollIndexEnabled ? "class=\"col-md-10 col-sm-12\"" : "class=\"col-md-12\"")>
<abp-card class="mb-4"> <abp-card class="mb-4">
<img src="/api/cms-kit/media/@Model.BlogPost.CoverImageMediaId" class="card-img-top" onerror="this.src='@dummyImageSource'"/> <img src="/api/cms-kit/media/@Model.BlogPost.CoverImageMediaId" class="card-img-top" onerror="this.src='@dummyImageSource'" />
<abp-card-body> <abp-card-body>
<abp-row> <abp-row>
<div class="col-lg-8 col-md-10 mx-auto pb-4"> <div class="col-lg-8 col-md-10 mx-auto pb-4">
<h1 class="mt-lg-4 mt-md-3">@Model.BlogPost.Title</h1> <h1 class="mt-lg-4 mt-md-3">@Model.BlogPost.Title</h1>
<p class="mb-lg-5 mb-md-3"> <p class="mb-lg-5 mb-md-3">
<a href="/blogs/@Model.BlogSlug?authorId=@Model.BlogPost.Author.Id"> <a href="/blogs/@Model.BlogSlug?authorId=@Model.BlogPost.Author.Id">
<span class="font-weight-bold">@@@Model.BlogPost.Author?.UserName</span> <span class="font-weight-bold">@@@Model.BlogPost.Author?.UserName</span>
</a> </a>
<small style="opacity:.65;">@Model.BlogPost.CreationTime</small> <small style="opacity:.65;">@Model.BlogPost.CreationTime</small>
</p> </p>
@foreach (var contentFragment in Model.BlogPost.ContentFragments) @foreach (var contentFragment in Model.BlogPost.ContentFragments)
{ {
if (contentFragment.Type == "Markdown") //TODO: Constant if (contentFragment.Type == ContentConsts.Markdown)
{ {
@Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty<string>("Content"))) @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty<string>("Content")))
} }
else if (contentFragment.Type == "Widget") //TODO: Constant else if (contentFragment.Type == ContentConsts.Widget)
{ {
@await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties)) @await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), contentFragment.ExtraProperties.ConvertToDynamicObject())
} }
} }
<p class="mb-3"> <p class="mb-3">
@ -85,18 +87,18 @@
<small style="opacity:.65;">@L["LastModification"].Value : @Model.BlogPost.LastModificationTime</small> <small style="opacity:.65;">@L["LastModification"].Value : @Model.BlogPost.LastModificationTime</small>
} }
</p> </p>
<hr/> <hr />
@if (GlobalFeatureManager.Instance.IsEnabled<TagsFeature>()) @if (GlobalFeatureManager.Instance.IsEnabled<TagsFeature>())
{ {
if (Model.TagsFeature?.IsEnabled == true) if (Model.TagsFeature?.IsEnabled == true)
{ {
@await Component.InvokeAsync(typeof(TagViewComponent), new @await Component.InvokeAsync(typeof(TagViewComponent), new
{ {
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString(), entityId = Model.BlogPost.Id.ToString(),
urlFormat = $"/blogs/{Model.BlogSlug}?tagId={{TagId}}" urlFormat = $"/blogs/{Model.BlogSlug}?tagId={{TagId}}"
}) })
} }
} }
</div> </div>
@ -109,10 +111,10 @@
if (Model.ReactionsFeature?.IsEnabled == true) if (Model.ReactionsFeature?.IsEnabled == true)
{ {
@await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new @await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new
{ {
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString() entityId = Model.BlogPost.Id.ToString()
}) })
} }
} }
</abp-column> </abp-column>
@ -122,10 +124,10 @@
if (Model.RatingsFeature?.IsEnabled == true) if (Model.RatingsFeature?.IsEnabled == true)
{ {
@await Component.InvokeAsync(typeof(RatingViewComponent), new @await Component.InvokeAsync(typeof(RatingViewComponent), new
{ {
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString() entityId = Model.BlogPost.Id.ToString()
}) })
} }
} }
</abp-column> </abp-column>
@ -164,21 +166,4 @@
entityId = Model.BlogPost.Id.ToString() entityId = Model.BlogPost.Id.ToString()
}) })
} }
}
@{
dynamic ConvertToDynamicObject(Dictionary<string, object> dict)
{
var eo = new ExpandoObject();
var eoColl = (ICollection<KeyValuePair<string, object>>)eo;
foreach (var kvp in dict)
{
eoColl.Add(kvp);
}
dynamic eoDynamic = eo;
return eoDynamic;
}
} }

24
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml

@ -7,6 +7,8 @@
@using Volo.Abp.Data @using Volo.Abp.Data
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs; @using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs;
@using Volo.Abp.AspNetCore.Mvc.UI.Widgets; @using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
@using Volo.CmsKit.Web.Contents;
@inject IMarkdownToHtmlRenderer MarkdownRenderer @inject IMarkdownToHtmlRenderer MarkdownRenderer
@ -33,31 +35,15 @@
<abp-card-body> <abp-card-body>
@foreach (ContentFragment contentFragment in Model.PageDto.ContentFragments) @foreach (ContentFragment contentFragment in Model.PageDto.ContentFragments)
{ {
if (contentFragment.Type == "Markdown") //TODO: Constant if (contentFragment.Type == ContentConsts.Markdown)
{ {
@Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty<string>("Content"))) @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty<string>("Content")))
} }
else if (contentFragment.Type == "Widget") //TODO: Constant else if (contentFragment.Type == ContentConsts.Widget)
{ {
@await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties)) @await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), contentFragment.ExtraProperties.ConvertToDynamicObject())
} }
} }
</abp-card-body> </abp-card-body>
</abp-card> </abp-card>
@{
dynamic ConvertToDynamicObject(Dictionary<string, object> dict)
{
var eo = new ExpandoObject();
var eoColl = (ICollection<KeyValuePair<string, object>>)eo;
foreach (var kvp in dict)
{
eoColl.Add(kvp);
}
dynamic eoDynamic = eo;
return eoDynamic;
}
}
Loading…
Cancel
Save