Files
hexo-theme-butterfly/scripts/common/postDesc.js
Jerry cf059bd533 fix: 更新 package.json 和 plugins.yml 中的版本號
fix: 修正 truncateContent 函數, 加密文章不显示自动擷取內容
feat: 增加首頁樣式以支持單詞換行
fix: 修正 truncateContent 函數以正確處理自動擷取內容
fix: 修复 card_archives 计数 bug
fix: 修正分頁順序邏輯
2025-05-09 17:52:01 +08:00

38 lines
1.0 KiB
JavaScript

'use strict'
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, 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, encrypt } = data
if (postDesc) return postDesc
const { length, method } = hexo.theme.config.index_post_content
if (method === false) return
let result
switch (method) {
case 1:
result = description
break
case 2:
result = description || truncateContent(content, length, encrypt)
break
default:
result = truncateContent(content, length, encrypt)
}
data.postDesc = result
return result
}
module.exports = { truncateContent, postDesc }