#!/usr/bin/env node 'use strict' // 下载页生成器:site/releases.json → site/index.html // 只做纯静态输出(无外链、无框架),部署到 NAS 的 nginx 静态目录。 const fs = require('fs') const path = require('path') const root = path.resolve(__dirname, '..') const inFile = process.argv[2] || path.join(root, 'site', 'releases.json') const outFile = process.argv[3] || path.join(root, 'site', 'index.html') const data = JSON.parse(fs.readFileSync(inFile, 'utf8')) const PLATFORMS = [ { key: 'darwin-aarch64', label: 'macOS · Apple Silicon', hint: 'M1 / M2 / M3 / M4' }, { key: 'darwin-x64', label: 'macOS · Intel', hint: 'x86_64' }, { key: 'windows-x86_64', label: 'Windows · x64', hint: '需要 WebView2' }, ] const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])) const fmtSize = (n) => (!n ? '' : (n / 1048576).toFixed(1) + ' MB') function platformRow (rel, p) { const item = rel && rel.platforms ? rel.platforms[p.key] : null const meta = item ? '版本 ' + esc(rel.version) + ' · ' + fmtSize(item.size) + ' · .' + esc(item.kind || 'dmg') : '' const action = item ? '下载' : '暂未提供' const hash = item && item.sha256 ? '
sha256 ' + esc(item.sha256.slice(0, 16)) + '…
' : '' return '
\n' + '
' + esc(p.label) + '
' + esc(p.hint) + '
\n' + '
' + meta + hash + '
\n' + ' ' + action + '\n' + '
' } const latest = data.releases && data.releases[0] const history = (data.releases || []).map((r) => { const avail = Object.keys(r.platforms || {}).map((k) => { const p = PLATFORMS.find((x) => x.key === k) return p ? p.label : k }) return '
\n' + '
' + esc(r.version) + (r.notes ? '
' + esc(r.notes) + '
' : '') + '
\n' + '
' + esc(r.date || '') + '
' + esc(avail.join(' / ') || '—') + '
\n' + '
' }).join('\n') const html = ` ${esc(data.app)} · 下载

${esc(data.app)}

${esc(data.subtitle || '')}

下载

${PLATFORMS.map((p) => platformRow(latest, p)).join('\n')}

系统要求

macOS 12 及以上 / Windows 10 1803 及以上(含 WebView2)
数据全部保存在本地目录 ~/Documents/ImageWorkbench,可整目录备份与迁移。

历史版本

${history}
本页由 scripts/gen-release-page.js 从 releases.json 生成 · 源码 git.maqiart.eu.org · 更新于 ${esc((data.updatedAt || '').slice(0, 10))}
` fs.writeFileSync(outFile, html) console.log('已生成 ' + path.relative(root, outFile) + '(' + data.releases.length + ' 个版本 / ' + Object.keys((latest && latest.platforms) || {}).length + ' 个平台)')