date()->toDate('Y/m/d'); return '/' . $date .'/' . $this->slug(); } /** * Simple function for estimating the reading time of the article. * * The algorithm counts all words in p-Elements and divides them by * words-per-minute amount defined in WORDS_PER_MINUTES. It outputs the * text defined in READING_TIME_FORMAT containing the estimated word count * and estimated reading time. * * @return string Text with estimated reading time. */ public function readingTime(): string { // After requiring PHP 8.4 or higher, replace DOMDocument with // DOM/HTMLDocument and remove the LIBXML_NOERROR option. This option // is only needed because DOMDocument only supports HTML4 and // therefore throws warnings for HTML5 tags. $doc = new DOMDocument(); $doc->loadHTML( '
' . $this->text()->kirbytext() . '', LIBXML_NOERROR ); $pElems = $doc->getElementsByTagName('p'); $text = ''; foreach ($pElems as $pElem) { $text .= $pElem->nodeValue . ' '; } $wordCount = count(explode(' ', $text)); $readingTime = (int)ceil($wordCount / self::WORDS_PER_MINUTE); return sprintf(self::READING_TIME_FORMAT, $wordCount, $readingTime); } }