From cf059bd533bdb027f7bb9d508132afc3c535bc13 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 9 May 2025 17:52:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=20package.json=20?= =?UTF-8?q?=E5=92=8C=20plugins.yml=20=E4=B8=AD=E7=9A=84=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=99=9F=20fix:=20=E4=BF=AE=E6=AD=A3=20truncateContent=20?= =?UTF-8?q?=E5=87=BD=E6=95=B8,=20=E5=8A=A0=E5=AF=86=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=E8=87=AA=E5=8A=A8=E6=93=B7=E5=8F=96?= =?UTF-8?q?=E5=85=A7=E5=AE=B9=20feat:=20=E5=A2=9E=E5=8A=A0=E9=A6=96?= =?UTF-8?q?=E9=A0=81=E6=A8=A3=E5=BC=8F=E4=BB=A5=E6=94=AF=E6=8C=81=E5=96=AE?= =?UTF-8?q?=E8=A9=9E=E6=8F=9B=E8=A1=8C=20fix:=20=E4=BF=AE=E6=AD=A3=20trunc?= =?UTF-8?q?ateContent=20=E5=87=BD=E6=95=B8=E4=BB=A5=E6=AD=A3=E7=A2=BA?= =?UTF-8?q?=E8=99=95=E7=90=86=E8=87=AA=E5=8B=95=E6=93=B7=E5=8F=96=E5=85=A7?= =?UTF-8?q?=E5=AE=B9=20fix:=20=E4=BF=AE=E5=A4=8D=20card=5Farchives=20?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=20bug=20fix:=20=E4=BF=AE=E6=AD=A3=E5=88=86?= =?UTF-8?q?=E9=A0=81=E9=A0=86=E5=BA=8F=E9=82=8F=E8=BC=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/includes/head/structured_data.pug | 8 +-- layout/includes/pagination.pug | 2 +- package.json | 2 +- plugins.yml | 28 ++++---- scripts/common/postDesc.js | 11 ++-- scripts/helpers/aside_archives.js | 82 +++++++++++++----------- source/css/_page/homepage.styl | 3 +- 7 files changed, 73 insertions(+), 63 deletions(-) diff --git a/layout/includes/head/structured_data.pug b/layout/includes/head/structured_data.pug index cacb02c..6e549c6 100644 --- a/layout/includes/head/structured_data.pug +++ b/layout/includes/head/structured_data.pug @@ -9,8 +9,8 @@ if theme.structured_data && page.layout === 'post' const datePublished = page.date.toISOString() const dateModified = (page.updated || page.date).toISOString() const author = page.copyright_author || config.author - const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url; - const authorHref = full_url_for(authorHrefVal); + const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url + const authorHref = full_url_for(authorHrefVal) const jsonLd = { "@context": "https://schema.org", @@ -25,9 +25,9 @@ if theme.structured_data && page.layout === 'post' "name": author, "url": authorHref }] - }; + } - jsonLdScript = JSON.stringify(jsonLd, null, 2); + jsonLdScript = JSON.stringify(jsonLd, null, 2) - script(type="application/ld+json"). diff --git a/layout/includes/pagination.pug b/layout/includes/pagination.pug index bbfc1eb..73b6c2b 100644 --- a/layout/includes/pagination.pug +++ b/layout/includes/pagination.pug @@ -7,7 +7,7 @@ } if globalPageType === 'post' - - let paginationOrder = theme.post_pagination === 1 ? { prev: page.prev, next: page.next } : { prev: page.next, next: page.prev } + - let paginationOrder = theme.post_pagination === 2 ? { prev: page.prev, next: page.next } : { prev: page.next, next: page.prev } nav#pagination.pagination-post each direction, key in paginationOrder diff --git a/package.json b/package.json index 3a3aaa6..149be7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "5.4.0-b1", + "version": "5.4.0-b2", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/plugins.yml b/plugins.yml index c79ad44..cea52d4 100644 --- a/plugins.yml +++ b/plugins.yml @@ -9,7 +9,7 @@ activate_power_mode: algolia_search: name: algoliasearch file: dist/lite/builds/browser.umd.js - version: 5.20.3 + version: 5.24.0 aplayer_css: name: aplayer file: dist/APlayer.min.css @@ -45,7 +45,7 @@ canvas_ribbon: chartjs: name: chart.js file: dist/chart.umd.js - version: 4.4.8 + version: 4.4.9 clickShowText: name: butterfly-extsrc file: dist/click-show-text.min.js @@ -57,11 +57,11 @@ click_heart: disqusjs: name: disqusjs file: dist/browser/disqusjs.es2015.umd.min.js - version: 3.0.2 + version: 3.1.0 disqusjs_css: name: disqusjs file: dist/browser/styles/disqusjs.css - version: 3.0.2 + version: 3.1.0 docsearch_css: name: '@docsearch/css' other_name: docsearch-css @@ -111,17 +111,17 @@ instantpage: instantsearch: name: instantsearch.js file: dist/instantsearch.production.min.js - version: 4.77.3 + version: 4.78.3 katex: name: katex file: dist/katex.min.css other_name: KaTeX - version: 0.16.21 + version: 0.16.22 katex_copytex: name: katex file: dist/contrib/copy-tex.min.js other_name: KaTeX - version: 0.16.21 + version: 0.16.22 lazyload: name: vanilla-lazyload file: dist/lazyload.iife.min.js @@ -137,7 +137,7 @@ medium_zoom: mermaid: name: mermaid file: dist/mermaid.min.js - version: 11.4.1 + version: 11.6.0 meting_js: name: butterfly-extsrc file: metingjs/dist/Meting.min.js @@ -160,17 +160,17 @@ prismjs_autoloader: name: prismjs file: plugins/autoloader/prism-autoloader.min.js other_name: prism - version: 1.29.0 + version: 1.30.0 prismjs_js: name: prismjs file: prism.js other_name: prism - version: 1.29.0 + version: 1.30.0 prismjs_lineNumber_js: name: prismjs file: plugins/line-numbers/prism-line-numbers.min.js other_name: prism - version: 1.29.0 + version: 1.30.0 sharejs: name: butterfly-extsrc file: sharejs/dist/js/social-share.min.js @@ -190,7 +190,7 @@ snackbar_css: twikoo: name: twikoo file: dist/twikoo.all.min.js - version: 1.6.41 + version: 1.6.42 typed: name: typed.js file: dist/typed.umd.js @@ -203,9 +203,9 @@ waline_css: name: '@waline/client' file: dist/waline.css other_name: waline - version: 3.5.5 + version: 3.5.7 waline_js: name: '@waline/client' file: dist/waline.js other_name: waline - version: 3.5.5 + version: 3.5.7 diff --git a/scripts/common/postDesc.js b/scripts/common/postDesc.js index f2d547f..39e3760 100644 --- a/scripts/common/postDesc.js +++ b/scripts/common/postDesc.js @@ -3,13 +3,14 @@ const { stripHTML, truncate } = require('hexo-util') // Truncates the given content to a specified length, removing HTML tags and replacing newlines with spaces. -const truncateContent = (content, length) => { - return truncate(stripHTML(content), { length, separator: ' ' }).replace(/\n/g, ' ') +const truncateContent = (content, length, encrypt = false) => { + if (!content || encrypt) return '' + return truncate(stripHTML(content).replace(/\n/g, ' '), { length }) } // Generates a post description based on the provided data and theme configuration. const postDesc = (data, hexo) => { - const { description, content, postDesc } = data + const { description, content, postDesc, encrypt } = data if (postDesc) return postDesc @@ -23,10 +24,10 @@ const postDesc = (data, hexo) => { result = description break case 2: - result = description || truncateContent(content, length) + result = description || truncateContent(content, length, encrypt) break default: - result = truncateContent(content, length) + result = truncateContent(content, length, encrypt) } data.postDesc = result diff --git a/scripts/helpers/aside_archives.js b/scripts/helpers/aside_archives.js index dd07b57..6301224 100644 --- a/scripts/helpers/aside_archives.js +++ b/scripts/helpers/aside_archives.js @@ -2,11 +2,7 @@ hexo.extend.helper.register('aside_archives', function (options = {}) { const { config, page, site, url_for, _p } = this - const { - archive_dir: archiveDir, - timezone, - language - } = config + const { archive_dir: archiveDir, timezone, language } = config // Destructure and set default options with object destructuring const { @@ -22,33 +18,42 @@ hexo.extend.helper.register('aside_archives', function (options = {}) { const lang = toMomentLocale(page.lang || page.language || language) // Memoize comparison function to improve performance - const compareFunc = type === 'monthly' - ? (yearA, monthA, yearB, monthB) => yearA === yearB && monthA === monthB - : (yearA, yearB) => yearA === yearB + const compareFunc = + type === 'monthly' + ? (yearA, monthA, yearB, monthB) => yearA === yearB && monthA === monthB + : (yearA, yearB) => yearA === yearB // Early return if no posts if (!site.posts.length) return '' // Use reduce for more efficient data processing - const data = site.posts - .sort('date', order) - .reduce((acc, post) => { - let date = post.date.clone() - if (timezone) date = date.tz(timezone) + const data = site.posts.sort('date', order).reduce((acc, post) => { + let date = post.date.clone() + if (timezone) date = date.tz(timezone) - const year = date.year() - const month = date.month() + 1 + const year = date.year() + const month = date.month() + 1 - if (lang) date = date.locale(lang) + if (lang) date = date.locale(lang) - // Find or create archive entry - const lastEntry = acc[acc.length - 1] - if (!lastEntry || !compareFunc( - lastEntry.year, - lastEntry.month, - year, - month - )) { + // Find or create archive entry + const lastEntry = acc[acc.length - 1] + + if (type === 'yearly') { + const existingYearIndex = acc.findIndex(entry => entry.year === year) + if (existingYearIndex !== -1) { + acc[existingYearIndex].count++ + } else { + // 否則創建新條目 + acc.push({ + name: date.format(format), + year, + month, + count: 1 + }) + } + } else { + if (!lastEntry || !compareFunc(lastEntry.year, lastEntry.month, year, month)) { acc.push({ name: date.format(format), year, @@ -58,9 +63,10 @@ hexo.extend.helper.register('aside_archives', function (options = {}) { } else { lastEntry.count++ } + } - return acc - }, []) + return acc + }, []) // Create link generator function const createArchiveLink = item => { @@ -72,39 +78,41 @@ hexo.extend.helper.register('aside_archives', function (options = {}) { } // Limit results efficiently - const limitedData = limit > 0 - ? data.slice(0, Math.min(data.length, limit)) - : data + const limitedData = limit > 0 ? data.slice(0, Math.min(data.length, limit)) : data // Use template literal for better readability const archiveHeader = `
${_p('aside.card_archives')} - ${data.length > limitedData.length - ? ` limitedData.length + ? ` ` - : ''} + : '' + }
` // Use map for generating list items, join for performance const archiveList = ` ` diff --git a/source/css/_page/homepage.styl b/source/css/_page/homepage.styl index 62bb2b2..f613119 100644 --- a/source/css/_page/homepage.styl +++ b/source/css/_page/homepage.styl @@ -171,4 +171,5 @@ $indexEnable = hexo-config('cover.index_enable') & > .content @extend .limit-more-line - -webkit-line-clamp: 2 \ No newline at end of file + -webkit-line-clamp: 2 + word-break: break-word \ No newline at end of file