poppastring / dasblog-core

The original DasBlog reimagined with ASP.NET Core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve the word count Tag helper to include images.

poppastring opened this issue · comments

The <post-read-time /> TagHelper is used to calculate the number of minutes we guess it will take to read the article. This calculation uses a simple arithmetic around the number of words Post.Content.

There is a hypothesis that suggests we should also include 30 seconds per image in the post.

The task here is to find the number of images in Post.Content and add it to the number of minutes calculated on line 24 in the following TagHelper:

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

Hello @poppastring,

Happy open-source-friday!

I hope you are doing well.

I was wondering if I can get this issue and solve it. I am pretty new in web development, so I might take some time. But, I am looking into it and hope to come up with a solution shortly.

Thanks!

Kind regards,
Thais

@tsdamas Please feel free to take this on :)
I will assign it to you, but take your time and please reach out if you have need any assistance.

Thanks @poppastring!!

As I said, I am pretty new in C#, so I think I might have a solution. But I would like to check with you first, if I am in the right path, if possible:
var images = dasBlogSettings.Post.Content.HtmlTagContext(img).Count();
var imgMinutes = images*30/60;

Thank you in advance,
Thais

Hey @tsdamas

I do not think this will need a change to dasBlogSettings unless we decide this image count needs to be elsewhere in code. All your changes should be here: \source\DasBlog.Web.UI\TagHelpers\Post\PostReadTimeTagHelper.cs

However, we should do something with post.Content. Ultimately, we need to count the number of images found in this property. I am assuming we do that with Regex but I am open to other solutions. The last imgMinutes line looks right and should be added to the existing minutes calculation in the TagHelper.

We can continue to discuss here but also feel free to send me a PR and I will do a code review.

Hey @poppastring

Thank you very much for clarifying! I believe I got into a possible solution.

I will do a PR for your review.