From 482e9a1e93d5974a2e0f06413cd28f955eb7f3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AA=E5=AD=90?= Date: Wed, 26 Mar 2025 09:14:45 +0800 Subject: [PATCH] 0.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了一个
未闭合的bug 优化分页和加载更多逻辑 --- archive.php | 21 +++--------------- assets/js/bundle.js | 4 ++-- assets/js/donate.js | 8 ------- assets/js/loadmore.js | 33 ++++++++++++++++------------ module/footer.php => footer.php | 0 functions.php | 12 ---------- module/header.php => header.php | 0 index.php | 39 +++++---------------------------- module/memos.php | 6 +++-- module/paging.php | 31 ++++++++++++++++++++++++++ module/postlist.php | 14 +++++++----- module/travel.php | 7 +++--- page-archives.php | 4 ++-- page-categories.php | 4 ++-- page-douban.php | 4 ++-- page-goods.php | 15 ++++--------- page-links.php | 4 ++-- page-mastodon.php | 4 ++-- page-memos.php | 12 +++------- page-neodb.php | 22 +++++++++---------- page-tags.php | 4 ++-- page.php | 4 ++-- post.php | 6 ++--- 23 files changed, 112 insertions(+), 146 deletions(-) rename module/footer.php => footer.php (100%) rename module/header.php => header.php (100%) create mode 100644 module/paging.php diff --git a/archive.php b/archive.php index 49d7269..9db9fe1 100644 --- a/archive.php +++ b/archive.php @@ -1,5 +1,5 @@ -need('module/header.php'); ?> +need('header.php'); ?>

