This commit is contained in:
Luk 2025-06-21 20:27:44 +08:00
parent fc146dc10d
commit 5f3cc1fb12

View File

@ -332,23 +332,24 @@ module.exports = {
// 返回新的数组 // 返回新的数组
filter_story (story) { filter_story (story) {
if (Array.isArray(story) && story.length) { if (Array.isArray(story) && story.length) {
// section can contain property '_xxx' which shall not change filter result.
return story.filter((section) => { return story.filter((section) => {
if (!section) return false if (!section) return false
return Object.entries(section).some(([key, val]) => !key.startsWith('_') && !this.is_empty(val)) return Object.values(section).some((val) => !this.is_empty(val))
//return Object.entries(section).some(([key, val]) => !key.startsWith('_') && !this.is_empty(val)) // don't check properties '_xxx'
}) })
} else { } else {
return [] return []
} }
}, },
// 20250621 todo 如果 text 是 {enUS,zhCN} 怎么处理
extract_story_title (story) { extract_story_title (story) {
if (Array.isArray(story) && story.length) { if (Array.isArray(story) && story.length) {
return ( return (
story story
.map(({ text = '' } = {}) => text.trim().replace(/\n/g, ' ')) .map(({ text = '' } = {}) => text.trim?.()?.replace?.(/\n/g, ' '))
.join(' ') ?.join(' ')
.substring(0, 140) || '' ?.substring?.(0, 140) || ''
) )
} else { } else {
return '' return ''