build_creation_pattern_v2.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 构建创作思维路径可视化 V2
  5. 新版特性:
  6. - 同一个发现编号的节点使用相同的填充颜色
  7. - 边框颜色代表节点类型(灵感点、目的点、关键点)
  8. 读取 creation_pattern 目录下的 JSON 数据,输出单文件 HTML
  9. """
  10. import json
  11. import sys
  12. from pathlib import Path
  13. # 项目路径
  14. project_root = Path(__file__).parent.parent.parent
  15. sys.path.insert(0, str(project_root))
  16. from script.data_processing.path_config import PathConfig
  17. HTML_TEMPLATE = '''<!DOCTYPE html>
  18. <html lang="zh-CN">
  19. <head>
  20. <meta charset="UTF-8">
  21. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  22. <title>创作思维路径可视化</title>
  23. <script src="https://d3js.org/d3.v7.min.js"></script>
  24. <style>
  25. * { margin: 0; padding: 0; box-sizing: border-box; }
  26. body {
  27. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  28. background: #1a1a2e;
  29. color: #eee;
  30. overflow: hidden;
  31. }
  32. .container { display: flex; flex-direction: column; height: 100vh; }
  33. header {
  34. padding: 12px 20px;
  35. background: #16213e;
  36. border-bottom: 1px solid #0f3460;
  37. display: flex;
  38. align-items: center;
  39. gap: 20px;
  40. }
  41. h1 { font-size: 16px; font-weight: 500; color: #e94560; }
  42. .controls { display: flex; align-items: center; gap: 12px; flex: 1; }
  43. .slider-container {
  44. display: flex;
  45. align-items: center;
  46. gap: 8px;
  47. background: #0f3460;
  48. padding: 6px 12px;
  49. border-radius: 6px;
  50. }
  51. .slider-container label { font-size: 13px; color: #aaa; }
  52. #stepSlider { width: 200px; cursor: pointer; }
  53. #stepDisplay { font-size: 14px; font-weight: 600; color: #e94560; min-width: 60px; }
  54. .play-btn {
  55. background: #e94560;
  56. border: none;
  57. color: white;
  58. padding: 6px 14px;
  59. border-radius: 4px;
  60. cursor: pointer;
  61. font-size: 13px;
  62. }
  63. .play-btn:hover { background: #ff6b6b; }
  64. /* 图例 - 两行 */
  65. .legend {
  66. display: flex;
  67. flex-direction: column;
  68. gap: 6px;
  69. font-size: 11px;
  70. color: #888;
  71. margin-left: auto;
  72. background: #0f3460;
  73. padding: 8px 12px;
  74. border-radius: 6px;
  75. }
  76. .legend-row { display: flex; gap: 12px; align-items: center; }
  77. .legend-label { color: #666; font-size: 10px; min-width: 50px; }
  78. .legend-item { display: flex; align-items: center; gap: 4px; }
  79. .legend-dot { width: 10px; height: 10px; border-radius: 50%; }
  80. .legend-dot-border {
  81. width: 10px;
  82. height: 10px;
  83. border-radius: 50%;
  84. background: transparent;
  85. border: 2px solid;
  86. }
  87. .legend-line { width: 20px; height: 2px; }
  88. /* 主内容区:左右布局 */
  89. main { flex: 1; display: flex; overflow: hidden; }
  90. .graph-area { flex: 1; position: relative; }
  91. .graph-area svg { width: 100%; height: 100%; }
  92. /* 右侧面板 */
  93. .right-panel {
  94. width: 360px;
  95. background: #16213e;
  96. border-left: 1px solid #0f3460;
  97. display: flex;
  98. flex-direction: column;
  99. overflow: hidden;
  100. }
  101. /* 帖子摘要区 */
  102. .post-summary {
  103. padding: 16px;
  104. border-bottom: 1px solid #0f3460;
  105. max-height: 200px;
  106. overflow-y: auto;
  107. }
  108. .post-title {
  109. font-size: 14px;
  110. font-weight: 600;
  111. color: #e94560;
  112. margin-bottom: 8px;
  113. line-height: 1.4;
  114. }
  115. .post-body {
  116. font-size: 12px;
  117. color: #aaa;
  118. line-height: 1.6;
  119. max-height: 100px;
  120. overflow-y: auto;
  121. }
  122. .post-meta {
  123. margin-top: 8px;
  124. font-size: 11px;
  125. color: #666;
  126. display: flex;
  127. gap: 12px;
  128. }
  129. /* 步骤时间轴 */
  130. .timeline {
  131. flex: 1;
  132. overflow-y: auto;
  133. padding: 16px;
  134. }
  135. .timeline-title {
  136. font-size: 13px;
  137. font-weight: 600;
  138. color: #888;
  139. margin-bottom: 12px;
  140. }
  141. .timeline-item {
  142. position: relative;
  143. padding-left: 24px;
  144. padding-bottom: 16px;
  145. border-left: 2px solid #0f3460;
  146. margin-left: 8px;
  147. cursor: pointer;
  148. transition: all 0.2s;
  149. }
  150. .timeline-item:hover {
  151. background: rgba(233, 69, 96, 0.1);
  152. margin-left: 6px;
  153. padding-left: 26px;
  154. }
  155. .timeline-item:last-child { border-left-color: transparent; }
  156. .timeline-item.active { border-left-color: #e94560; }
  157. .timeline-item.future { opacity: 0.4; }
  158. .timeline-dot {
  159. position: absolute;
  160. left: -7px;
  161. top: 0;
  162. width: 12px;
  163. height: 12px;
  164. border-radius: 50%;
  165. border: 2px solid #0f3460;
  166. background: #1a1a2e;
  167. display: flex;
  168. align-items: center;
  169. justify-content: center;
  170. font-size: 8px;
  171. font-weight: bold;
  172. color: white;
  173. }
  174. .timeline-item.active .timeline-dot {
  175. border-color: #e94560;
  176. background: #e94560;
  177. }
  178. .timeline-node-name {
  179. font-size: 13px;
  180. font-weight: 500;
  181. color: #eee;
  182. margin-bottom: 4px;
  183. }
  184. .timeline-node-dim {
  185. font-size: 11px;
  186. padding: 2px 6px;
  187. border-radius: 3px;
  188. display: inline-block;
  189. margin-bottom: 6px;
  190. }
  191. .timeline-node-dim.灵感点 { background: rgba(255,107,107,0.2); color: #ff6b6b; }
  192. .timeline-node-dim.目的点 { background: rgba(78,205,196,0.2); color: #4ecdc4; }
  193. .timeline-node-dim.关键点 { background: rgba(255,230,109,0.2); color: #ffe66d; }
  194. .timeline-reason {
  195. font-size: 11px;
  196. color: #888;
  197. line-height: 1.5;
  198. background: #0f3460;
  199. padding: 8px;
  200. border-radius: 4px;
  201. }
  202. .timeline-from {
  203. font-size: 11px;
  204. color: #666;
  205. margin-bottom: 4px;
  206. }
  207. .timeline-from span { color: #e94560; }
  208. /* 节点样式 */
  209. .node { cursor: pointer; }
  210. .node circle { stroke-width: 3px; transition: all 0.3s; }
  211. .node.unknown circle { fill: #2a2a4a !important; stroke: #444 !important; opacity: 0.4; }
  212. .node.known circle { filter: drop-shadow(0 0 6px currentColor); }
  213. .node.highlight circle { stroke-width: 5px; filter: drop-shadow(0 0 12px currentColor); }
  214. .node text { font-size: 11px; fill: #ccc; text-anchor: middle; pointer-events: none; }
  215. .node.unknown text { fill: #555; }
  216. .node .order-badge { font-size: 10px; font-weight: bold; fill: white; }
  217. .link { stroke-opacity: 0.6; transition: all 0.3s; }
  218. .link.hidden { stroke-opacity: 0 !important; }
  219. .link.highlight { stroke-opacity: 1; stroke-width: 3px; }
  220. .link-label { font-size: 9px; fill: #888; pointer-events: none; }
  221. .link-label.hidden { opacity: 0; }
  222. </style>
  223. </head>
  224. <body>
  225. <div class="container">
  226. <header>
  227. <h1>创作思维路径</h1>
  228. <div class="controls">
  229. <div class="slider-container">
  230. <label>步骤:</label>
  231. <input type="range" id="stepSlider" min="0" max="9" value="9">
  232. <span id="stepDisplay">9/9</span>
  233. </div>
  234. <button class="play-btn" id="playBtn">▶ 播放</button>
  235. </div>
  236. <div class="legend">
  237. <div class="legend-row">
  238. <span class="legend-label">边框类型:</span>
  239. <div class="legend-item"><span class="legend-dot-border" style="border-color: #ff6b6b;"></span><span>灵感点</span></div>
  240. <div class="legend-item"><span class="legend-dot-border" style="border-color: #4ecdc4;"></span><span>目的点</span></div>
  241. <div class="legend-item"><span class="legend-dot-border" style="border-color: #ffe66d;"></span><span>关键点</span></div>
  242. </div>
  243. <div class="legend-row">
  244. <span class="legend-label">填充步骤:</span>
  245. <div class="legend-item"><span class="legend-dot" style="background: #e94560;"></span><span>步骤1</span></div>
  246. <div class="legend-item"><span class="legend-dot" style="background: #9b59b6;"></span><span>步骤2</span></div>
  247. <div class="legend-item"><span class="legend-dot" style="background: #3498db;"></span><span>步骤3...</span></div>
  248. </div>
  249. </div>
  250. </header>
  251. <main>
  252. <div class="graph-area">
  253. <svg id="graph"></svg>
  254. </div>
  255. <div class="right-panel">
  256. <div class="post-summary" id="postSummary"></div>
  257. <div class="timeline" id="timeline">
  258. <div class="timeline-title">推导过程</div>
  259. </div>
  260. </div>
  261. </main>
  262. </div>
  263. <script>
  264. const DATA = __DATA_PLACEHOLDER__;
  265. // 维度颜色(用于边框)
  266. const dimColors = { '灵感点': '#ff6b6b', '目的点': '#4ecdc4', '关键点': '#ffe66d' };
  267. // 步骤颜色调色板(用于填充,同一编号同一颜色)
  268. const stepColors = [
  269. '#e94560', // 1 - 红色
  270. '#9b59b6', // 2 - 紫色
  271. '#3498db', // 3 - 蓝色
  272. '#1abc9c', // 4 - 青色
  273. '#2ecc71', // 5 - 绿色
  274. '#f39c12', // 6 - 橙色
  275. '#e74c3c', // 7 - 深红
  276. '#8e44ad', // 8 - 深紫
  277. '#2980b9', // 9 - 深蓝
  278. '#16a085', // 10 - 深青
  279. '#27ae60', // 11 - 深绿
  280. '#d35400', // 12 - 深橙
  281. '#c0392b', // 13
  282. '#7b1fa2', // 14
  283. '#1565c0', // 15
  284. ];
  285. function getStepColor(order) {
  286. if (!order || order <= 0) return '#2a2a4a';
  287. return stepColors[(order - 1) % stepColors.length];
  288. }
  289. // 提取数据
  290. const postDetail = DATA['帖子详情'];
  291. const steps = DATA['步骤列表'];
  292. const lastStep = steps[steps.length - 1];
  293. const nodes = lastStep['输出']['节点列表'];
  294. const edges = lastStep['输出']['边列表'].filter(e => e['关系类型'] === 'AI推导');
  295. const maxOrder = Math.max(...nodes.map(n => n['发现编号'] || 0));
  296. // 构建边的查找表(目标节点 -> 边)
  297. const edgeByTarget = {};
  298. edges.forEach(e => { edgeByTarget[e['目标']] = e; });
  299. const nodeById = {};
  300. const graphNodes = nodes.map(n => {
  301. const node = {
  302. id: n['节点ID'],
  303. name: n['节点名称'],
  304. dimension: n['节点维度'],
  305. category: n['节点分类'],
  306. description: n['节点描述'],
  307. order: n['发现编号'],
  308. isKnown: n['是否已知']
  309. };
  310. nodeById[node.id] = node;
  311. return node;
  312. });
  313. const graphLinks = edges.map(e => ({
  314. source: e['来源'],
  315. target: e['目标'],
  316. type: e['关系类型'],
  317. score: e['可能性分数'],
  318. reason: e['推理说明']
  319. }));
  320. // 渲染帖子摘要
  321. function renderPostSummary() {
  322. const container = document.getElementById('postSummary');
  323. const bodyText = postDetail.body_text || '';
  324. const shortBody = bodyText.length > 150 ? bodyText.slice(0, 150) + '...' : bodyText;
  325. container.innerHTML = `
  326. <div class="post-title">${postDetail.postTitle || '无标题'}</div>
  327. <div class="post-body">${shortBody}</div>
  328. <div class="post-meta">
  329. <span>❤️ ${postDetail.like_count || 0}</span>
  330. <span>⭐ ${postDetail.collect_count || 0}</span>
  331. <span>${postDetail.publish_time || ''}</span>
  332. </div>
  333. `;
  334. }
  335. // 渲染时间轴
  336. function renderTimeline() {
  337. const container = document.getElementById('timeline');
  338. // 按发现顺序排序节点
  339. const sortedNodes = [...graphNodes].filter(n => n.order).sort((a, b) => a.order - b.order);
  340. let html = '<div class="timeline-title">推导过程</div>';
  341. sortedNodes.forEach(n => {
  342. const edge = edgeByTarget[n.id];
  343. const fromNode = edge ? nodeById[edge.source] : null;
  344. const stepColor = getStepColor(n.order);
  345. html += `
  346. <div class="timeline-item" data-order="${n.order}" data-node-id="${n.id}">
  347. <div class="timeline-dot" style="background: ${stepColor}; border-color: ${stepColor};">${n.order}</div>
  348. <div class="timeline-node-name">${n.name}</div>
  349. <div class="timeline-node-dim ${n.dimension}">${n.dimension}</div>
  350. ${fromNode ? `<div class="timeline-from">← 从 <span>${fromNode.name}</span> 推导</div>` : '<div class="timeline-from">起点</div>'}
  351. ${edge ? `<div class="timeline-reason">${edge.reason || ''}</div>` : ''}
  352. </div>
  353. `;
  354. });
  355. container.innerHTML = html;
  356. // 绑定点击事件
  357. container.querySelectorAll('.timeline-item').forEach(item => {
  358. item.addEventListener('click', () => {
  359. const order = parseInt(item.dataset.order);
  360. const nodeId = item.dataset.nodeId;
  361. slider.value = order;
  362. updateDisplay(order);
  363. highlightNode(nodeId);
  364. });
  365. item.addEventListener('mouseenter', () => {
  366. const nodeId = item.dataset.nodeId;
  367. highlightNode(nodeId);
  368. });
  369. item.addEventListener('mouseleave', () => {
  370. clearHighlight();
  371. });
  372. });
  373. }
  374. let currentStep = maxOrder;
  375. const slider = document.getElementById('stepSlider');
  376. const stepDisplay = document.getElementById('stepDisplay');
  377. const playBtn = document.getElementById('playBtn');
  378. slider.max = maxOrder;
  379. slider.value = maxOrder;
  380. const svg = d3.select('#graph');
  381. const graphArea = document.querySelector('.graph-area');
  382. const width = graphArea.clientWidth;
  383. const height = graphArea.clientHeight;
  384. const g = svg.append('g');
  385. const zoom = d3.zoom()
  386. .scaleExtent([0.2, 3])
  387. .on('zoom', (event) => g.attr('transform', event.transform));
  388. svg.call(zoom);
  389. svg.append('defs').append('marker')
  390. .attr('id', 'arrow')
  391. .attr('viewBox', '0 -5 10 10')
  392. .attr('refX', 20)
  393. .attr('refY', 0)
  394. .attr('markerWidth', 6)
  395. .attr('markerHeight', 6)
  396. .attr('orient', 'auto')
  397. .append('path')
  398. .attr('d', 'M0,-5L10,0L0,5')
  399. .attr('fill', '#e94560');
  400. const simulation = d3.forceSimulation(graphNodes)
  401. .force('link', d3.forceLink(graphLinks).id(d => d.id).distance(120))
  402. .force('charge', d3.forceManyBody().strength(-400))
  403. .force('center', d3.forceCenter(width / 2, height / 2))
  404. .force('collision', d3.forceCollide().radius(50));
  405. const link = g.append('g')
  406. .selectAll('line')
  407. .data(graphLinks)
  408. .join('line')
  409. .attr('class', 'link')
  410. .attr('stroke', '#e94560')
  411. .attr('stroke-width', 2)
  412. .attr('marker-end', 'url(#arrow)');
  413. const linkLabel = g.append('g')
  414. .selectAll('text')
  415. .data(graphLinks)
  416. .join('text')
  417. .attr('class', 'link-label')
  418. .text(d => d.score?.toFixed(2) || '');
  419. const node = g.append('g')
  420. .selectAll('g')
  421. .data(graphNodes)
  422. .join('g')
  423. .attr('class', d => `node dim-${d.dimension}`)
  424. .call(d3.drag()
  425. .on('start', dragstarted)
  426. .on('drag', dragged)
  427. .on('end', dragended))
  428. .on('click', (event, d) => {
  429. slider.value = d.order || maxOrder;
  430. updateDisplay(d.order || maxOrder);
  431. })
  432. .on('mouseenter', (event, d) => highlightNode(d.id))
  433. .on('mouseleave', () => clearHighlight());
  434. // 节点圆形:填充色按步骤编号,边框色按维度类型
  435. node.append('circle')
  436. .attr('r', 18)
  437. .attr('fill', d => getStepColor(d.order)) // 填充色按编号
  438. .attr('stroke', d => dimColors[d.dimension] || '#888'); // 边框色按类型
  439. node.append('text')
  440. .attr('class', 'order-badge')
  441. .attr('dy', 4)
  442. .text(d => d.order || '');
  443. node.append('text')
  444. .attr('dy', 35)
  445. .text(d => d.name);
  446. simulation.on('tick', () => {
  447. link.attr('x1', d => d.source.x).attr('y1', d => d.source.y)
  448. .attr('x2', d => d.target.x).attr('y2', d => d.target.y);
  449. linkLabel.attr('x', d => (d.source.x + d.target.x) / 2)
  450. .attr('y', d => (d.source.y + d.target.y) / 2 - 8);
  451. node.attr('transform', d => `translate(${d.x},${d.y})`);
  452. });
  453. function dragstarted(event, d) {
  454. if (!event.active) simulation.alphaTarget(0.3).restart();
  455. d.fx = d.x; d.fy = d.y;
  456. }
  457. function dragged(event, d) { d.fx = event.x; d.fy = event.y; }
  458. function dragended(event, d) {
  459. if (!event.active) simulation.alphaTarget(0);
  460. d.fx = null; d.fy = null;
  461. }
  462. // 高亮节点
  463. function highlightNode(nodeId) {
  464. node.classed('highlight', d => d.id === nodeId);
  465. // 高亮相关边
  466. link.classed('highlight', d => d.target.id === nodeId || d.target === nodeId);
  467. // 高亮时间轴项
  468. document.querySelectorAll('.timeline-item').forEach(item => {
  469. item.classList.toggle('active', item.dataset.nodeId === nodeId);
  470. });
  471. }
  472. function clearHighlight() {
  473. node.classed('highlight', false);
  474. link.classed('highlight', false);
  475. }
  476. function updateDisplay(step) {
  477. currentStep = step;
  478. stepDisplay.textContent = `${step}/${maxOrder}`;
  479. node.classed('known', d => d.order && d.order <= step);
  480. node.classed('unknown', d => !d.order || d.order > step);
  481. link.classed('hidden', d => {
  482. const srcKnown = nodeById[d.source.id || d.source]?.order <= step;
  483. const tgtKnown = nodeById[d.target.id || d.target]?.order <= step;
  484. return !srcKnown || !tgtKnown;
  485. });
  486. linkLabel.classed('hidden', d => {
  487. const srcKnown = nodeById[d.source.id || d.source]?.order <= step;
  488. const tgtKnown = nodeById[d.target.id || d.target]?.order <= step;
  489. return !srcKnown || !tgtKnown;
  490. });
  491. // 更新时间轴状态
  492. document.querySelectorAll('.timeline-item').forEach(item => {
  493. const order = parseInt(item.dataset.order);
  494. item.classList.toggle('future', order > step);
  495. });
  496. }
  497. slider.addEventListener('input', (e) => updateDisplay(parseInt(e.target.value)));
  498. let playing = false, playInterval = null;
  499. playBtn.addEventListener('click', () => {
  500. if (playing) {
  501. clearInterval(playInterval);
  502. playBtn.textContent = '▶ 播放';
  503. playing = false;
  504. } else {
  505. if (currentStep >= maxOrder) { currentStep = 0; slider.value = 0; updateDisplay(0); }
  506. playing = true;
  507. playBtn.textContent = '⏸ 暂停';
  508. playInterval = setInterval(() => {
  509. currentStep++;
  510. slider.value = currentStep;
  511. updateDisplay(currentStep);
  512. // 滚动时间轴到当前项
  513. const currentItem = document.querySelector(`.timeline-item[data-order="${currentStep}"]`);
  514. if (currentItem) currentItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
  515. if (currentStep >= maxOrder) {
  516. clearInterval(playInterval);
  517. playBtn.textContent = '▶ 播放';
  518. playing = false;
  519. }
  520. }, 1200);
  521. }
  522. });
  523. // 初始化
  524. renderPostSummary();
  525. renderTimeline();
  526. updateDisplay(maxOrder);
  527. setTimeout(() => {
  528. const bounds = g.node().getBBox();
  529. const scale = Math.min((width - 60) / bounds.width, (height - 60) / bounds.height, 1.2);
  530. const tx = (width - bounds.width * scale) / 2 - bounds.x * scale;
  531. const ty = (height - bounds.height * scale) / 2 - bounds.y * scale;
  532. svg.transition().duration(500).call(zoom.transform, d3.zoomIdentity.translate(tx, ty).scale(scale));
  533. }, 1000);
  534. </script>
  535. </body>
  536. </html>
  537. '''
  538. def main():
  539. import argparse
  540. parser = argparse.ArgumentParser(description='构建创作思维路径可视化 V2')
  541. parser.add_argument('input_dir', nargs='?', help='输入目录路径(可选,默认使用 PathConfig)')
  542. parser.add_argument('--version', '-v', type=str, default='v4',
  543. help='creation_pattern 版本 (v2/v3/v4),默认 v4')
  544. args = parser.parse_args()
  545. if args.input_dir:
  546. input_dir = Path(args.input_dir)
  547. print(f"输入目录: {input_dir}")
  548. else:
  549. config = PathConfig()
  550. input_dir = config.intermediate_dir / f"creation_pattern_{args.version}"
  551. print(f"账号: {config.account_name}")
  552. print(f"输入目录: {input_dir}")
  553. if not input_dir.exists():
  554. print(f"错误: 目录不存在!")
  555. sys.exit(1)
  556. # 查找所有创作模式文件
  557. pattern_files = sorted(input_dir.glob("*_创作模式.json"))
  558. print(f"找到 {len(pattern_files)} 个创作模式文件")
  559. if not pattern_files:
  560. print("错误: 没有找到创作模式文件!")
  561. sys.exit(1)
  562. # 为每个文件生成 HTML
  563. for pattern_file in pattern_files:
  564. post_id = pattern_file.stem.replace("_创作模式", "")
  565. print(f"\n处理: {post_id}")
  566. # 读取数据
  567. with open(pattern_file, "r", encoding="utf-8") as f:
  568. data = json.load(f)
  569. # 生成 HTML
  570. data_json = json.dumps(data, ensure_ascii=False)
  571. html_content = HTML_TEMPLATE.replace("__DATA_PLACEHOLDER__", data_json)
  572. # 输出文件
  573. output_file = input_dir / f"{post_id}_创作思维路径.html"
  574. with open(output_file, "w", encoding="utf-8") as f:
  575. f.write(html_content)
  576. print(f"输出: {output_file}")
  577. print("\n完成!")
  578. if __name__ == "__main__":
  579. main()