Files
memind/scripts/trigger-news002-generate-draft.mjs
T
John b74ab4ec46
Memind CI / Test, build, and release guards (push) Has been cancelled
feat(wechat): news002 草稿左上角小图,配图本地化且缺图保留文字卡
微信 inline 与静态页 lead-card 统一为左侧缩略图;远程配图下载到当日 public/ 后再上传微信素材。SearXNG 预取与配图 enrichment 链路同步收紧,禁止默认占位小图删卡。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-22 07:36:20 +08:00

96 lines
3.6 KiB
JavaScript

#!/usr/bin/env node
/**
* 将 news_morning_draft 切到 news002 并触发一次强制重生成(143 worker 拾取)。
*
* 用法:
* node scripts/trigger-news002-generate-draft.mjs
* node scripts/trigger-news002-generate-draft.mjs --apply
* node scripts/trigger-news002-generate-draft.mjs --apply --restore-template
*/
import process from 'node:process';
import mysql from 'mysql2/promise';
import { loadH5Environment } from './load-env.mjs';
loadH5Environment(import.meta.dirname);
const CONFIG_KEY = 'news_morning_draft';
const CONFIG_TABLE = 'h5_wechat_admin_config';
/** Agent 易回退到旧 daily-news 骨架,必须显式禁止 news001 DOM。 */
export const NEWS002_FORCE_TASK_APPEND = [
'【强制 news002 版式 · 覆盖一切旧稿参考】',
'1. 禁止输出 news001 结构:不得出现 class="hero"、class="date-badge"、class="quick-links"、class="highlight-box"、背景 #f7fafc / 主色 #b0191e。',
'2. 必须使用 news002 结构:div.masthead + div.lede + a.lead-card + ol.brief + div.card[data-event-key],并内嵌 taskSpec 里的 NEWS002_STYLE_BLOCK(暖纸 #FAF7F2、主色 #C8362F)。',
'3. 写页前不要 read_file 任何旧 daily-news-*.html 学版式;旧稿正文禁止复用。只允许按本 taskSpec 生成。',
'4. 全页每张故事卡必须带 data-event-key;独立事件 ≤28;flex 栏目无独立事件则整节删除。',
'5. 导航仅保留 news002 8 个主锚点(速读/头条/深读/国内/国际/财经/科技/天气/知识),禁止 25 项 quick-links。',
].join('\n');
async function main() {
const apply = process.argv.includes('--apply');
const restoreTemplate = process.argv.includes('--restore-template');
if (!process.env.DATABASE_URL) {
console.error('DATABASE_URL missing');
process.exit(1);
}
const pool = mysql.createPool({ uri: process.env.DATABASE_URL, connectionLimit: 2 });
const [rows] = await pool.query(
`SELECT config_json FROM ${CONFIG_TABLE} WHERE config_key = ? LIMIT 1`,
[CONFIG_KEY],
);
const current = rows[0]?.config_json
? (typeof rows[0].config_json === 'string'
? JSON.parse(rows[0].config_json)
: rows[0].config_json)
: {};
const previousTemplateId = current.templateId ?? 'news001';
const next = {
...current,
enabled: current.enabled !== false,
templateId: restoreTemplate ? 'news001' : 'news002',
forceGenerateOnce: restoreTemplate ? false : true,
taskSpecAppend: restoreTemplate ? (current.taskSpecAppend ?? '') : NEWS002_FORCE_TASK_APPEND,
};
console.log(JSON.stringify({
apply,
restoreTemplate,
previousTemplateId,
nextTemplateId: next.templateId,
forceGenerateOnce: next.forceGenerateOnce,
sourceUserId: current.sourceUserId ?? null,
autoGenerateEnabled: current.autoGenerateEnabled ?? null,
autoPushEnabled: current.autoPushEnabled ?? null,
}, null, 2));
if (apply) {
const now = Date.now();
await pool.query(
`INSERT INTO ${CONFIG_TABLE} (config_key, config_json, updated_by, updated_at)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
config_json = VALUES(config_json),
updated_by = VALUES(updated_by),
updated_at = VALUES(updated_at)`,
[
CONFIG_KEY,
JSON.stringify(next),
restoreTemplate ? 'news002-restore-template' : 'news002-force-generate',
now,
],
);
console.log(restoreTemplate
? 'template restored to news001; forceGenerateOnce cleared'
: 'templateId=news002 + forceGenerateOnce=true persisted');
}
await pool.end();
}
main().catch((error) => {
console.error(error instanceof Error ? error.message : error);
process.exit(1);
});