From 8b103f7c26623abc47c84038799f675de5797a45 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 10 Nov 2026 17:46:52 +0800 Subject: [PATCH] Update App.jsx via upload script - 2026-11-10 17:46:36 --- App.jsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/App.jsx b/App.jsx index 41719a3..87628a5 100644 --- a/App.jsx +++ b/App.jsx @@ -7173,6 +7173,13 @@ const NEWS_LINK_PAGES = [ const NEWS_BLOCK_LABEL = { p: '段落', h: '小标题', quote: '引言', img: '图片', pair: '两图并排', gallery: '图集', yt: 'YouTube 视频', links: '相关产品' }; const nowCn = () => new Date(Date.now() + 8 * 3600e3).toISOString().slice(0, 16); const artText = (o) => String((o && (o.zh || o.en)) || ''); +// 早期导入的文章里可能带着 Word 标签残留("o:p>"、"/o:p>"):打开后台时自动清掉 +const OFFICE_JUNK_RE = /\n]{0,80}?>/g; +const cleanArtStr = (v) => (typeof v === 'string' ? v.replace(OFFICE_JUNK_RE, '').replace(/[ \t]{2,}/g, ' ').trim() : v); +const cleanArtObj = (o) => (o && typeof o === 'object' ? Object.fromEntries(Object.entries(o).map(([k, v]) => [k, ['zh', 'en', 'es', 'ru'].includes(k) ? cleanArtStr(v) : v])) : o); +const cleanArticle = (n) => ({ title: cleanArtObj(n.title), excerpt: cleanArtObj(n.excerpt), place: cleanArtObj(n.place), + blocks: (n.blocks || []).map(b => ({ ...cleanArtObj(b), ...(b.cap ? { cap: cleanArtObj(b.cap) } : {}) })) }); +const hasOfficeJunk = (n) => { OFFICE_JUNK_RE.lastIndex = 0; const r = OFFICE_JUNK_RE.test(JSON.stringify([n.title, n.excerpt, n.place, n.blocks])); OFFICE_JUNK_RE.lastIndex = 0; return r; }; const imgBlockType = (n) => (n <= 1 ? 'img' : n === 2 ? 'pair' : 'gallery'); function SiteNewsEditor({ news, setNews, onNotify }) { @@ -7241,6 +7248,7 @@ function SiteArticleItem({ n, open, toggle, update, remove, onNotify }) { const blocks = Array.isArray(n.blocks) ? n.blocks : []; const [showEn, setShowEn] = useState(false); const [uploading, setUploading] = useState(false); + useEffect(() => { if (hasOfficeJunk(n)) update(cleanArticle(n)); }, [n.id]); const setBlocks = (fn) => update(x => ({ blocks: fn(Array.isArray(x.blocks) ? x.blocks : []) })); const setBlock = (i, patch) => setBlocks(l => l.map((b, j) => (j === i ? { ...b, ...patch } : b))); const moveBlock = (i, d) => setBlocks(l => { const j = i + d; if (j < 0 || j >= l.length) return l; const c = [...l]; [c[i], c[j]] = [c[j], c[i]]; return c; });