summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorEltrac Koalar <hi@guhub.cn>2022-09-24 23:54:29 +0800
committerEltrac Koalar <hi@guhub.cn>2022-09-24 23:54:29 +0800
commitdb86bb4726d28d679e425d09e5b98672ede1ac10 (patch)
tree9add9672c7d4ecaff70f25e7ae61444937a47dc5 /libs
parent812c284d66134819eccc25a821e275e4bfcd36a6 (diff)
:newspaper: Add: 新增首页「相关链接」功能
Diffstat (limited to 'libs')
-rw-r--r--libs/Matcha.php48
-rw-r--r--libs/Options.php14
2 files changed, 60 insertions, 2 deletions
diff --git a/libs/Matcha.php b/libs/Matcha.php
index b0bf12c..c968410 100644
--- a/libs/Matcha.php
+++ b/libs/Matcha.php
@@ -223,7 +223,7 @@ class Matcha
public static function excerpt(Widget_Archive $archive)
{
if(Helper::options()->IndexDisplayMode=='FullText'){
- $archive->content('');
+ $archive->content('继续阅读');
}
elseif(Helper::options()->IndexDisplayMode=='Excerpt200'){
$archive->excerpt(200);
@@ -443,7 +443,8 @@ class Matcha
/**
* 主题色
*/
- public static function getThemeColor() {
+ public static function getThemeColor()
+ {
if(Helper::options()->themeColor=='maple'){
return '#E95A2D';
}
@@ -463,4 +464,47 @@ class Matcha
return '#c5c56a';
}
}
+
+ /**
+ * 首页相关链接
+ */
+ public static function relatedLinks($archives)
+ {
+ $data = '['.Helper::options()->relatedLinks.']';
+ if($data!=''){
+ $data=json_decode($data, true);
+ foreach($data as $item){
+ echo '<div class="indexlink-item">';
+
+ //如果是文章
+ if($item['type']=='post') {
+ if(!isset($item['cid'])) {
+ echo '没有设置 cid,请检查你的设置';
+ return false;
+ }
+ $archives->widget('Widget_Archive@indexxiu', 'pageSize=1&type=post', 'cid='.$item['cid'])->to($post);
+ echo '<a href="'.$post->permalink.'">
+ <h2>'.$post->title.'</h2>
+ <p>';
+ $post->excerpt(30);
+ echo '</p>
+ </a>';
+ }
+ //如果是自定义链接
+ else {
+ if(!isset($item['title']) || !isset($item['des']) || !isset($item['link'])) {
+ echo '信息设置不完整,请检查你的设置';
+ return false;
+ }
+ echo '<a href="'.$item['link'].'" target="_blank">
+ <h2>'.$item['title'].'</h2>
+ <p>'.$item['des'].'</p>
+ </a>';
+ }
+
+ echo '</div>';
+ }
+ }
+ return false;
+ }
} \ No newline at end of file
diff --git a/libs/Options.php b/libs/Options.php
index 43180e0..76419d3 100644
--- a/libs/Options.php
+++ b/libs/Options.php
@@ -10,6 +10,11 @@ function themeConfig($form) {
* 基本信息
*/
+ echo '<div style="border:1px solid #ddd;background:#eee;padding:1em;margin-top:1em">
+ <h1 style="margin:0;font-weight:600">Matcha 主题配置</h1>
+ <p style="line-height:1.5;margin:0">主题配置有关的说明请查看<a href="https://matcha.guhub.cn/">说明文档</a></p>
+ </div>';
+
//主题色
$themeColor = new Typecho_Widget_Helper_Form_Element_Radio('themeColor', array(
'matcha' => _t('抹茶绿'),
@@ -115,6 +120,15 @@ function themeConfig($form) {
);
$form->addInput($EnableBusuanzi->addRule('required', _t('此处必须设置')));
+
+ //首页相关链接
+ $relatedLinksTitle = new Typecho_Widget_Helper_Form_Element_Text('relatedLinksTitle', NULL, NULL, _t('首页「相关链接」标题'), _t('
+ <p class="description">下一个设置项不留空则生效,自定义相关链接之前显示的标题</p>'));
+ $form->addInput($relatedLinksTitle);
+ $relatedLinks = new Typecho_Widget_Helper_Form_Element_Textarea('relatedLinks', NULL, NULL, _t('首页「相关链接」内容'), _t('
+ <p class="description">使用特定的 JSON 格式书写,可以在首页文章目录之前展示一个相关链接版块,详情请查看说明文档</p><hr>'));
+ $form->addInput($relatedLinks);
+
/**
* 自定义
*/