diff options
| author | Eltrac Koalar <hi@guhub.cn> | 2022-10-02 21:38:09 +0800 |
|---|---|---|
| committer | Eltrac Koalar <hi@guhub.cn> | 2022-10-02 21:38:09 +0800 |
| commit | bf285ac1dee6be5f9c7961549dd904c2f9066094 (patch) | |
| tree | 3e5c6e37fda122beb4b0eb7e6e47d41e6d3fa84a | |
| parent | 2cac9513aac057fc586dd928446fe5a9a66c1a99 (diff) | |
:newspaper: Add: 加入 <!--less--> 标签
| -rw-r--r-- | functions.php | 2 | ||||
| -rw-r--r-- | libs/Matcha.php | 29 |
2 files changed, 27 insertions, 4 deletions
diff --git a/functions.php b/functions.php index 5a2f7ff..54773b7 100644 --- a/functions.php +++ b/functions.php @@ -11,7 +11,7 @@ require_once('libs/Options.php'); require_once('libs/Comments.php'); Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('Matcha','parseContent'); -Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('Matcha','parseContent'); +Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('Matcha','parseExcerpt'); function themeInit($archive) { Helper::options()->commentsAntiSpam = false; //关闭反垃圾 diff --git a/libs/Matcha.php b/libs/Matcha.php index c3d76e9..1ec3c39 100644 --- a/libs/Matcha.php +++ b/libs/Matcha.php @@ -307,7 +307,7 @@ class Matcha /** * LazyLoad */ - static public function lazyLoad($text){ + static public function parseLazyLoad($text){ $text = preg_replace( '/\<img(.*?)src=\"(.*?)\"(.*?)alt=\"(.*?)\"(.*?)\>/s', '<figure><a href="${2}" class="fluidbox-anchor" no-linkTarget><img${1}src="'.Utils::indexThemeUrl('assets/loading.gif').'" data-src="${2}"${3}class="lazy"${4}></a><figcaption>${3}</figcaption></figure>', @@ -318,7 +318,7 @@ class Matcha /** * 为文章标题添加id */ - static public function tocbot($text){ + static public function parseTocbot($text){ $text = preg_replace( '/\<h(2|3)(.*?)\>(.*?)\<\/h(2|3)\>/s', '<h${1}${2} id="heading-${3}">${3}</h${1}>', @@ -327,13 +327,36 @@ class Matcha } /** + * <!--less--> + */ + static public function parseLess($text){ + $text = preg_replace( + '/(.*?)\<\!\-\-less\-\-\>(.*?)/s', + '${2}', + $text); + return $text; + } + + /** * 解析文章内容 */ static public function parseContent($data, $widget, $last) { $text = empty($last) ? $data : $last; if ($widget instanceof Widget_Archive) { - $text = Matcha::tocbot(Matcha::lazyLoad($text)); + $text = Matcha::parseTocbot(Matcha::parseLazyLoad($text)); + } + return $text; + } + + /** + * 解析摘要内容 + */ + static public function parseExcerpt($data, $widget, $last) + { + $text = empty($last) ? $data : $last; + if ($widget instanceof Widget_Archive) { + $text = Matcha::parseLess(Matcha::parseTocbot(Matcha::parseLazyLoad($text))); } return $text; } |
