-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
32 lines (29 loc) · 1.31 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php namespace x\excerpt;
function page__content($content) {
if (!$content) {
return $content;
}
$exist = \strpos($content, "\f") ?: \strpos($content, '') ?: \stripos($content, '');
if (!$exist) {
return $content;
}
// Normalize `` and `` to a literal `\f`. Also, remove the surrounding HTML element if any (usually a paragraph element)
return \preg_replace('/\s*<([\w:-]+)(?:\s[^>]*)?>\s*(?:[\f]|&#(?:12|x[cC]);)\s*<\/\1>\s*|\s*(?:[\f]|&#(?:12|x[cC]);)\s*/', "\f", $content);
}
function page__excerpt($excerpt) {
// `excerpt` data has been set
if ($excerpt) {
return $excerpt; // Return the initial value
}
$content = $this->content ?? "";
$exist = \strpos($content, "\f");
// Page’s `content` is empty or excerpt marker does not exist, return the page’s `description`
if (!$content || !$exist) {
// If page’s `description` is empty, create a fake excerpt generated by the page’s `content`
return '<p>' . ($this->description ?? \To::description((string) $content)) . '</p>';
}
$content = \trim(\substr($content, 0, $exist));
return "" !== $content ? $content : null;
}
\Hook::set('page.content', __NAMESPACE__ . "\\page__content", 2.1);
\Hook::set('page.excerpt', __NAMESPACE__ . "\\page__excerpt", 2.1);