File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
src/LinkDotNet.Blog.Web/Shared Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 1
1
@using System .Net
2
+ @using System .Text .RegularExpressions
2
3
@using System .Web
3
4
@using LinkDotNet .Blog .Domain
4
5
@inherits MarkdownComponentBase
19
20
</ul >
20
21
</li >
21
22
}
23
+ <li class =" read-time" >@readTime min</li >
22
24
</ul >
23
25
</div >
24
26
<div class =" description" >
40
42
public bool UseAlternativeStyle { get ; set ; }
41
43
42
44
private string AltCssClass => UseAlternativeStyle ? " alt" : string .Empty ;
45
+
46
+ private int readTime ;
47
+
48
+ protected override void OnInitialized ()
49
+ {
50
+ var images = GetAllOccurrences (RenderMarkupString (BlogPost .Content ).Value , " <img" );
51
+ var words = BlogPost .Content .Split (Array .Empty <char >(), StringSplitOptions .RemoveEmptyEntries ).Length ;
52
+
53
+ var readTimeInPrecision = images * 15 + words / 3 . 333 ;
54
+ readTime = (int )Math .Floor (readTimeInPrecision / 60 );
55
+ }
56
+
57
+ private int GetAllOccurrences (string text , string lookup )
58
+ {
59
+ var currentPosition = - 1 ;
60
+ var count = 0 ;
61
+
62
+ while ((currentPosition = text .IndexOf (lookup , currentPosition + 1 , StringComparison .Ordinal )) != - 1 )
63
+ {
64
+ count ++ ;
65
+ }
66
+
67
+ return count ;
68
+ }
69
+
43
70
}
Original file line number Diff line number Diff line change 82
82
.blog-card .details .tags li {
83
83
margin-right : 2px ;
84
84
}
85
- .blog-card .details .tags li : first-child {
86
- margin-left : -4px ;
87
- }
85
+
88
86
.blog-card .description {
89
87
padding : 1rem ;
90
88
background : # fff ;
117
115
margin-left : 5px ;
118
116
opacity : 1 ;
119
117
}
118
+
119
+ .blog-card .read-time : before {
120
+ font-family : "Font Awesome 5 Free" ;
121
+ font-weight : 900 ;
122
+ margin-right : 10px ;
123
+ content : "\f017" ;
124
+ }
125
+
120
126
.blog-card p {
121
127
position : relative;
122
128
margin : 1rem 0 0 ;
You can’t perform that action at this time.
0 commit comments