fix: 更新 package.json 和 plugins.yml 中的版本號

fix: 修正 truncateContent 函數, 加密文章不显示自动擷取內容
feat: 增加首頁樣式以支持單詞換行
fix: 修正 truncateContent 函數以正確處理自動擷取內容
fix: 修复 card_archives 计数 bug
fix: 修正分頁順序邏輯
This commit is contained in:
Jerry
2025-05-09 17:52:01 +08:00
parent ca030589fb
commit cf059bd533
7 changed files with 73 additions and 63 deletions

View File

@@ -9,8 +9,8 @@ if theme.structured_data && page.layout === 'post'
const datePublished = page.date.toISOString() const datePublished = page.date.toISOString()
const dateModified = (page.updated || page.date).toISOString() const dateModified = (page.updated || page.date).toISOString()
const author = page.copyright_author || config.author const author = page.copyright_author || config.author
const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url; const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url
const authorHref = full_url_for(authorHrefVal); const authorHref = full_url_for(authorHrefVal)
const jsonLd = { const jsonLd = {
"@context": "https://schema.org", "@context": "https://schema.org",
@@ -25,9 +25,9 @@ if theme.structured_data && page.layout === 'post'
"name": author, "name": author,
"url": authorHref "url": authorHref
}] }]
}; }
jsonLdScript = JSON.stringify(jsonLd, null, 2); jsonLdScript = JSON.stringify(jsonLd, null, 2)
- -
script(type="application/ld+json"). script(type="application/ld+json").

View File

@@ -7,7 +7,7 @@
} }
if globalPageType === 'post' 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 nav#pagination.pagination-post
each direction, key in paginationOrder each direction, key in paginationOrder

View File

@@ -1,6 +1,6 @@
{ {
"name": "hexo-theme-butterfly", "name": "hexo-theme-butterfly",
"version": "5.4.0-b1", "version": "5.4.0-b2",
"description": "A Simple and Card UI Design theme for Hexo", "description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json", "main": "package.json",
"scripts": { "scripts": {

View File

@@ -9,7 +9,7 @@ activate_power_mode:
algolia_search: algolia_search:
name: algoliasearch name: algoliasearch
file: dist/lite/builds/browser.umd.js file: dist/lite/builds/browser.umd.js
version: 5.20.3 version: 5.24.0
aplayer_css: aplayer_css:
name: aplayer name: aplayer
file: dist/APlayer.min.css file: dist/APlayer.min.css
@@ -45,7 +45,7 @@ canvas_ribbon:
chartjs: chartjs:
name: chart.js name: chart.js
file: dist/chart.umd.js file: dist/chart.umd.js
version: 4.4.8 version: 4.4.9
clickShowText: clickShowText:
name: butterfly-extsrc name: butterfly-extsrc
file: dist/click-show-text.min.js file: dist/click-show-text.min.js
@@ -57,11 +57,11 @@ click_heart:
disqusjs: disqusjs:
name: disqusjs name: disqusjs
file: dist/browser/disqusjs.es2015.umd.min.js file: dist/browser/disqusjs.es2015.umd.min.js
version: 3.0.2 version: 3.1.0
disqusjs_css: disqusjs_css:
name: disqusjs name: disqusjs
file: dist/browser/styles/disqusjs.css file: dist/browser/styles/disqusjs.css
version: 3.0.2 version: 3.1.0
docsearch_css: docsearch_css:
name: '@docsearch/css' name: '@docsearch/css'
other_name: docsearch-css other_name: docsearch-css
@@ -111,17 +111,17 @@ instantpage:
instantsearch: instantsearch:
name: instantsearch.js name: instantsearch.js
file: dist/instantsearch.production.min.js file: dist/instantsearch.production.min.js
version: 4.77.3 version: 4.78.3
katex: katex:
name: katex name: katex
file: dist/katex.min.css file: dist/katex.min.css
other_name: KaTeX other_name: KaTeX
version: 0.16.21 version: 0.16.22
katex_copytex: katex_copytex:
name: katex name: katex
file: dist/contrib/copy-tex.min.js file: dist/contrib/copy-tex.min.js
other_name: KaTeX other_name: KaTeX
version: 0.16.21 version: 0.16.22
lazyload: lazyload:
name: vanilla-lazyload name: vanilla-lazyload
file: dist/lazyload.iife.min.js file: dist/lazyload.iife.min.js
@@ -137,7 +137,7 @@ medium_zoom:
mermaid: mermaid:
name: mermaid name: mermaid
file: dist/mermaid.min.js file: dist/mermaid.min.js
version: 11.4.1 version: 11.6.0
meting_js: meting_js:
name: butterfly-extsrc name: butterfly-extsrc
file: metingjs/dist/Meting.min.js file: metingjs/dist/Meting.min.js
@@ -160,17 +160,17 @@ prismjs_autoloader:
name: prismjs name: prismjs
file: plugins/autoloader/prism-autoloader.min.js file: plugins/autoloader/prism-autoloader.min.js
other_name: prism other_name: prism
version: 1.29.0 version: 1.30.0
prismjs_js: prismjs_js:
name: prismjs name: prismjs
file: prism.js file: prism.js
other_name: prism other_name: prism
version: 1.29.0 version: 1.30.0
prismjs_lineNumber_js: prismjs_lineNumber_js:
name: prismjs name: prismjs
file: plugins/line-numbers/prism-line-numbers.min.js file: plugins/line-numbers/prism-line-numbers.min.js
other_name: prism other_name: prism
version: 1.29.0 version: 1.30.0
sharejs: sharejs:
name: butterfly-extsrc name: butterfly-extsrc
file: sharejs/dist/js/social-share.min.js file: sharejs/dist/js/social-share.min.js
@@ -190,7 +190,7 @@ snackbar_css:
twikoo: twikoo:
name: twikoo name: twikoo
file: dist/twikoo.all.min.js file: dist/twikoo.all.min.js
version: 1.6.41 version: 1.6.42
typed: typed:
name: typed.js name: typed.js
file: dist/typed.umd.js file: dist/typed.umd.js
@@ -203,9 +203,9 @@ waline_css:
name: '@waline/client' name: '@waline/client'
file: dist/waline.css file: dist/waline.css
other_name: waline other_name: waline
version: 3.5.5 version: 3.5.7
waline_js: waline_js:
name: '@waline/client' name: '@waline/client'
file: dist/waline.js file: dist/waline.js
other_name: waline other_name: waline
version: 3.5.5 version: 3.5.7

View File

@@ -3,13 +3,14 @@
const { stripHTML, truncate } = require('hexo-util') const { stripHTML, truncate } = require('hexo-util')
// Truncates the given content to a specified length, removing HTML tags and replacing newlines with spaces. // Truncates the given content to a specified length, removing HTML tags and replacing newlines with spaces.
const truncateContent = (content, length) => { const truncateContent = (content, length, encrypt = false) => {
return truncate(stripHTML(content), { length, separator: ' ' }).replace(/\n/g, ' ') if (!content || encrypt) return ''
return truncate(stripHTML(content).replace(/\n/g, ' '), { length })
} }
// Generates a post description based on the provided data and theme configuration. // Generates a post description based on the provided data and theme configuration.
const postDesc = (data, hexo) => { const postDesc = (data, hexo) => {
const { description, content, postDesc } = data const { description, content, postDesc, encrypt } = data
if (postDesc) return postDesc if (postDesc) return postDesc
@@ -23,10 +24,10 @@ const postDesc = (data, hexo) => {
result = description result = description
break break
case 2: case 2:
result = description || truncateContent(content, length) result = description || truncateContent(content, length, encrypt)
break break
default: default:
result = truncateContent(content, length) result = truncateContent(content, length, encrypt)
} }
data.postDesc = result data.postDesc = result

View File

@@ -2,11 +2,7 @@
hexo.extend.helper.register('aside_archives', function (options = {}) { hexo.extend.helper.register('aside_archives', function (options = {}) {
const { config, page, site, url_for, _p } = this const { config, page, site, url_for, _p } = this
const { const { archive_dir: archiveDir, timezone, language } = config
archive_dir: archiveDir,
timezone,
language
} = config
// Destructure and set default options with object destructuring // Destructure and set default options with object destructuring
const { const {
@@ -22,7 +18,8 @@ hexo.extend.helper.register('aside_archives', function (options = {}) {
const lang = toMomentLocale(page.lang || page.language || language) const lang = toMomentLocale(page.lang || page.language || language)
// Memoize comparison function to improve performance // Memoize comparison function to improve performance
const compareFunc = type === 'monthly' const compareFunc =
type === 'monthly'
? (yearA, monthA, yearB, monthB) => yearA === yearB && monthA === monthB ? (yearA, monthA, yearB, monthB) => yearA === yearB && monthA === monthB
: (yearA, yearB) => yearA === yearB : (yearA, yearB) => yearA === yearB
@@ -30,9 +27,7 @@ hexo.extend.helper.register('aside_archives', function (options = {}) {
if (!site.posts.length) return '' if (!site.posts.length) return ''
// Use reduce for more efficient data processing // Use reduce for more efficient data processing
const data = site.posts const data = site.posts.sort('date', order).reduce((acc, post) => {
.sort('date', order)
.reduce((acc, post) => {
let date = post.date.clone() let date = post.date.clone()
if (timezone) date = date.tz(timezone) if (timezone) date = date.tz(timezone)
@@ -43,12 +38,22 @@ hexo.extend.helper.register('aside_archives', function (options = {}) {
// Find or create archive entry // Find or create archive entry
const lastEntry = acc[acc.length - 1] const lastEntry = acc[acc.length - 1]
if (!lastEntry || !compareFunc(
lastEntry.year, if (type === 'yearly') {
lastEntry.month, const existingYearIndex = acc.findIndex(entry => entry.year === year)
if (existingYearIndex !== -1) {
acc[existingYearIndex].count++
} else {
// 否則創建新條目
acc.push({
name: date.format(format),
year, year,
month month,
)) { count: 1
})
}
} else {
if (!lastEntry || !compareFunc(lastEntry.year, lastEntry.month, year, month)) {
acc.push({ acc.push({
name: date.format(format), name: date.format(format),
year, year,
@@ -58,6 +63,7 @@ hexo.extend.helper.register('aside_archives', function (options = {}) {
} else { } else {
lastEntry.count++ lastEntry.count++
} }
}
return acc return acc
}, []) }, [])
@@ -72,39 +78,41 @@ hexo.extend.helper.register('aside_archives', function (options = {}) {
} }
// Limit results efficiently // Limit results efficiently
const limitedData = limit > 0 const limitedData = limit > 0 ? data.slice(0, Math.min(data.length, limit)) : data
? data.slice(0, Math.min(data.length, limit))
: data
// Use template literal for better readability // Use template literal for better readability
const archiveHeader = ` const archiveHeader = `
<div class="item-headline"> <div class="item-headline">
<i class="fas fa-archive"></i> <i class="fas fa-archive"></i>
<span>${_p('aside.card_archives')}</span> <span>${_p('aside.card_archives')}</span>
${data.length > limitedData.length ${
data.length > limitedData.length
? `<a class="card-more-btn" href="${url_for(archiveDir)}/" ? `<a class="card-more-btn" href="${url_for(archiveDir)}/"
title="${_p('aside.more_button')}"> title="${_p('aside.more_button')}">
<i class="fas fa-angle-right"></i> <i class="fas fa-angle-right"></i>
</a>` </a>`
: ''} : ''
}
</div> </div>
` `
// Use map for generating list items, join for performance // Use map for generating list items, join for performance
const archiveList = ` const archiveList = `
<ul class="card-archive-list"> <ul class="card-archive-list">
${limitedData.map(item => ` ${limitedData
.map(
item => `
<li class="card-archive-list-item"> <li class="card-archive-list-item">
<a class="card-archive-list-link" href="${createArchiveLink(item)}"> <a class="card-archive-list-link" href="${createArchiveLink(item)}">
<span class="card-archive-list-date"> <span class="card-archive-list-date">
${transform ? transform(item.name) : item.name} ${transform ? transform(item.name) : item.name}
</span> </span>
${showCount ${showCount ? `<span class="card-archive-list-count">${item.count}</span>` : ''}
? `<span class="card-archive-list-count">${item.count}</span>`
: ''}
</a> </a>
</li> </li>
`).join('')} `
)
.join('')}
</ul> </ul>
` `

View File

@@ -172,3 +172,4 @@ $indexEnable = hexo-config('cover.index_enable')
& > .content & > .content
@extend .limit-more-line @extend .limit-more-line
-webkit-line-clamp: 2 -webkit-line-clamp: 2
word-break: break-word