1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-25 17:23:00 +00:00

feature-readingtime: improve algorithm by stripping markdown syntax

This commit is contained in:
Starbeamrainbowlabs 2020-08-11 15:46:34 +01:00
parent e7bdaed679
commit b1381552f0
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -1,7 +1,7 @@
<?php <?php
register_module([ register_module([
"name" => "Reading time estimator", "name" => "Reading time estimator",
"version" => "0.1", "version" => "0.2",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Displays the approximate reading time for a page beneath it's title.", "description" => "Displays the approximate reading time for a page beneath it's title.",
"id" => "feature-readingtime", "id" => "feature-readingtime",
@ -44,7 +44,10 @@ register_module([
* @return array An array in the form [ low_time, high_time ] in minutes * @return array An array in the form [ low_time, high_time ] in minutes
*/ */
function estimate_reading_time(string $text, string $lang = "en") : array { function estimate_reading_time(string $text, string $lang = "en") : array {
$chars_count = mb_strlen($text); $chars_count = mb_strlen(preg_replace("/\s+?/", "", strtr($text, [
"[" => "", "]" => "", "(" => "", ")" => "",
"|" => "", "#" => "", "*" => ""
])));
$langs = [ $langs = [
"en" => (object) [ "cpm" => 987, "variance" => 118 ], "en" => (object) [ "cpm" => 987, "variance" => 118 ],
"ar" => (object) [ "cpm" => 612, "variance" => 88 ], "ar" => (object) [ "cpm" => 612, "variance" => 88 ],