108 lines
4.9 KiB
JavaScript
108 lines
4.9 KiB
JavaScript
#!/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
|
||
? '<a class="btn" href="/' + esc(item.file) + '">下载</a>'
|
||
: '<span class="muted">暂未提供</span>'
|
||
const hash = item && item.sha256
|
||
? '<div class="hash">sha256 ' + esc(item.sha256.slice(0, 16)) + '…</div>'
|
||
: ''
|
||
return ' <div class="row">\n' +
|
||
' <div class="name">' + esc(p.label) + '<div class="hint">' + esc(p.hint) + '</div></div>\n' +
|
||
' <div class="meta">' + meta + hash + '</div>\n' +
|
||
' ' + action + '\n' +
|
||
' </div>'
|
||
}
|
||
|
||
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 ' <div class="row">\n' +
|
||
' <div class="name">' + esc(r.version) + (r.notes ? '<div class="hint">' + esc(r.notes) + '</div>' : '') + '</div>\n' +
|
||
' <div class="meta">' + esc(r.date || '') + '<div class="hint">' + esc(avail.join(' / ') || '—') + '</div></div>\n' +
|
||
' </div>'
|
||
}).join('\n')
|
||
|
||
const html = `<!doctype html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||
<title>${esc(data.app)} · 下载</title>
|
||
<style>
|
||
:root{--bg:#fafaf9;--fg:#1c1917;--muted:#78716c;--line:#e7e5e4;--card:#fff;--brand:#1c1917}
|
||
@media (prefers-color-scheme:dark){:root{--bg:#17161a;--fg:#f5f5f4;--muted:#a8a29e;--line:#2f2d33;--card:#1f1e23;--brand:#f5f5f4}}
|
||
*{box-sizing:border-box}
|
||
body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.65 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif}
|
||
.wrap{max-width:760px;margin:0 auto;padding:56px 22px 72px}
|
||
h1{font-size:27px;margin:0 0 6px;letter-spacing:-.01em}
|
||
.sub{color:var(--muted);margin:0 0 34px}
|
||
h2{font-size:12px;letter-spacing:.08em;text-transform:uppercase;color:var(--muted);font-weight:600;margin:38px 0 2px}
|
||
.row{display:flex;align-items:center;gap:16px;padding:15px 0;border-bottom:1px solid var(--line)}
|
||
.row:first-of-type{border-top:1px solid var(--line)}
|
||
.name{flex:1 1 auto;font-weight:550}
|
||
.hint{color:var(--muted);font-size:12.5px;font-weight:400;margin-top:2px}
|
||
.meta{flex:0 0 auto;text-align:right;color:var(--muted);font-size:13px}
|
||
.hash{font-size:11.5px;opacity:.75;margin-top:2px;font-variant-numeric:tabular-nums}
|
||
.btn{flex:0 0 auto;font-size:13px;padding:7px 18px;border-radius:8px;background:var(--brand);color:var(--bg);text-decoration:none}
|
||
.btn:hover{opacity:.88}
|
||
.muted{flex:0 0 auto;font-size:13px;color:var(--muted);opacity:.7}
|
||
.foot{margin-top:46px;color:var(--muted);font-size:12.5px;line-height:1.8}
|
||
.foot a{color:inherit}
|
||
code{font-size:12.5px}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="wrap">
|
||
<h1>${esc(data.app)}</h1>
|
||
<p class="sub">${esc(data.subtitle || '')}</p>
|
||
|
||
<h2>下载</h2>
|
||
${PLATFORMS.map((p) => platformRow(latest, p)).join('\n')}
|
||
|
||
<h2>系统要求</h2>
|
||
<div class="row">
|
||
<div class="name">macOS 12 及以上 / Windows 10 1803 及以上(含 WebView2)
|
||
<div class="hint">数据全部保存在本地目录 <code>~/Documents/ImageWorkbench</code>,可整目录备份与迁移。</div>
|
||
</div>
|
||
</div>
|
||
|
||
<h2>历史版本</h2>
|
||
${history}
|
||
|
||
<div class="foot">
|
||
本页由 <code>scripts/gen-release-page.js</code> 从 releases.json 生成 · 源码 <a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop">git.maqiart.eu.org</a> · 更新于 ${esc((data.updatedAt || '').slice(0, 10))}
|
||
</div>
|
||
</div>
|
||
</body>
|
||
</html>
|
||
`
|
||
fs.writeFileSync(outFile, html)
|
||
console.log('已生成 ' + path.relative(root, outFile) + '(' + data.releases.length + ' 个版本 / ' + Object.keys((latest && latest.platforms) || {}).length + ' 个平台)')
|