Update App.jsx via upload script - 2026-11-10 17:46:36

This commit is contained in:
mike 2026-11-10 17:46:52 +08:00
parent 27f9bfc72a
commit 8b103f7c26
1 changed files with 8 additions and 0 deletions

View File

@ -7173,6 +7173,13 @@ const NEWS_LINK_PAGES = [
const NEWS_BLOCK_LABEL = { p: '段落', h: '小标题', quote: '引言', img: '图片', pair: '两图并排', gallery: '图集', yt: 'YouTube 视频', links: '相关产品' }; 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 nowCn = () => new Date(Date.now() + 8 * 3600e3).toISOString().slice(0, 16);
const artText = (o) => String((o && (o.zh || o.en)) || ''); const artText = (o) => String((o && (o.zh || o.en)) || '');
// 早期导入的文章里可能带着 Word 标签残留("o:p>"、"/o:p>"):打开后台时自动清掉
const OFFICE_JUNK_RE = /<?\/?(?:o|w|v|m|st\d+):[a-zA-Z]+[^>\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'); const imgBlockType = (n) => (n <= 1 ? 'img' : n === 2 ? 'pair' : 'gallery');
function SiteNewsEditor({ news, setNews, onNotify }) { 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 blocks = Array.isArray(n.blocks) ? n.blocks : [];
const [showEn, setShowEn] = useState(false); const [showEn, setShowEn] = useState(false);
const [uploading, setUploading] = 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 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 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; }); 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; });