u
This commit is contained in:
12
tool_core.js
12
tool_core.js
@@ -332,7 +332,11 @@ module.exports = {
|
||||
// 返回新的数组
|
||||
filter_story (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?.()
|
||||
// section can contain property '_xxx' which shall not change filter result.
|
||||
return story.filter((section) => {
|
||||
if (!section) return false
|
||||
return Object.entries(section).some(([key, val]) => !key.startsWith('_') && !this.is_empty(val))
|
||||
})
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
@@ -354,7 +358,7 @@ module.exports = {
|
||||
summarize_story (story = []) {
|
||||
// story is an array of objects, each object could either be {text:'some string'}, {image: url} or {video:url}. Please construct a summary object as result: { textLength, imageCount, VideoCount }
|
||||
return story.reduce(
|
||||
(summary, { text, image, video, file, linkTarget } = {}) => {
|
||||
(summary, { text, image, video, audio, file, linkTarget } = {}) => {
|
||||
if (text) {
|
||||
summary.textLength += text.length
|
||||
summary.wordCount += text.split(/\s+/).length
|
||||
@@ -362,6 +366,8 @@ module.exports = {
|
||||
summary.imageCount++
|
||||
} else if (video) {
|
||||
summary.videoCount++
|
||||
} else if (audio) {
|
||||
summary.audioCount++
|
||||
} else if (file) {
|
||||
summary.fileCount++
|
||||
} else if (linkTarget) {
|
||||
@@ -371,7 +377,7 @@ module.exports = {
|
||||
}
|
||||
return summary
|
||||
},
|
||||
{ textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0, fileCount: 0, linkCount: 0, untypeCount: 0 }
|
||||
{ textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0, audioCount: 0, fileCount: 0, linkCount: 0, untypeCount: 0 }
|
||||
)
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user