// 导出《天下·拾遗 诗词篇 全稿(审阅版)》——供老板离线通读审定。每首:原诗+作者其时+考证+魂句+化用曲词。 // 输出 Word 可直接打开的 .doc(HTML)到 Downloads。 import { readFileSync, writeFileSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const REPO = path.resolve(__dirname, '../..'); const BACKEND = path.resolve(__dirname, '..'); const src = readFileSync(path.join(REPO, 'digital-me-web/src/data/shici.ts'), 'utf8'); const SHI = JSON.parse(src.match(/export const SHI: Shi\[\] = (\[[\s\S]*\]);/)[1]); const ERAS = JSON.parse(src.match(/export const SHI_ERAS:[^=]*= (\[[\s\S]*?\]);/)[1]); // Suno 风格指令在后端曲库(前端已剥配方)。审阅稿给老板自己看+喂Suno,带上。id: shici.ts 的 p.id ↔ music-library 的 shici: const LIB = JSON.parse(readFileSync(path.join(BACKEND, 'src/data/music-library.json'), 'utf8')); const sunoMap = {}; const clipMap = {}; for (const s of LIB) if (String(s.id).startsWith('shici:')) { const k = s.id.slice('shici:'.length); sunoMap[k] = s.sunoStyle || ''; clipMap[k] = s.clip || ''; } const esc = (s) => String(s == null ? '' : s).replace(/&/g, '&').replace(//g, '>'); const br = (s) => esc(s).replace(/\n/g, '
'); const generatedAt = new Date().toISOString().slice(0, 10); let body = ''; let n = 0; for (const era of ERAS) { const list = SHI.filter((p) => p.eraSlug === era.slug); if (!list.length) continue; body += `

${esc(era.label)} ${list.length} 首

`; for (const p of list) { n++; body += `
${n} ${esc(p.title)} ${esc(p.author)} ${esc(p.dynasty)} [${esc(p.id)}]
原诗
${br(p.text)}
${p.authorBrief ? `
作者其时
${br(p.authorBrief)}
` : ''} ${p.background ? `
创作背景
${br(p.background)}
` : ''} ${p.kao ? `
考证
${br(p.kao)}
` : ''} ${p.soulLine ? `
魂句
${br(p.soulLine)}
` : ''} ${p.song && p.song.lyrics ? `
化用曲词
${br(p.song.lyrics)}
${p.song.embedded ? `
嵌入原句:${br(p.song.embedded)}
` : ''}
` : '
(此首暂无化用曲词)
'} ${sunoMap[p.id] ? `
Suno 风格指令
${br(sunoMap[p.id])}
${clipMap[p.id] ? `
1分钟截取:${br(clipMap[p.id])}
` : ''}
` : '
(此首暂无 Suno 风格指令)
'}
`; } } const html = ` 天下·拾遗 诗词篇 全稿(审阅版)

天下 · 拾遗 · 诗词篇 全稿(审阅版)

共 ${SHI.length} 首 · 先秦至明清 · 每首含【化用曲词 + Suno 风格指令】· 生成 ${generatedAt} · 供离线审定
审阅用法:要改的请记下左上角编号或 [id](如 [tang-012]),回头告诉我批量改;改定后再一起做确权。
⚠ 本稿含 Suno 风格指令(=制作配方,仅你自己看/喂 Suno 用,前端已对用户隐藏,勿外传)。
${body} `; const OUT = 'C:/Users/solut/Downloads/天下诗词篇全稿-审阅版-含Suno风格.doc'; writeFileSync(OUT, '\uFEFF' + html, 'utf8'); console.log('已导出:', OUT); console.log('共', SHI.length, '首;有化用曲词的', SHI.filter((p) => p.song && p.song.lyrics).length, '首');