#!/usr/bin/env node 'use strict' // 站点生成器:用 site/_home.tpl.html 与 site/_plugins.tpl.html 渲染首页 / 插件页, // 数据来自 site/releases.json(版本)与 market/index.json(插件)。 const fs = require('fs') const path = require('path') const root = path.resolve(__dirname, '..') const site = path.join(root, 'site') const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])) const mb = (n) => (Number(n) / 1048576).toFixed(1) + ' MB' const data = JSON.parse(fs.readFileSync(path.join(site, 'releases.json'), 'utf8')) const rel = Array.isArray(data.releases) ? data.releases.slice() : (Array.isArray(data) ? data.slice() : []) rel.sort((a, b) => String(b.version).localeCompare(String(a.version), undefined, { numeric: true })) const latest = rel[0] || { version: '', platforms: {} } const V = esc(latest.version) const STAMP = encodeURIComponent(V + '-' + Date.now().toString(36)) const marketFile = path.join(root, 'market', 'index.json') const market = fs.existsSync(marketFile) ? JSON.parse(fs.readFileSync(marketFile, 'utf8')) : { plugins: [] } const plugins = Array.isArray(market.plugins) ? market.plugins : [] const nav = (active) => [ '', ].join('\n') const footer = [ '', ].join('\n') const card = (p) => [ '
', '
' + esc(p.icon || '◻') + '', '
' + esc(p.name || p.id) + '
v' + esc(p.version || '') + ' · ' + esc(p.author === 'official' ? '官方' : (p.author || '')) + '
', '
' + esc(p.desc || '') + '
', '
' + (p.tags || []).map((t) => '' + esc(t) + '').join('') + '
', '
', ].join('\n') const feats = [ ['💻', '#eef2ff', '本地优先', '图片与数据保存在 ~/Documents/ImageWorkbench,不经服务器中转;可整目录备份、迁移到新电脑。'], ['🕸️', '#fff7ed', '节点式无限画布', '参考图 → 提示词 → 生成 → 图库,用连线把工作流串起来;一张画布容纳整条生产线。'], ['🧩', '#ecfdf5', '插件按需安装', '应用本体不含插件,需要什么装什么;可随时启停,关闭后入口自动隐藏。'], ] const featCards = feats.map((f) => [ '
' + f[0] + '
', '

' + f[2] + '

' + f[3] + '

', ].join('\n')).join('\n') const dlCards = [ ['darwin-aarch64', 'macOS · Apple Silicon', 'M1 / M2 / M3 / M4'], ['darwin-x86_64', 'macOS · Intel', 'x86_64'], ['windows-x86_64', 'Windows · x64', '需要 WebView2'], ].map(([key, label, hint]) => { const p = (latest.platforms || {})[key] if (!p) return '
' + label + '
暂未提供
' return '
' + label + '
' + hint + ' · ' + mb(p.size) + ' · .' + esc(String(p.file).split('.').pop()) + '
' }).join('\n ') const tags = [] for (const p of plugins) for (const t of (p.tags || [])) if (tags.indexOf(t) < 0) tags.push(t) const tagChips = tags.map((t) => '').join('\n ') function mdToHtml (md) { const esc2 = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' }[c])) const inline = (s) => esc2(s) .replace(/`([^`]+)`/g, '$1') .replace(/\*\*([^*]+)\*\*/g, '$1') .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') const lines = String(md).split('\n') const out = [] let i = 0 let inCode = false let code = [] let inList = '' const closeList = () => { if (inList) { out.push(''); inList = '' } } while (i < lines.length) { const line = lines[i] if (line.trim().indexOf('```') === 0) { if (!inCode) { inCode = true; code = [] } else { inCode = false out.push('
' + esc2(code.join('\n')) + '
') } i++; continue } if (inCode) { code.push(line); i++; continue } if (!line.trim()) { closeList(); i++; continue } if (/^---+$/.test(line.trim())) { closeList(); out.push('
'); i++; continue } const h = line.match(/^(#{1,4})\s+(.*)$/) if (h) { closeList(); out.push('' + inline(h[2]) + ''); i++; continue } if (line.trim().indexOf('|') === 0) { const rows = [] while (i < lines.length && lines[i].trim().indexOf('|') === 0) rows.push(lines[i++]) const cells = rows.map((r) => r.trim().replace(/^\||\|$/g, '').split('|').map((c) => c.trim())) if (cells.length > 1) { out.push('' + cells[0].map((c) => '').join('') + '') for (let r = 2; r < cells.length; r++) out.push('' + cells[r].map((c) => '').join('') + '') out.push('
' + inline(c) + '
' + inline(c) + '
') } continue } if (/^ \S/.test(line)) { closeList() const block = [] while (i < lines.length && (/^ /.test(lines[i]) || !lines[i].trim())) { block.push(lines[i].replace(/^ /, '')); i++ } while (block.length && !block[block.length - 1].trim()) block.pop() out.push('
' + esc2(block.join('\n')) + '
') continue } const li = line.match(/^\s*[-*]\s+(.*)$/) if (li) { if (inList !== 'ul') { closeList(); out.push('