From 4c95f401bc84647a3ea0d07b1a8a96b1de42c529 Mon Sep 17 00:00:00 2001 From: Luk Date: Sat, 7 Feb 2026 11:36:04 +0800 Subject: [PATCH] u --- seafile-ignore.txt | 12 ++++++++++++ tool_core.js | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/seafile-ignore.txt b/seafile-ignore.txt index f761786..d0a7486 100644 --- a/seafile-ignore.txt +++ b/seafile-ignore.txt @@ -22,6 +22,12 @@ *.nosf/ *.nosf.*/ +## everything 'git pull or fetch' will update `.git/FETCH_HEAD`, even if the content doesn't change. To avoid too many useless updates of this file in Seafile history: +FETCH_HEAD +*/FETCH_HEAD + +.Trash/ + .DS_Store */.DS_Store @@ -48,12 +54,18 @@ _desktop.ini node_modules/ */node_modules/ package-lock.json +*/package-lock.json pages4loader.json5 +*/pages4loader.json5 .deploy_git/ */.deploy_git/ +# next.js 项目 +.next/ +*/.next/ + # HBuilder 目录 unpackage/ */unpackage/ diff --git a/tool_core.js b/tool_core.js index 1723384..058ec60 100644 --- a/tool_core.js +++ b/tool_core.js @@ -38,18 +38,42 @@ module.exports = { return obj }, + parse_json (value, { failsafe } = {}) { + failsafe = typeof failsafe !== 'undefined' ? failsafe : value + if (typeof value === 'object') return value + else if (typeof value === 'string') { + try { + return JSON.parse(value) + } catch (e) { + return failsafe + } + } else { + return failsafe + } + }, + parse_json_anyway (value) { - try { - return JSON.parse(value) - } catch (e) { + if (typeof value === 'object') return value + else if (typeof value === 'string') { + try { + return JSON.parse(value) + } catch (e) { + return undefined + } + } else { return undefined } }, parse_json_or_keep (value) { - try { - return JSON.parse(value) - } catch (e) { + if (typeof value === 'object') return value + else if (typeof value === 'string') { + try { + return JSON.parse(value) + } catch (e) { + return value + } + } else { return value } }, @@ -342,7 +366,6 @@ module.exports = { } }, - // 20250621 todo 如果 text 是 {enUS,zhCN} 怎么处理 extract_story_title ({ story, lang = 'enUS' } = {}) { if (Array.isArray(story) && story.length) { return (