add method extract_story_title

This commit is contained in:
Luk 2025-04-09 19:47:33 +08:00
parent baeed8d332
commit 5cb8755a00

View File

@ -329,13 +329,26 @@ module.exports = {
// 返回新的数组
filter_story (story) {
if (Array.isArray(story)) {
if (Array.isArray(story) && story.length) {
return story.filter((section) => Object.values(section || {}).some((val) => !this.is_empty(val))) // (section.text || section.image || section.video)?.trim?.()
} else {
return []
}
},
extract_story_title (story) {
if (Array.isArray(story) && story.length) {
return (
story
.map(({ text = '' } = {}) => text.trim().replace(/\n/g, ' '))
.join(' ')
.substring(0, 140) || ''
)
} else {
return ''
}
},
is_empty (data) {
// empty: undefined, null, false, 0, NaN, '', '空格tab, \n等', [], {}
if (data) {