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 11@using System .Net
2+ @using System .Text .RegularExpressions
23@using System .Web
34@using LinkDotNet .Blog .Domain
45@inherits MarkdownComponentBase
1920 </ul >
2021 </li >
2122 }
23+ <li class =" read-time" >@readTime min</li >
2224 </ul >
2325 </div >
2426 <div class =" description" >
4042 public bool UseAlternativeStyle { get ; set ; }
4143
4244 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+
4370}
Original file line number Diff line number Diff line change 8282.blog-card .details .tags li {
8383 margin-right : 2px ;
8484}
85- .blog-card .details .tags li : first-child {
86- margin-left : -4px ;
87- }
85+
8886.blog-card .description {
8987 padding : 1rem ;
9088 background : # fff ;
117115 margin-left : 5px ;
118116 opacity : 1 ;
119117}
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+
120126.blog-card p {
121127 position : relative;
122128 margin : 1rem 0 0 ;
You can’t perform that action at this time.
0 commit comments