mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
feature-readingtime: improve algorithm by stripping markdown syntax
This commit is contained in:
parent
e7bdaed679
commit
b1381552f0
1 changed files with 5 additions and 2 deletions
|
@ -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 ],
|
||||||
|
|
Loading…
Reference in a new issue