#!/usr/bin/env node import fs from 'node:fs/promises'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { upsertMindspaceCoverMeta } from '../mindspace-cover-meta.mjs'; import { ensureWorkspaceHtmlThumbnail } from '../mindspace-workspace-thumbnails.mjs'; const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); const PATCHES = [ { rel: 'MindSpace/02f8634f-8988-4313-80e2-a289bb319faa/public/123.html', description: 'Tang 的 123 简单展示页', cover: { tag: '精选页面', emoji: '✨', accent: '#667eea', accent2: '#764ba2', subtitle: '欢迎来到 Tang 的 123 页面', cover: 'https://images.unsplash.com/photo-1557683316-973673baf926?auto=format&fit=crop&w=1200&q=80', }, }, { rel: 'MindSpace/02f8634f-8988-4313-80e2-a289bb319faa/public/essay.html', description: '夏夜的风,带着一丝凉意 — TKMind 散文', cover: { tag: '精选页面', emoji: '🌙', accent: '#4a5a9c', accent2: '#0b0e1a', subtitle: '夏夜随笔 · 星空与萤火', cover: 'https://images.unsplash.com/photo-1419242902214-272b4217a589?auto=format&fit=crop&w=1200&q=80', }, }, { rel: 'MindSpace/02f8634f-8988-4313-80e2-a289bb319faa/public/prose.html', description: '黄昏时分,河堤漫步 — 散文《黄昏书简》', cover: { tag: '精选页面', emoji: '🌅', accent: '#c9ad93', accent2: '#6b4f3a', subtitle: '黄昏书简 · 与时光温柔和解', cover: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?auto=format&fit=crop&w=1200&q=80', }, }, { rel: 'MindSpace/1c99b83b-0454-474f-a5d2-129d34506a32/public/MIT-计算机科学课程学习路线.html', description: 'MIT 计算机科学课程体系 · 分阶段学习路线与资源汇总', cover: { tag: '报告', emoji: '📚', accent: '#6a67ce', accent2: '#24243e', subtitle: '7 大章节 · 从数学基础到 AI 方向', cover: 'https://images.unsplash.com/photo-1517694712202-9963a793792c?auto=format&fit=crop&w=1200&q=80', }, }, { rel: 'MindSpace/1c99b83b-0454-474f-a5d2-129d34506a32/public/太湖三白.html', description: '太湖三白 · 白鱼、白虾、银鱼 — 江南水中三宝', cover: { tag: '美食', emoji: '🐟', accent: '#2e86ab', accent2: '#0b2a44', subtitle: '千年太湖,一味三鲜', cover: 'https://images.unsplash.com/photo-1546069901-ba9599a7e63c?auto=format&fit=crop&w=1200&q=80', }, }, { rel: 'MindSpace/1c99b83b-0454-474f-a5d2-129d34506a32/public/春江花月夜.html', description: '春江花月夜 · 张若虚 — 孤篇盖全唐', cover: { tag: '精选页面', emoji: '🌕', accent: '#c9a227', accent2: '#0a0e1a', subtitle: '春江潮水连海平 · 海上明月共潮生', cover: 'https://images.unsplash.com/photo-1444703686981-a3abbc4d4fe3?auto=format&fit=crop&w=1200&q=80', }, }, ]; function upsertDescription(html, description) { const meta = ``; if (/]+name=["']description["']/i.test(html)) { return html.replace(/]+name=["']description["'][^>]*>/i, meta); } if (/]+name=["']viewport["'][^>]*>/i.test(html)) { return html.replace(/(]+name=["']viewport["'][^>]*>)/i, `$1\n${meta}`); } return html.replace(/]*)>/i, `\n${meta}`); } function upsertPlatformBrand(html) { if (/data-mindspace-page-tag=["']platform-brand["']/i.test(html)) return html; const brand = '\n

TKMind · 智趣

\n'; return html.replace(/<\/body>/i, `${brand}`); } for (const patch of PATCHES) { const abs = path.join(root, patch.rel); let html = await fs.readFile(abs, 'utf8'); html = upsertDescription(html, patch.description); html = upsertMindspaceCoverMeta(html, patch.cover); html = upsertPlatformBrand(html); await fs.writeFile(abs, html, 'utf8'); const publishDir = path.dirname(abs); const htmlRel = path.basename(abs); await ensureWorkspaceHtmlThumbnail(publishDir, htmlRel, html, { title: patch.cover.subtitle.split('·')[0].trim(), subtitle: patch.description, force: true, }); console.log(`✓ ${patch.rel}`); } console.log('\n完成 6 页 patch + 缩略图重建');