archiveTitle(array( @@ -37,25 +37,10 @@ $memosId = is_numeric($memosId) ? intval($memosId) : null; need('module/postlist.php'); ?> - pageNav( - ' ', - ' ', - 1, - '...', - array( - 'wrapTag' => 'nav', - 'wrapClass' => 'nav-links nav-links__comment', - 'itemTag' => '', - 'textTag' => 'span', - 'itemClass' => 'page-numbers', - 'currentClass' => 'page-numbers current', - 'prevClass' => 'hidden', - 'nextClass' => 'hidden' - ) - ); ?> + need('module/paging.php'); ?> need('module/notfound.php'); ?>

-need('module/footer.php'); ?> \ No newline at end of file +need('footer.php'); ?> \ No newline at end of file diff --git a/assets/js/bundle.js b/assets/js/bundle.js index 571f38c..a9e9828 100644 --- a/assets/js/bundle.js +++ b/assets/js/bundle.js @@ -17,7 +17,7 @@ is_single = false; post_id = 0; is_archive = false; - VERSION = "0.7.0"; + VERSION = "0.7.1"; constructor() { super(); this.initCopyright(); @@ -46,7 +46,7 @@ } initCopyright() { const copyright = ``; document.querySelector(".site--footer__content").insertAdjacentHTML("afterend", copyright); document.querySelector(".icon--copryrights").addEventListener("click", () => { diff --git a/assets/js/donate.js b/assets/js/donate.js index 2f68e8f..11038fb 100644 --- a/assets/js/donate.js +++ b/assets/js/donate.js @@ -5,7 +5,6 @@ document.addEventListener('DOMContentLoaded', function() { const methodBtns = document.querySelectorAll('.donate-method-btn'); const qrImages = document.querySelectorAll('.qr-image'); let isVisible = false; - // 切换支付方式 function switchPayMethod(method) { // 更新按钮状态 @@ -15,7 +14,6 @@ document.addEventListener('DOMContentLoaded', function() { btn.classList.add('active'); } }); - // 更新二维码显示 qrImages.forEach(img => { img.classList.remove('active'); @@ -24,21 +22,18 @@ document.addEventListener('DOMContentLoaded', function() { } }); } - // 点击打赏按钮切换二维码显示状态 function toggleQRCode(event) { event.stopPropagation(); isVisible = !isVisible; qrcodePanel.style.display = isVisible ? 'block' : 'none'; } - // 点击关闭按钮隐藏二维码 function hideQRCode(event) { event.stopPropagation(); isVisible = false; qrcodePanel.style.display = 'none'; } - // 点击二维码面板之外的地方隐藏二维码 function handleDocumentClick(event) { if (isVisible && !qrcodePanel.contains(event.target) && !donateBtn.contains(event.target)) { @@ -46,12 +41,10 @@ document.addEventListener('DOMContentLoaded', function() { qrcodePanel.style.display = 'none'; } } - // 绑定事件监听器 donateBtn.addEventListener('click', toggleQRCode); donateClose.addEventListener('click', hideQRCode); document.addEventListener('click', handleDocumentClick); - // 绑定支付方式切换按钮事件 methodBtns.forEach(btn => { btn.addEventListener('click', (e) => { @@ -59,7 +52,6 @@ document.addEventListener('DOMContentLoaded', function() { switchPayMethod(method); }); }); - // 初始化显示第一个支付方式 switchPayMethod('wechat'); }); \ No newline at end of file diff --git a/assets/js/loadmore.js b/assets/js/loadmore.js index 69e165a..31ee6b8 100644 --- a/assets/js/loadmore.js +++ b/assets/js/loadmore.js @@ -1,13 +1,13 @@ document.addEventListener('click', function (e) { - // 检查点击的元素是否是 .post-read-more a + // 检查点击的元素是否是 .loadmore a if (e.target.closest('.loadmore a')) { e.preventDefault(); var btn = e.target.closest('.loadmore a'); - var nextPage = btn.getAttribute('href'); + var nextPage = btn.getAttribute('href'); // 防止重复点击 if (btn.classList.contains('loading')) return false; btn.classList.add('loading'); - btn.textContent = '加载中...'; + btn.textContent = '加载中...'; // 发起 AJAX 请求 fetch(nextPage) .then(response => { @@ -19,18 +19,23 @@ document.addEventListener('click', function (e) { .then(data => { // 创建一个临时的 DOM 元素来解析返回的 HTML var parser = new DOMParser(); - var htmlDoc = parser.parseFromString(data, 'text/html'); - // 找到新的文章 - var newPosts = htmlDoc.querySelectorAll('.post--item'); - // 找到新的"加载更多"按钮 - var newBtn = htmlDoc.querySelector('.nav-links a'); - // 获取文章列表容器和加载更多按钮 - var postReadMore = document.querySelector('.nav-links'); - var articleList = document.querySelector('.articleList'); + var htmlDoc = parser.parseFromString(data, 'text/html'); + // 调试代码:检查选择器 + console.log('Searching for #loadpost:', htmlDoc.querySelectorAll('#loadpost')); + console.log('Searching for .nav-links:', htmlDoc.querySelector('.nav-links')); + // 找到新的文章和按钮 + var newPosts = htmlDoc.querySelectorAll('#loadpost'); + var newBtn = htmlDoc.querySelector('.nav-links a'); + // 更健壮的元素选择 + var articleList = document.querySelector('#loadposts') || + document.querySelector('.posts-container') || + document.body; + var postReadMore = document.querySelector('.nav-links'); if (newPosts.length > 0) { newPosts.forEach(post => { - articleList.insertBefore(post, postReadMore); - }); + // 使用 appendChild 替代 insertBefore + articleList.appendChild(post); + }); // 新文章淡入效果 Array.from(newPosts).forEach(post => { post.style.opacity = 0; @@ -39,7 +44,7 @@ document.addEventListener('click', function (e) { post.style.opacity = 1; }, 10); }); - } + } // 更新"加载更多"按钮或移除它 if (newBtn) { btn.setAttribute('href', newBtn.getAttribute('href')); diff --git a/module/footer.php b/footer.php similarity index 100% rename from module/footer.php rename to footer.php diff --git a/functions.php b/functions.php index fbd9a0e..2016e6d 100644 --- a/functions.php +++ b/functions.php @@ -71,18 +71,6 @@ function themeFields($layout) { $layout->addItem($summary); $cover= new Typecho_Widget_Helper_Form_Element_Text('cover', NULL, NULL, _t('文章封面'), _t('自定义文章封面')); $layout->addItem($cover); - // $douban= new Typecho_Widget_Helper_Form_Element_Text('douban', NULL, NULL, _t('豆瓣API'), _t('自定义页面豆瓣API')); - // $layout->addItem($douban); - //$neodb= new Typecho_Widget_Helper_Form_Element_Text('neodb', NULL, NULL, _t('NeoDB API'), _t('自定义页面NeoDB API')); - //$layout->addItem($neodb); - // $tooot= new Typecho_Widget_Helper_Form_Element_Text('tooot', NULL, NULL, _t('Mastodon API'), _t('自定义页面Mastodon API')); - // $layout->addItem($tooot); - // $memos= new Typecho_Widget_Helper_Form_Element_Text('memos', NULL, NULL, _t('Memos地址'), _t(' 自定义页面Memos地址')); - // $layout->addItem($memos); - // $memosID= new Typecho_Widget_Helper_Form_Element_Text('memosID', NULL, NULL, _t('Memos ID'), _t('自定义页面Memos ID')); - // $layout->addItem($memosID); - // $memosnum= new Typecho_Widget_Helper_Form_Element_Text('memosnum', NULL, NULL, _t('Memos数量'), _t('自定义页面Memos数量')); - // $layout->addItem($memosnum); } /* diff --git a/module/header.php b/header.php similarity index 100% rename from module/header.php rename to header.php diff --git a/index.php b/index.php index b1727ed..e4000cc 100644 --- a/index.php +++ b/index.php @@ -91,40 +91,11 @@ foreach ($normalPosts as $normalPost) { $this->push($normalPost); } ?> -need('module/header.php');?> +need('header.php');?>
-
-need('module/postlist.php'); ?> -options->loadmore): ?> - pageNav( - ' ', - ' ', - 1, - '...', - array( - 'wrapTag' => 'nav', - 'wrapClass' => 'nav-links nav-links__comment', - 'itemTag' => '', - 'textTag' => 'span', - 'itemClass' => 'page-numbers', - 'currentClass' => 'page-numbers current', - 'prevClass' => 'hidden', - 'nextClass' => 'hidden' - ) - ); - ?> - - _currentPage + 1; -$totalPages = ceil($this->getTotal() / $this->parameter->pageSize); -if ($this->_currentPage < $totalPages): ?> -
-need('module/footer.php'); ?> \ No newline at end of file +need('footer.php'); ?> \ No newline at end of file diff --git a/module/memos.php b/module/memos.php index aef0375..c73455b 100644 --- a/module/memos.php +++ b/module/memos.php @@ -1,6 +1,7 @@ +
next()): ?> -
+
@@ -14,4 +15,5 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/module/paging.php b/module/paging.php new file mode 100644 index 0000000..c0e1b99 --- /dev/null +++ b/module/paging.php @@ -0,0 +1,31 @@ +options->loadmore): ?> + pageNav( + ' ', + ' ', + 1, + '...', + array( + 'wrapTag' => 'nav', + 'wrapClass' => 'nav-links nav-links__comment', + 'itemTag' => '', + 'textTag' => 'span', + 'itemClass' => 'page-numbers', + 'currentClass' => 'page-numbers current', + 'prevClass' => 'hidden', + 'nextClass' => 'hidden' + ) + ); + ?> + + _currentPage + 1; + $totalPages = ceil($this->getTotal() / $this->parameter->pageSize); + if ($this->_currentPage < $totalPages): + ?> + + + + \ No newline at end of file diff --git a/module/postlist.php b/module/postlist.php index c9c843d..0552a62 100644 --- a/module/postlist.php +++ b/module/postlist.php @@ -1,10 +1,10 @@ +
next()): ?> categories; $memosMid = $this->options->memos; // 获取主题设置中的说说分类 mid $isMemos = false; - // 检查当前文章是否属于说说分类 foreach ($categories as $category) { if ($category['mid'] == $memosMid) { @@ -12,10 +12,10 @@ break; } } - // 根据是否为说说分类使用不同的显示模板 if ($isMemos): ?> +
@@ -29,9 +29,11 @@ excerpt(200, '...'); ?>
- + +
-
+ - \ No newline at end of file + + \ No newline at end of file diff --git a/module/travel.php b/module/travel.php index fb7c39c..e306473 100644 --- a/module/travel.php +++ b/module/travel.php @@ -1,5 +1,5 @@ -
+
next()): ?> themeUrl . '/assets/images/nopic.svg'; @@ -13,7 +13,7 @@ $imageToDisplay = $firstImage; } ?> -
+
<?php $this->title() ?>

@@ -34,4 +34,5 @@

- \ No newline at end of file + + \ No newline at end of file diff --git a/page-archives.php b/page-archives.php index 1969728..a9cbbd6 100644 --- a/page-archives.php +++ b/page-archives.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> -need('./module/header.php'); ?> +need('header.php'); ?>

title() ?>

@@ -57,4 +57,4 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> ?>
-need('./module/footer.php'); ?> \ No newline at end of file +need('footer.php'); ?> \ No newline at end of file diff --git a/page-categories.php b/page-categories.php index 33edf81..a01d543 100644 --- a/page-categories.php +++ b/page-categories.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> -need('./module/header.php'); ?> +need('header.php'); ?>

title() ?>

@@ -33,4 +33,4 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
-need('./module/footer.php'); ?> \ No newline at end of file +need('footer.php'); ?> \ No newline at end of file diff --git a/page-douban.php b/page-douban.php index 9f734f2..bd06cc9 100644 --- a/page-douban.php +++ b/page-douban.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> -need('./module/header.php'); ?> +need('header.php'); ?>
@@ -28,4 +28,4 @@ new Douban({
-need('./module/footer.php'); ?> \ No newline at end of file +need('footer.php'); ?> \ No newline at end of file diff --git a/page-goods.php b/page-goods.php index 298d48b..9836d8a 100644 --- a/page-goods.php +++ b/page-goods.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; -$this->need('./module/header.php'); +$this->need('header.php'); ?>
@@ -77,25 +77,20 @@ $this->need('./module/header.php'); */ function parseGoodsTable($content) { $goods = array(); - // 创建DOM对象 $dom = new DOMDocument(); libxml_use_internal_errors(true); // 禁用libxml错误 $dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); libxml_clear_errors(); - // 查找表格 $tables = $dom->getElementsByTagName('table'); - if ($tables->length > 0) { $table = $tables->item(0); // 获取第一个表格 - $rows = $table->getElementsByTagName('tr'); - + $rows = $table->getElementsByTagName('tr'); // 跳过表头行 for ($i = 1; $i < $rows->length; $i++) { $row = $rows->item($i); - $cells = $row->getElementsByTagName('td'); - + $cells = $row->getElementsByTagName('td'); // 确保有足够的单元格 if ($cells->length >= 5) { $item = array( @@ -113,9 +108,7 @@ function parseGoodsTable($content) { } } } - return $goods; } - -$this->need('./module/footer.php'); +$this->need('footer.php'); ?> \ No newline at end of file diff --git a/page-links.php b/page-links.php index f840749..7f3796c 100644 --- a/page-links.php +++ b/page-links.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> -need('./module/header.php'); ?> +need('header.php'); ?>

title() ?>

@@ -26,4 +26,4 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
-need('./module/footer.php'); ?> \ No newline at end of file +need('footer.php'); ?> \ No newline at end of file diff --git a/page-mastodon.php b/page-mastodon.php index 8a9a8c1..e62b53f 100644 --- a/page-mastodon.php +++ b/page-mastodon.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> -need('./module/header.php'); ?> +need('header.php'); ?>

title() ?>

@@ -148,4 +148,4 @@ img { }
-need('./module/footer.php'); ?> +need('footer.php'); ?> diff --git a/page-memos.php b/page-memos.php index fe42528..2fb8243 100644 --- a/page-memos.php +++ b/page-memos.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> -need('./module/header.php'); ?> +need('header.php'); ?>

title() ?>

@@ -16,7 +16,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> $memos = $this->fields->memos ? $this->fields->memos : 'https://memos.imsun.org'; $memosID = $this->fields->memosID ? $this->fields->memosID : '1'; $memosnum = $this->fields->memosnum ? $this->fields->memosnum : '20'; - ?> + ?>
@@ -32,7 +32,6 @@ const limit = 10; // 每页条数 let url = ''; let memosID = ''; let memosnum = ''; - function loadMemos(page) { fetch(`${url}/api/v1/memo?creatorId=${memosID}&rowStatus=NORMAL&limit=${limit}&offset=${(page - 1) * limit}`) .then(res => res.json()) @@ -64,7 +63,6 @@ function loadMemos(page) { // 这里可以添加一些用户提示错误发生的 HTML 更新 }); } - function Format(item) { let date = getTime(new Date(item.createdTs * 1000).toString()), content = item.content, @@ -94,7 +92,6 @@ function Format(item) { text: text.replace(/\[(.*?)\]\((.*?)\)/g, '[链接]' + `${imgs?'[图片]':''}`) } } - // 页面时间格式化 function getTime(time) { let d = new Date(time), @@ -105,16 +102,13 @@ function getTime(time) { if (new Date().getFullYear() == ls[0]) return ls[1] + '月' + ls[2] + '日 ' + ls[3] +':'+ ls[4] else return ls[0] + '年' + ls[1] + '月' + ls[2] + '日 ' + ls[3] +':'+ ls[4] } - // 初始加载第一页 loadMemos(currentPage); - // 点击“加载更多”按钮时加载下一页 document.getElementById('loadmore').addEventListener('click', function() { currentPage++; loadMemos(currentPage); }); -
-need('./module/footer.php'); ?> +need('footer.php'); ?> diff --git a/page-neodb.php b/page-neodb.php index d66277c..48f2d9b 100644 --- a/page-neodb.php +++ b/page-neodb.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> -need('./module/header.php'); ?> +need('header.php'); ?>
@@ -15,14 +15,14 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
- fields->neodb ? $this->fields->neodb : 'https://neodb.imsun.org'; ?> - -
+ fields->neodb ? $this->fields->neodb : 'https://neodb.imsun.org'; ?> + +
-need('./module/footer.php'); ?> \ No newline at end of file +need('footer.php'); ?> \ No newline at end of file diff --git a/page-tags.php b/page-tags.php index 99f1450..a1d0ea9 100644 --- a/page-tags.php +++ b/page-tags.php @@ -5,7 +5,7 @@ * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> -need('./module/header.php'); ?> +need('header.php'); ?>

title() ?>

@@ -30,4 +30,4 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
-need('./module/footer.php'); ?> \ No newline at end of file +need('footer.php'); ?> \ No newline at end of file diff --git a/page.php b/page.php index d08b87d..bd7180d 100644 --- a/page.php +++ b/page.php @@ -1,5 +1,5 @@ -need('./module/header.php'); ?> +need('header.php'); ?>

title() ?>

@@ -14,5 +14,5 @@
-need('module/footer.php'); ?> +need('footer.php'); ?> \ No newline at end of file diff --git a/post.php b/post.php index bc9d629..607ed35 100644 --- a/post.php +++ b/post.php @@ -1,5 +1,5 @@ -need('module/header.php'); ?> +need('header.php'); ?>