Add a few small features to the blog
Shududu is blogging again.
As a code illiterate (roughly equivalent to the illiterate who has read a book for one year), he always likes to toss about his blog. Fortunately, he has a powerful search engine and can basically realize the functions he needs. Thanks to these sharing friends, shududu put these two methods together, which is called carrying and integration.
Add word count and reading time prompt
This function is also found on @ foleap blog. I'm afraid of being bothered by others. I'm sorry to ask.
The process of searching is maddening. I don't know what key words to use. The idea is very simple. First I count the words of the article, then I divide it by 350 (general reading speed), and I find the way to count the words, but I don't know how to calculate them. I can't get them from the comparison course. I just need to find another way.
The implementation method is quite special. The word count and reading time calculation use different methods to calculate the word count, which is quite funny.
1. Word count:
Without function, add the following code [1] directly to the number of words to be displayed:
In this paper, PHP echo (string) MB strlen (STR replace (PHP EOL, "', String Tags ($this content)),'utf-8');"
2. Estimate the time required to read the text [2]. Insert the following code into the foot.php file
Script type = text/JavaScript $(document). Ready (function() {var read time = $(' content'). Text(). Length;// get the content of the article and calculate the word number var read time = read time/400;// calculate the reading time var read time = math. Round (read );// round to the nearest if (read time) {$(' read-time'). HTML ('expected reading time: '+ read time +' minute '); }Else {$('?read-time'). HTML ('expected reading time: 1 minute ');}})/script
Then call span id = read time/span where you need to. What I need to pay attention to here is that I specially added a container, div ID content, to the article
See this article for the effect. I wonder if the words counted by the two are the same. Is there a better way to achieve it?
Reference material
Typecho gets the number of words in the article jQuery calculates the expected reading time of the article
Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/netweb/Add-a-few-small-features-to-the-blog.htm