This commit is contained in:
myw committed 2024-10-20 17:47:28 +08:00
1 parent 95ca6878f0
commit c72f8c41ec
32 files changed
+207 -209

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
'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) => {
return truncate(stripHTML(content), { length, separator: ' ' }).replace(/\n/g, ' ')
}
// Generates a post description based on the provided data and theme configuration.
const postDesc = (data, hexo) => {
const { description, content, postDesc } = 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)
break
default:
result = truncateContent(content, length)
}
data.postDesc = result
return result
}
module.exports = { truncateContent, postDesc }
-3
View File
@@ -380,9 +380,6 @@ hexo.extend.filter.register('before_generate', () => {
tidio: {
public_key: null
},
daovoice: {
app_id: null
},
crisp: {
website_id: null
},
+6 -3
View File
@@ -1,10 +1,13 @@
'use strict'
const { stripHTML, prettyUrls, truncate } = require('hexo-util')
const { truncateContent, postDesc } = require('../common/postDesc')
const { prettyUrls } = require('hexo-util')
const crypto = require('crypto')
hexo.extend.helper.register('truncate', (content, length) => {
return truncate(stripHTML(content), { length, separator: ' ' }).replace(/\n/g, ' ')
hexo.extend.helper.register('truncate', truncateContent)
hexo.extend.helper.register('postDesc', data => {
return postDesc(data, hexo)
})
hexo.extend.helper.register('cloudTags', function (options = {}) {
Loaded 3 of 32 files, more files were not shown because too many files have changed in this diff. Show more