/** * 生成 server/utils/seed.ts(一次性工具)。 * * 从当前 i18n 文案 + 内容元数据转录出 articles/works 双语种子数据, * 供 DB 初始化时灌入,保证站点初始内容与改造前一致。 * * 用法: node scripts/generate-seed.mjs */ import { readFileSync, writeFileSync } from 'node:fs' const zh = JSON.parse(readFileSync('i18n/locales/zh.json', 'utf8')) const en = JSON.parse(readFileSync('i18n/locales/en.json', 'utf8')) // ---------- 动态元数据(与原 app/data/news.ts 一致) ---------- const articleMeta = [ { slug: 'design-trends-2026', category: 'insights', date: '2026-05-28', readTime: 5, author: 'ArcticNewOne', image: 'https://picsum.photos/id/1/800/500' }, { slug: 'forma-digital-launch', category: 'projects', date: '2026-05-15', readTime: 3, author: 'ArcticNewOne', image: 'https://picsum.photos/id/201/800/500' }, { slug: 'studio-expansion', category: 'announcements', date: '2026-05-10', readTime: 2, author: 'ArcticNewOne', image: 'https://picsum.photos/id/164/800/500' }, { slug: 'ux-research-methods', category: 'insights', date: '2026-04-28', readTime: 7, author: 'ArcticNewOne', image: 'https://picsum.photos/id/180/800/500' }, { slug: 'bold-moves-case-study', category: 'projects', date: '2026-04-20', readTime: 6, author: 'ArcticNewOne', image: 'https://picsum.photos/id/119/800/500' }, { slug: 'new-tools-integration', category: 'announcements', date: '2026-04-12', readTime: 4, author: 'ArcticNewOne', image: 'https://picsum.photos/id/326/800/500' }, ] // ---------- 作品元数据(与原 app/data/work.ts 一致) ---------- const workMeta = [ { slug: 'forma-digital', category: 'webDesign', year: '2026', tags: ['Web Design', 'E-commerce', 'React'], image: 'https://picsum.photos/id/201/1200/800', gallery: ['https://picsum.photos/id/201/800/600', 'https://picsum.photos/id/202/800/600', 'https://picsum.photos/id/203/800/600', 'https://picsum.photos/id/204/800/600'], url: null }, { slug: 'one-step', category: 'branding', year: '2024', tags: ['Branding', 'Marketing', 'UI/UX'], image: 'https://picsum.photos/id/180/1200/800', gallery: ['https://picsum.photos/id/180/800/600', 'https://picsum.photos/id/181/800/600', 'https://picsum.photos/id/182/800/600', 'https://picsum.photos/id/183/800/600'], url: null }, { slug: 'nero-vision', category: 'development', year: '2025', tags: ['Development', 'Vue.js', 'Node.js'], image: 'https://picsum.photos/id/119/1200/800', gallery: ['https://picsum.photos/id/119/800/600', 'https://picsum.photos/id/120/800/600', 'https://picsum.photos/id/121/800/600', 'https://picsum.photos/id/122/800/600'], url: null }, { slug: 'bold-moves', category: 'webDesign', year: '2024', tags: ['Web Design', '3D', 'Three.js'], image: 'https://picsum.photos/id/164/1200/800', gallery: ['https://picsum.photos/id/164/800/600', 'https://picsum.photos/id/165/800/600', 'https://picsum.photos/id/166/800/600', 'https://picsum.photos/id/167/800/600'], url: null }, { slug: 'echo-labs', category: 'branding', year: '2025', tags: ['Branding', 'Visual Identity', 'Corporate'], image: 'https://picsum.photos/id/101/1200/800', gallery: ['https://picsum.photos/id/101/800/600', 'https://picsum.photos/id/102/800/600', 'https://picsum.photos/id/103/800/600', 'https://picsum.photos/id/104/800/600'], url: null }, { slug: 'flux-api', category: 'development', year: '2025', tags: ['Development', 'API', 'Python'], image: 'https://picsum.photos/id/326/1200/800', gallery: ['https://picsum.photos/id/326/800/600', 'https://picsum.photos/id/327/800/600', 'https://picsum.photos/id/328/800/600', 'https://picsum.photos/id/329/800/600'], url: null }, ] // ---------- 文章正文块(从 i18n 转录) ---------- function articleBlocks(locale, slug) { const d = locale.detail.items[slug] return [ { type: 'paragraph', text: d.content }, { type: 'heading', text: d.section1Title }, { type: 'paragraph', text: d.section1Content }, { type: 'quote', text: d.quote }, { type: 'heading', text: d.section2Title }, { type: 'paragraph', text: d.section2Content }, { type: 'heading', text: d.section3Title }, { type: 'paragraph', text: d.section3Content }, ] } const articles = articleMeta.map((m) => ({ slug: m.slug, category: m.category, titleZh: zh.news.items[m.slug].title, titleEn: en.news.items[m.slug].title, excerptZh: zh.news.items[m.slug].excerpt, excerptEn: en.news.items[m.slug].excerpt, contentZh: articleBlocks(zh.news, m.slug), contentEn: articleBlocks(en.news, m.slug), image: m.image, date: m.date, readTime: m.readTime, author: m.author, published: 1, })) const works = workMeta.map((m) => ({ slug: m.slug, category: m.category, titleZh: zh.work.items[m.slug].title, titleEn: en.work.items[m.slug].title, descriptionZh: zh.work.items[m.slug].description, descriptionEn: en.work.items[m.slug].description, overviewZh: zh.work.detail.items[m.slug].overview, overviewEn: en.work.detail.items[m.slug].overview, challengeZh: zh.work.detail.items[m.slug].challenge, challengeEn: en.work.detail.items[m.slug].challenge, solutionZh: zh.work.detail.items[m.slug].solution, solutionEn: en.work.detail.items[m.slug].solution, clientZh: zh.work.detail.items[m.slug].client, clientEn: en.work.detail.items[m.slug].client, durationZh: zh.work.detail.items[m.slug].duration, durationEn: en.work.detail.items[m.slug].duration, year: m.year, tags: m.tags, image: m.image, gallery: m.gallery, url: m.url, published: 1, })) const out = `/** * 种子数据(由 scripts/generate-seed.mjs 生成,勿手改)。 * 站点初始内容:6 篇动态 + 6 个作品(中英双语)。 * DB 初始化(migrate)时若对应表为空则自动灌入。 */ import type { ArticleBlock } from './db' export interface ArticleSeed { slug: string category: 'insights' | 'projects' | 'announcements' titleZh: string titleEn: string excerptZh: string excerptEn: string contentZh: ArticleBlock[] contentEn: ArticleBlock[] image: string date: string readTime: number author: string published: number } export interface WorkSeed { slug: string category: 'webDesign' | 'branding' | 'development' titleZh: string titleEn: string descriptionZh: string descriptionEn: string overviewZh: string overviewEn: string challengeZh: string challengeEn: string solutionZh: string solutionEn: string clientZh: string clientEn: string durationZh: string durationEn: string year: string tags: string[] image: string gallery: string[] url: string | null published: number } export const articlesSeed: ArticleSeed[] = ${JSON.stringify(articles, null, 2)} export const worksSeed: WorkSeed[] = ${JSON.stringify(works, null, 2)} ` writeFileSync('server/utils/seed.ts', out) console.log(`seed.ts generated: ${articles.length} articles, ${works.length} works`)