mirror of
https://github.com/danpros/htmly.git
synced 2026-04-18 19:46:21 +05:30
Teaser break handling. See #693
This commit is contained in:
parent
3125dc0703
commit
95f7afe950
1 changed files with 25 additions and 19 deletions
|
|
@ -678,7 +678,6 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0)
|
|||
$word_count = str_word_count(strip_tags($post->body));
|
||||
$post->readTime = ceil($word_count / 200);
|
||||
|
||||
|
||||
$toc = explode('<!--toc-->', $post->body);
|
||||
if (isset($toc['1'])) {
|
||||
$post->body = insert_toc('subpage-' . $post->slug, $toc['0'], $toc['1']);
|
||||
|
|
@ -1201,7 +1200,6 @@ function get_author($name)
|
|||
}
|
||||
|
||||
$author->body = $author->about;
|
||||
|
||||
$author->title = $author->name;
|
||||
|
||||
$tmp[] = $author;
|
||||
|
|
@ -2211,16 +2209,22 @@ function get_teaser($string, $url = null, $char = null)
|
|||
} else {
|
||||
return $string;
|
||||
}
|
||||
} else {
|
||||
$readMore = explode('<!--more-->', $string);
|
||||
if (isset($readMore['1'])) {
|
||||
$string = shorten($readMore[0]);
|
||||
return $string;
|
||||
} else {
|
||||
$string = shorten($string, $char);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shorten the string
|
||||
function shorten($string = null, $char = null)
|
||||
{
|
||||
if(empty($char) || empty($string)) {
|
||||
if(empty($string)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -2237,10 +2241,12 @@ function shorten($string = null, $char = null)
|
|||
$string = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', mb_convert_encoding($dom->saveHTML($dom->documentElement), 'UTF-8'));
|
||||
$string = preg_replace('/\s\s+/', ' ', strip_tags($string));
|
||||
$string = ltrim(rtrim($string));
|
||||
if (!empty($char)) {
|
||||
if (strlen($string) > $char) {
|
||||
$string = substr($string, 0, $char);
|
||||
$string = substr($string, 0, strrpos($string, ' '));
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue