Skip to content

Commit 6613b64

Browse files
committed
Couple of minor updates including adding the namespace.
1 parent 793d097 commit 6613b64

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

source/DasBlog.Web.UI/TagHelpers/Post/PostReadTimeTagHelper.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using DasBlog.Web.Models.BlogViewModels;
33
using Microsoft.AspNetCore.Razor.TagHelpers;
44
using System;
5-
using System.Linq;
5+
using System.Text.RegularExpressions;
66

77
namespace DasBlog.Web.TagHelpers.Post
88
{
@@ -20,19 +20,12 @@ public PostReadTimeTagHelper(IDasBlogSettings dasBlogSettings)
2020

2121
public override void Process(TagHelperContext context, TagHelperOutput output)
2222
{
23+
var rx = new Regex(@"<img.*?src="".*?"".*?>");
24+
var numberImages = rx.Matches(Post.Content).Count;
2325

24-
string pattern = @"<img.*?src="".*?"".*?>";
25-
Regex rx = new Regex(pattern);
26-
var numberImages = string.Empty;
27-
foreach(Match m in rx.Matches(Post.Content))
28-
{
29-
var numberImages = m.Count;
30-
}
31-
32-
var imgMinutes = (numberImages*30)/60;
26+
var imgMinutes = (double)(numberImages*30)/60;
3327
var delimiters = new char[] { ' ', '\r', '\n' };
34-
var minute = Math.Round((double)dasBlogSettings.FilterHtml(Post.Content).Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Length / 200) + imgMinutes;
35-
28+
var minute = Math.Round((double)dasBlogSettings.FilterHtml(Post.Content).Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Length / 200) + Math.Round(imgMinutes, MidpointRounding.AwayFromZero);
3629
output.TagName = "span";
3730
output.TagMode = TagMode.StartTagAndEndTag;
3831
output.Attributes.SetAttribute("class", "dbc-post-readtime");

0 commit comments

Comments
 (0)