26 Commits

Author SHA1 Message Date
浪子 a006880f58 0.5.6 2024-07-16 18:15:23 +08:00
浪子 a065f44da4 fix 目录样式 2024-07-16 16:43:09 +08:00
浪子 372828a290 1.5.6 2024-07-08 19:59:04 +08:00
浪子 87be98f196 0.5.6 2024-07-06 09:09:42 +08:00
浪子 4ab2a62d99 none 2024-07-06 09:08:32 +08:00
浪子 1aad58e012 Update post.php 2024-07-05 16:47:48 +08:00
浪子 09e8e9e8a5 fix toc 2024-07-05 09:53:04 +08:00
浪子 ce9ae76e8a fix 2024-07-05 09:00:34 +08:00
浪子 d1e6567cc9 add 分类图片获取 2024-07-04 20:02:06 +08:00
浪子 2b595583c1 Update index.php 2024-07-01 18:34:20 +08:00
浪子 296ea94340 正确获取昵称 2024-06-27 15:37:29 +08:00
浪子 0c72f67d8e 调整图片显示 2024-06-20 09:38:13 +08:00
浪子 ffe4db83de 调整图片 2024-06-20 08:22:58 +08:00
浪子 65d780c01a Update page-memos.php 2024-06-16 11:09:22 +08:00
浪子 6165bacaa9 Update page-memos.php 2024-06-16 10:24:28 +08:00
浪子 5fb2e66399 Update page-memos.php 2024-06-16 10:19:50 +08:00
浪子 30fcb2885b Update page-memos.php 2024-06-16 09:44:05 +08:00
浪子 8e0e73b594 Update page-memos.php 2024-06-15 16:44:34 +08:00
浪子 57fd7fe485 Update page-mastodon.php 2024-06-15 10:47:10 +08:00
浪子 95c172b529 Update page-mastodon.php 2024-06-15 10:38:53 +08:00
浪子 34276f132b Update page-mastodon.php 2024-06-15 10:32:29 +08:00
浪子 f26bc907d4 add有新评论通知QQ 2024-06-14 16:33:47 +08:00
浪子 e37ef68e30 Update comments.php 2024-06-13 22:05:34 +08:00
浪子 1deff9afbf 刷新版本号 2024-06-13 18:30:48 +08:00
浪子 8543bc6fe1 增加显示页面加载时间的开关 2024-06-13 17:51:54 +08:00
浪子 a88130d5c5 优化一下评论列表加上@ 2024-06-13 15:30:11 +08:00
21 changed files with 227 additions and 164 deletions
+7 -22
View File
@@ -3,6 +3,9 @@
移植自 `bigfa `大大的 `hugo-theme-farallon` 原汁原味,可以直接使用 原主题的CSS 移植自 `bigfa `大大的 `hugo-theme-farallon` 原汁原味,可以直接使用 原主题的CSS
精简部分 JS. 精简部分 JS.
- 2024.7.4
把分类图片以`mid`.jpg 的形式在主题`/dist/img`目录下,自动匹配
- 2024.6.12 - 2024.6.12
更新豆瓣API获取方式 更新豆瓣API获取方式
@@ -42,32 +45,13 @@ https://github.com/gogobody/typecho-whisper
## 原项目地址 ## 原项目地址
https://github.com/bigfa/hugo-theme-farallon https://github.com/bigfa/hugo-theme-farallon
## 移植进度
96%
## 功能 ## 功能
### 已知问题
由于typecho分类并无图片,所以默认使用
`bigfa``https://static.fatesinger.com/2021/12/vhp6eou5x2wqh2zy.jpg`
可以自行替换或者删除
### 豆瓣观影 ### 豆瓣观影
更新 获取方式 更新 获取方式
~~使用原版的获取方式~~
~~豆瓣收藏使用方法~~
~~微信扫码登录https://node.wpista.com/~~
~~输入你的豆瓣数字 id,点击保存即可自动同步豆瓣记录。~~
~~点击 Get integration token 会生成一个 token。~~
~~获取`token`之后填入主题设置项中~~
### 友情链接 ### 友情链接
基于 `links` 插件实现 基于 `links` 插件实现
@@ -90,15 +74,16 @@ https://github.com/bigfa/hugo-theme-farallon
### 说说 by Mastodon ### 说说 by Mastodon
根据 https://www.imsun.org/archives/1643.html#toc3 根据 https://www.imsun.org/archives/1643.html
获得API地址 获得API地址
在自定义字段中填入`tooot`值为Mastodon API 地址 在自定义字段中填入`tooot`值为Mastodon API 地址
### 好物 by memos ### 好物 by memos
在自定义字段中填入`memos`值为memos地址
在自定义字段中填入`memosID`默认值为`1`,不为`1`时才需要设置
在自定义字段中填入`memostag`默认值为`好物`,不为`好物`时才需要设置
## 预览地址 ## 预览地址
https://www.imsun.org https://www.imsun.org
+4 -11
View File
@@ -43,7 +43,6 @@
<?php $this->comments()->to($comments); ?> <?php $this->comments()->to($comments); ?>
<?php if($this->allow('comment')): ?> <?php if($this->allow('comment')): ?>
<?php if ($this->is('attachment')) : ?> <?php if ($this->is('attachment')) : ?>
<?php _e(''); ?>
<?php else: ?> <?php else: ?>
<h3 class="comments--title" id="comments"> <h3 class="comments--title" id="comments">
<svg viewBox="0 0 24 24" class="icon" aria-hidden="true" width="16" height="16"> <svg viewBox="0 0 24 24" class="icon" aria-hidden="true" width="16" height="16">
@@ -52,7 +51,8 @@
d="M1.751 10c0-4.42 3.584-8 8.005-8h4.366c4.49 0 8.129 3.64 8.129 8.13 0 2.96-1.607 5.68-4.196 7.11l-8.054 4.46v-3.69h-.067c-4.49.1-8.183-3.51-8.183-8.01zm8.005-6c-3.317 0-6.005 2.69-6.005 6 0 3.37 2.77 6.08 6.138 6.01l.351-.01h1.761v2.3l5.087-2.81c1.951-1.08 3.163-3.13 3.163-5.36 0-3.39-2.744-6.13-6.129-6.13H9.756z"> d="M1.751 10c0-4.42 3.584-8 8.005-8h4.366c4.49 0 8.129 3.64 8.129 8.13 0 2.96-1.607 5.68-4.196 7.11l-8.054 4.46v-3.69h-.067c-4.49.1-8.183-3.51-8.183-8.01zm8.005-6c-3.317 0-6.005 2.69-6.005 6 0 3.37 2.77 6.08 6.138 6.01l.351-.01h1.761v2.3l5.087-2.81c1.951-1.08 3.163-3.13 3.163-5.36 0-3.39-2.744-6.13-6.129-6.13H9.756z">
</path> </path>
</g> </g>
</svg><?php $this->commentsNum(_t('0'), _t('1'), _t('%d')); ?> </svg>
<?php $this->commentsNum(_t('0'), _t('1'), _t('%d')); ?>
</h3> </h3>
<ol class="commentlist sulliComment--list"></ol> <ol class="commentlist sulliComment--list"></ol>
<div id="<?php $this->respondId(); ?>" class="comment-respond"> <div id="<?php $this->respondId(); ?>" class="comment-respond">
@@ -64,7 +64,6 @@
<?php $this->user->screenName(); ?></a>. <?php $this->user->screenName(); ?></a>.
<a href="<?php $this->options->logoutUrl(); ?>" title="Logout"><?php _e('退出'); ?> &raquo;</a></p> <a href="<?php $this->options->logoutUrl(); ?>" title="Logout"><?php _e('退出'); ?> &raquo;</a></p>
<?php else: ?> <?php else: ?>
<p class="comment-form-author"> <p class="comment-form-author">
<input placeholder="称呼 *" type="text" name="author" id="author" class="text" value="" required /> <input placeholder="称呼 *" type="text" name="author" id="author" class="text" value="" required />
</p> </p>
@@ -78,7 +77,6 @@
<p class="comment-form-comment"> <p class="comment-form-comment">
<textarea rows="8" cols="50" name="text" id="textarea" class="textarea" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('misubmit').click();return false};" placeholder="<?php _e('评论审核后显示,请勿重复提交...'); ?>" required ><?php $this->remember('text'); ?></textarea> <textarea rows="8" cols="50" name="text" id="textarea" class="textarea" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('misubmit').click();return false};" placeholder="<?php _e('评论审核后显示,请勿重复提交...'); ?>" required ><?php $this->remember('text'); ?></textarea>
</p> </p>
<p class="form-submit"> <p class="form-submit">
<button type="submit" class="submit" id="misubmit"><?php _e('提交评论(Ctrl+Enter'); ?></button> <button type="submit" class="submit" id="misubmit"><?php _e('提交评论(Ctrl+Enter'); ?></button>
</p> </p>
@@ -86,9 +84,8 @@
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php else: ?> <?php else: ?>
<?php _e(''); ?>
<?php endif; ?>
<?php endif; ?>
<?php if ($comments->have()): ?> <?php if ($comments->have()): ?>
<?php $comments->listComments(); ?> <?php $comments->listComments(); ?>
<?php <?php
@@ -152,6 +149,7 @@ function threadedComments($comments, $options) {
</div> </div>
</div> </div>
<div class="comment-content"> <div class="comment-content">
<?php if ($comments->parent) {echo getPermalinkFromCoid($comments->parent);}?>
<?php $comments->content(); ?> <?php $comments->content(); ?>
</div> </div>
</div> </div>
@@ -162,8 +160,3 @@ function threadedComments($comments, $options) {
<?php } ?> <?php } ?>
</li> </li>
<?php } ?> <?php } ?>
<ol class="commentlist">
<?php $this->comments()->to($comments); ?>
<?php while($comments->next()): ?>
<?php endwhile; ?>
</ol>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+1 -1
View File
@@ -17,7 +17,7 @@
is_single = false; is_single = false;
post_id = 0; post_id = 0;
is_archive = false; is_archive = false;
VERSION = "0.5.4"; VERSION = "0.5.6";
constructor() { constructor() {
super(); super();
this.initCopyright(); this.initCopyright();
+8 -5
View File
@@ -4,13 +4,16 @@
<div class=site--footer__sns> <div class=site--footer__sns>
<?php $this->need('sns.php'); ?> <?php $this->need('sns.php'); ?>
</div> </div>
<?php if($this->options->sitemapurl): ?> <?php //sitemap填入
if($this->options->sitemapurl): ?>
<a href="<?php $this->options->sitemapurl() ?>" target="_blank">💗</a> <a href="<?php $this->options->sitemapurl() ?>" target="_blank">💗</a>
<?php endif; ?> <?php endif; ?>
<a href="https://www.typecho.org">Typecho驱动</a> <a href="https://www.typecho.org" target="_blank">Typecho驱动</a>
<a href="https://www.imsun.org">&nbsp;Made with Sun</a> <a href="https://www.imsun.org" target="_blank">&nbsp;Made with Sun</a>
&nbsp;页面加载耗时 <?php //添加加载时间控制
<?php echo timer_stop();?> if ($this->options->showtime): ?>
&nbsp;页面加载耗时<?php echo timer_stop();?>
<?php endif; ?>
<div class="copyright"> <div class="copyright">
<a href="<?php $this->options->siteUrl(); ?>"> <a href="<?php $this->options->siteUrl(); ?>">
<?php $this->options->title(); ?> <?php $this->options->title(); ?>
+71 -3
View File
@@ -47,10 +47,14 @@ function themeConfig($form) {
array('0'=> _t('否'), '1'=> _t('是')), array('0'=> _t('否'), '1'=> _t('是')),
'0', _t('是否显示复制链接'), _t('选择“是”将在文章页面显示复制链接。')); '0', _t('是否显示复制链接'), _t('选择“是”将在文章页面显示复制链接。'));
$form->addInput($showshare); $form->addInput($showshare);
$showtoc = new Typecho_Widget_Helper_Form_Element_Radio('showtoc', $showtime = new Typecho_Widget_Helper_Form_Element_Radio('showtime',
array('0'=> _t('否'), '1'=> _t('是')), array('0'=> _t('否'), '1'=> _t('是')),
'0', _t('是否显示文章目录'), _t('选择“是”将在文章页面显示文章目录(仅在宽度大于1400px的设备中显示)。')); '0', _t('是否显示页面加载时间'), _t('选择“是”将在页脚显示加载时间。'));
$form->addInput($showtoc); $form->addInput($showtime);
$qqboturl = new Typecho_Widget_Helper_Form_Element_Text('qqboturl', NULL, 'https://bot.asbid.cn', _t('QQ机器人API,保持默认则需添加 2280858259 为好友'), _t('基于cqhttp,有评论时QQ通知'));
$form->addInput($qqboturl);
$qqnum = new Typecho_Widget_Helper_Form_Element_Text('qqnum', NULL, '80116747', _t('QQ号码'), _t('用于接收QQ通知的号码'));
$form->addInput($qqnum);
} }
function get_post_view($archive) { function get_post_view($archive) {
$cid = $archive->cid; $cid = $archive->cid;
@@ -190,6 +194,70 @@ function img_postthumb($cid) {
return ""; // 没有匹配到图片URL,返回空字符串 return ""; // 没有匹配到图片URL,返回空字符串
} }
} }
//回复加上@
function getPermalinkFromCoid($coid) {
$db = Typecho_Db::get();
$row = $db->fetchRow($db->select('author')->from('table.comments')->where('coid = ? AND status = ?', $coid, 'approved'));
if (empty($row)) return '';
return '<a href="#comment-'.$coid.'" style="text-decoration: none;">@'.$row['author'].'</a>';
}
// 评论提交通知函数
function notifyQQBot($comment) {
$options = Helper::options();
// 检查评论是否已经审核通过
if ($comment->status != "approved") {
error_log('Comment is not approved.');
return;
}
// 获取配置中的QQ机器人API地址
$cq_url = $options->qqboturl;
// 检查API地址是否为空
if (empty($cq_url)) {
error_log('QQ Bot URL is empty. Using default URL.');
$cq_url = 'https://bot.asbid.cn';
}
// 获取QQ号码
$qqnum = $options->qqnum;
// 检查QQ号码是否为空
if (empty($qqnum)) {
error_log('QQ number is empty.');
return;
}
// 如果是管理员自己发的评论则不发送通知
if ($comment->authorId === $comment->ownerId) {
error_log('This comment is by the post owner.');
return;
}
// 构建消息内容
$msg = '「' . $comment->author . '」在文章《' . $comment->title . '》中发表了评论!';
$msg .= "\n评论内容:\n{$comment->text}\n永久链接地址:{$comment->permalink}";
// 准备发送消息的数据
$_message_data_ = [
'user_id' => (int) trim($qqnum),
'message' => str_replace(["\r\n", "\r", "\n"], "\r\n", htmlspecialchars_decode(strip_tags($msg)))
];
// 输出调试信息
error_log('Sending message to QQ Bot: ' . print_r($_message_data_, true));
// 初始化Curl请求
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "{$cq_url}/send_msg?" . http_build_query($_message_data_, '', '&'),
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 0
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
error_log('Curl error: ' . curl_error($ch));
} else {
error_log('Response: ' . $response);
}
curl_close($ch);
}
Typecho_Plugin::factory('Widget_Feedback')->finishComment = 'notifyQQBot';
//开始增加某些奇怪的东西 //开始增加某些奇怪的东西
// 获取月份 // 获取月份
function getMonth() { function getMonth() {
+1 -1
View File
@@ -3,7 +3,7 @@
* 移植自HUGO主题 farallon 原作者 bigfa * 移植自HUGO主题 farallon 原作者 bigfa
* @package farallon * @package farallon
* @author 老孙 * @author 老孙
* @version 0.5.4 * @version 0.5.6
* @link https://imsun.org * @link https://imsun.org
*/ */
if (!defined('__TYPECHO_ROOT_DIR__')) exit; if (!defined('__TYPECHO_ROOT_DIR__')) exit;
+16 -7
View File
@@ -12,17 +12,26 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<h2 class="post--single__subtitle"><?php $this->content(); ?> </h2> <h2 class="post--single__subtitle"><?php $this->content(); ?> </h2>
</header> </header>
<section class="category--list"> <section class="category--list">
<?php $this->widget('Widget_Metas_Category_List')->parse(' <?php $this->widget('Widget_Metas_Category_List')->to($categories); ?>
<?php while($categories->next()): ?>
<?php
// 获取分类 ID
$categoryId = $categories->mid;
// 获取主题URL
$themeUrl = $this->options->themeUrl;
// 为每个分类生成图片地址
$categoryImage = $themeUrl . '/dist/img/' . $categoryId . '.jpg';
?>
<div class="category--item"> <div class="category--item">
<img src="https://static.fatesinger.com/2021/12/vhp6eou5x2wqh2zy.jpg" class="category--cover"/> <img class="category--cover" src="<?php echo $categoryImage; ?>" loading="lazy" alt="<?php $categories->name(); ?>">
<div class="category--content"> <div class="category--content">
<a href="{permalink}" class="category--card">{name} <a class="category--card" href="<?php $categories->permalink(); ?>"><?php $categories->name(); ?>
<span>({count})</span> <span>(<?php $categories->count(); ?>)</span></a>
</a> <div class="category--desc"> <?php $categories->description(); ?>
<div class="category--desc">{description}</div>
</div> </div>
</div> </div>
'); ?> </div>
<?php endwhile; ?>
</section> </section>
</div> </div>
<?php $this->need('footer.php'); ?> <?php $this->need('footer.php'); ?>
+1 -1
View File
@@ -10,7 +10,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<section class="site--main"> <section class="site--main">
<header class="archive--header"> <header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1> <h1 class="post--single__title"><?php $this->title() ?></h1>
<h2 class="post--single__subtitle">数据来源于豆瓣</h2> <h2 class="post--single__subtitle"><?php $this->content(); ?></h2>
</header> </header>
<div class="site--main"> <div class="site--main">
<div class="db--container"></div> <div class="db--container"></div>
+22 -12
View File
@@ -100,26 +100,32 @@ div p a {
word-break: break-all; word-break: break-all;
word-break: break-word; word-break: break-word;
} }
.thumbnail-image {
width:100%;
height: 200px;
align-items: center;
justify-content: center;
overflow: hidden;
}
.resimg { .resimg {
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
column-gap: 10px; column-gap: 10px;
row-gap: 10px; row-gap: 10px;
} }
/* 单个缩略图的样式 */
.thumbnail-image {
width: 100%; /* 确保其宽度填满父容器 */
height: 200px; /* 固定高度 */
display: flex; /* 使用 flexbox 居中 */
align-items: center; /* 垂直居中 */
justify-content: center; /* 水平居中 */
overflow: hidden; /* 确保容器内的多余内容不会显示出来 */
border-radius: 4px; /* 圆角 */
transition: transform .3s ease; /* 鼠标悬停时的过渡效果 */
cursor: zoom-in; /* 鼠标指针变为放大镜 */
}
img {
object-fit: cover; /* 保持图片的纵横比,但会将图片裁剪以填充容器 */
object-position: center; /* 保证中央部分 */
}
/* 缩略图内的图片样式 */
.thumbnail-image img { .thumbnail-image img {
width: 100%; width: 100%;
height:170px; min-height: 200px;
object-fit:cover;
border-radius:4px;
transition:transform .3s ease;
cursor:zoom-in
} }
/* 当屏幕宽度小于732px时 */ /* 当屏幕宽度小于732px时 */
@media (max-width: 732px) { @media (max-width: 732px) {
@@ -132,6 +138,10 @@ div p a {
.resimg { .resimg {
grid-template-columns: 1fr; /* 修改为一列 */ grid-template-columns: 1fr; /* 修改为一列 */
} }
.thumbnail-image img {
width: 100%;
height: 480px;
}
} }
.load-more-btn { .load-more-btn {
display: block; display: block;
+9 -7
View File
@@ -31,7 +31,6 @@ if (99) {
.then(data => { .then(data => {
let html = ''; let html = '';
data.forEach(item => { data.forEach(item => {
// 假设这里的 Format 函数能正确地格式化每个 item,并确保它返回有 `date` 和 `tag` 的对象
let data = Format(item); let data = Format(item);
let memoURL = url + '/m/' + item.id; let memoURL = url + '/m/' + item.id;
let mdContent = marked.parse(data.content); let mdContent = marked.parse(data.content);
@@ -43,8 +42,8 @@ if (99) {
<a class="humane--time" href="${memoURL}" target="_blank">${data.date}</a> <a class="humane--time" href="${memoURL}" target="_blank">${data.date}</a>
</header> </header>
<div class="description" itemprop="about"> <div class="description" itemprop="about">
<span class="talk_tag"># ${data.tag}</span><br>
${mdContent} ${mdContent}
<span class="tag--list"><a>${data.tag}</a></span>
</div> </div>
</div> </div>
</article> </article>
@@ -56,7 +55,6 @@ if (99) {
console.error('Error:', error); console.error('Error:', error);
// 这里可以添加一些用户提示错误发生的 HTML 更新 // 这里可以添加一些用户提示错误发生的 HTML 更新
}); });
// 页面内容格式化
function Format(item) { function Format(item) {
let date = getTime(new Date(item.createdTs * 1000).toString()), let date = getTime(new Date(item.createdTs * 1000).toString()),
content = item.content, content = item.content,
@@ -121,6 +119,9 @@ div p a {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
overflow: hidden; overflow: hidden;
border-radius:4px;
transition:transform .3s ease;
cursor:zoom-in;
} }
.resimg { .resimg {
display: grid; display: grid;
@@ -130,11 +131,12 @@ div p a {
} }
.thumbnail-image img { .thumbnail-image img {
width:100%; width:100%;
height:170px; min-height: 200px;
object-fit:cover; object-fit:cover;
border-radius:4px; }
transition:transform .3s ease; img {
cursor:zoom-in object-fit: cover; /* 保持图片的纵横比,但会将图片裁剪以填充容器 */
object-position: center; /* 保证中央部分 */
} }
/* 当屏幕宽度小于732px时 */ /* 当屏幕宽度小于732px时 */
@media (max-width: 732px) { @media (max-width: 732px) {
+27 -33
View File
@@ -1,5 +1,13 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?> <?php $this->need('header.php'); ?>
<style>
#toc {font-size:14px;padding:10px 15px;background-color:var(--farallon-background-gray);border-radius:10px;margin-bottom:20px}
#toc summary{cursor:pointer}
#toc toc-title{font-weight:600}
#toc ul{padding-left:10px;margin-bottom:10px}
#toc ul li::before{content:"·";margin-right:5px}
#toc ul li>ul{margin-left:10px;font-size:12px}
</style>
<main class="site--main"> <main class="site--main">
<article class="post--single"> <article class="post--single">
<ul class="meta"> <ul class="meta">
@@ -36,8 +44,8 @@
</div> </div>
<h2 class="post--single__title"><?php $this->title() ?></h2> <h2 class="post--single__title"><?php $this->title() ?></h2>
<div class="post--single__content graph" ><?php $this->content(); ?></div> <div class="post--single__content graph" ><?php $this->content(); ?></div>
<!--打赏 -->
<?php if($this->options->donate): ?> <?php if($this->options->donate): ?>
<!--打赏 -->
<div class="post--single__action"> <div class="post--single__action">
<link rel="stylesheet" href="<?php $this->options->themeUrl('/dist/css/donate.css'); ?>"> <link rel="stylesheet" href="<?php $this->options->themeUrl('/dist/css/donate.css'); ?>">
<script type="text/javascript" src="<?php $this->options->themeUrl('/dist/js/donate.js'); ?>"></script> <script type="text/javascript" src="<?php $this->options->themeUrl('/dist/js/donate.js'); ?>"></script>
@@ -150,10 +158,10 @@
</nav> </nav>
</ul> </ul>
</article> </article>
<?php if($this->options->showtoc): ?> </main>
<!--TOC 在宽度大于1400px时才会显示-->
<script> <script>
document.addEventListener('DOMContentLoaded', (event) => { document.addEventListener('DOMContentLoaded', (event) => {
const targetClassElement = document.querySelector('.post--single__title');
const postContent = document.querySelector('.post--single__content'); const postContent = document.querySelector('.post--single__content');
if (!postContent) return; if (!postContent) return;
@@ -164,19 +172,25 @@ document.addEventListener('DOMContentLoaded', (event) => {
} }
} }
if (!found) return; if (!found) return;
const heads = postContent.querySelectorAll('h1, h2, h3, h4, h5, h6'); const heads = postContent.querySelectorAll('h1, h2, h3, h4, h5, h6');
const toc = document.createElement('div'); const toc = document.createElement('div');
toc.id = 'toc'; toc.id = 'toc';
toc.innerHTML = '<strong>目录</strong><ul></ul>'; toc.innerHTML = '<details class="toc" open><summary class="toc-title">目录</summary><nav id="TableOfContents"><ul></ul></nav></details>';
document.body.appendChild(toc);
// 插入到指定 class 元素之后
if (targetClassElement) {
targetClassElement.parentNode.insertBefore(toc, targetClassElement.nextSibling);
}
let currentLevel = 0; let currentLevel = 0;
let currentList = toc.querySelector('ul'); let currentList = toc.querySelector('ul');
let levelCounts = [0]; // 初始化层级计数器 let levelCounts = [0];
heads.forEach((head, index) => { heads.forEach((head, index) => {
const level = parseInt(head.tagName.substring(1)); const level = parseInt(head.tagName.substring(1));
if (levelCounts[level] === undefined) { if (levelCounts[level] === undefined) {
levelCounts[level] = 1; // 初始化该层级计数 levelCounts[level] = 1;
} else { } else {
levelCounts[level]++; levelCounts[level]++;
} }
@@ -194,7 +208,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
} }
currentList = newList; currentList = newList;
currentLevel++; currentLevel++;
levelCounts[currentLevel] = 1; // 初始化下一层级的计数器 levelCounts[currentLevel] = 1;
} }
while (level < currentLevel) { while (level < currentLevel) {
currentList = currentList.parentElement; currentList = currentList.parentElement;
@@ -203,37 +217,17 @@ document.addEventListener('DOMContentLoaded', (event) => {
} }
currentLevel--; currentLevel--;
} }
const numbers = levelCounts.slice(1, level + 1).join(' ') ; const anchor = head.textContent.trim().replace(/\s+/g, '-');
const item = document.createElement('li');
item.classList.add('toc-item'); // 添加基本类
item.classList.add(`level-${level}`); // 根据级别添加类
const anchor = `toc${index}`;
head.id = anchor; head.id = anchor;
const item = document.createElement('li');
const link = document.createElement('a'); const link = document.createElement('a');
link.href = `#${anchor}`; link.href = `#${anchor}`;
link.textContent = `${numbers}. ${head.textContent}`; // 序号+标题文本 link.textContent = `${head.textContent}`;
link.style.textDecoration = 'none';
item.appendChild(link); item.appendChild(link);
currentList.appendChild(item); currentList.appendChild(item);
}); });
}); });
</script> </script>
<style>
#toc {
position: fixed;
top: 100px;
right: 50px;
max-width: 200px;
background-color: var(--farallon-background-gray);
padding: 10px;
border-radius: 5px;
/* 其他样式... */
}
@media screen and (max-width: 1400px) {
#toc {
display: none;
}
}
</style>
<?php endif; ?>
</main>
<?php $this->need('footer.php'); ?> <?php $this->need('footer.php'); ?>
-1
View File
@@ -4,7 +4,6 @@
<div class="content"> <div class="content">
<h2 class="post--title"> <h2 class="post--title">
<a href="<?php $this->permalink() ?>"> <a href="<?php $this->permalink() ?>">
<!--三天内显示火苗-->
<?php $this->title() ?> <?php $this->title() ?>
<?php if((time() - $this->created) < 60*60*24*3): ?> <?php if((time() - $this->created) < 60*60*24*3): ?>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
+1 -1
View File
@@ -2,7 +2,7 @@
<div class="author--card"> <div class="author--card">
<img src="<?php $this->options->logoUrl() ?>" class="avatar" height="64" width="64" decoding="async"> <img src="<?php $this->options->logoUrl() ?>" class="avatar" height="64" width="64" decoding="async">
<div class="author--name"> <div class="author--name">
<?php $this->options->author() ?> <?php $this->author(); ?>
</div> </div>
<div class="author--description"> <div class="author--description">
<?php $this->options->description() ?> <?php $this->options->description() ?>