From 5cb8755a001cf409089843234839282750a78735 Mon Sep 17 00:00:00 2001 From: Luk Date: Wed, 9 Apr 2025 19:47:33 +0800 Subject: [PATCH] add method `extract_story_title` --- tool_core.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tool_core.js b/tool_core.js index b25a3fc..c463414 100644 --- a/tool_core.js +++ b/tool_core.js @@ -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) {