Files
qiqi e017f8733f
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 26s
site: 更换站点 logo 与 favicon(官网/首页/下载/插件/开发页)
2026-11-23 07:11:26 +08:00

193 lines
10 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[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) => [
'<nav><div class="wrap inner">',
' <a class="brand" href="/"><img class="logo" src="/assets/logo.png" alt="" width="26" height="26">Image Workbench</a>',
' <div class="links">',
' <a href="/"' + (active === 'home' ? ' class="on"' : '') + '>首页</a>',
' <a href="/download/"' + (active === 'download' ? ' class="on"' : '') + '>下载</a>',
' <a href="/plugins/"' + (active === 'plugins' ? ' class="on"' : '') + '>插件</a>',
' <a href="/dev/"' + (active === 'dev' ? ' class="on"' : '') + '>开发</a>',
' <a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码</a>',
' </div>',
' <div class="right">',
' <a class="btn" href="/plugins/">插件市场</a>',
' <a class="btn primary" href="/download/">下载 v' + V + '</a>',
' </div>',
'</div></nav>',
].join('\n')
const footer = [
'<footer><div class="wrap">',
' <div class="cols">',
' <div><div style="color:#fff;font-weight:640;margin-bottom:8px">Image Workbench</div>',
' <div style="font-size:13px;line-height:1.8">本地优先的 AI 生图无限画布。图片、提示词与模型配置全部留在你自己的电脑里。</div></div>',
' <div><h4>产品</h4><a href="/">首页</a><a href="/download/">下载</a><a href="/plugins/">插件市场</a></div>',
' <div><h4>资源</h4><a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码仓库</a><a href="https://git.maqiart.eu.org/malongan/iwb-plugins-desktop" target="_blank" rel="noopener">插件仓库</a><a href="/updates/latest.json" target="_blank" rel="noopener">更新源</a></div>',
' <div><h4>说明</h4><a href="/download/">安装步骤</a><a href="/plugins/">插件安装</a></div>',
' </div>',
' <div class="copy"><span>© ' + new Date().getFullYear() + ' Image Workbench</span><span>数据保存在本地 · 不上传任何图片</span></div>',
'</div></footer>',
].join('\n')
const card = (p) => [
' <div class="pcard" data-name="' + esc((p.name + ' ' + p.id + ' ' + (p.desc || '') + ' ' + (p.tags || []).join(' ')).toLowerCase()) + '" data-tags="' + esc((p.tags || []).join(',')) + '">',
' <div class="head"><span class="av" style="background:' + esc(p.color || '#eef2f6') + '">' + esc(p.icon || '◻') + '</span>',
' <div><div class="nm">' + esc(p.name || p.id) + '</div><div class="ver">v' + esc(p.version || '') + ' · ' + esc(p.author === 'official' ? '官方' : (p.author || '')) + '</div></div></div>',
' <div class="desc">' + esc(p.desc || '') + '</div>',
' <div class="tags">' + (p.tags || []).map((t) => '<span class="tag">' + esc(t) + '</span>').join('') + '</div>',
' </div>',
].join('\n')
const feats = [
['💻', '#eef2ff', '本地优先', '图片与数据保存在 ~/Documents/ImageWorkbench,不经服务器中转;可整目录备份、迁移到新电脑。'],
['🕸️', '#fff7ed', '节点式无限画布', '参考图 → 提示词 → 生成 → 图库,用连线把工作流串起来;一张画布容纳整条生产线。'],
['🧩', '#ecfdf5', '插件按需安装', '应用本体不含插件,需要什么装什么;可随时启停,关闭后入口自动隐藏。'],
]
const featCards = feats.map((f) => [
' <div class="card"><div class="ico" style="background:' + f[1] + '">' + f[0] + '</div>',
' <h3>' + f[2] + '</h3><p>' + f[3] + '</p></div>',
].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 '<div class="none"><div class="n">' + label + '</div><div class="s">暂未提供</div></div>'
return '<a href="/' + esc(p.file) + (p.h ? '?h=' + esc(p.h) : '') + '"><div class="n">' + label + '</div><div class="s">' + hint + ' · ' + mb(p.size) + ' · .' + esc(String(p.file).split('.').pop()) + '</div></a>'
}).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) => '<button class="tag" data-tag="' + esc(t) + '" style="cursor:pointer;padding:5px 12px">' + esc(t) + '</button>').join('\n ')
function mdToHtml (md) {
const esc2 = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]))
const inline = (s) => esc2(s)
.replace(/`([^`]+)`/g, '<code>$1</code>')
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>')
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 + '>'); inList = '' } }
while (i < lines.length) {
const line = lines[i]
if (line.trim().indexOf('```') === 0) {
if (!inCode) { inCode = true; code = [] } else {
inCode = false
out.push('<pre><code>' + esc2(code.join('\n')) + '</code></pre>')
}
i++; continue
}
if (inCode) { code.push(line); i++; continue }
if (!line.trim()) { closeList(); i++; continue }
if (/^---+$/.test(line.trim())) { closeList(); out.push('<hr>'); i++; continue }
const h = line.match(/^(#{1,4})\s+(.*)$/)
if (h) { closeList(); out.push('<h' + h[1].length + '>' + inline(h[2]) + '</h' + h[1].length + '>'); 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('<table><thead><tr>' + cells[0].map((c) => '<th>' + inline(c) + '</th>').join('') + '</tr></thead><tbody>')
for (let r = 2; r < cells.length; r++) out.push('<tr>' + cells[r].map((c) => '<td>' + inline(c) + '</td>').join('') + '</tr>')
out.push('</tbody></table>')
}
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('<pre><code>' + esc2(block.join('\n')) + '</code></pre>')
continue
}
const li = line.match(/^\s*[-*]\s+(.*)$/)
if (li) {
if (inList !== 'ul') { closeList(); out.push('<ul>'); inList = 'ul' }
out.push('<li>' + inline(li[1]) + '</li>'); i++; continue
}
const ol = line.match(/^\s*\d+\.\s+(.*)$/)
if (ol) {
if (inList !== 'ol') { closeList(); out.push('<ol>'); inList = 'ol' }
out.push('<li>' + inline(ol[1]) + '</li>'); i++; continue
}
closeList(); out.push('<p>' + inline(line) + '</p>'); i++
}
closeList()
if (inCode) out.push('<pre><code>' + esc2(code.join('\n')) + '</code></pre>')
return out.join('\n')
}
function render(tpl, map) {
let out = fs.readFileSync(path.join(site, tpl), 'utf8')
for (const k of Object.keys(map)) out = out.split('<!--' + k + '-->').join(map[k])
return out
}
let home = render('_home.tpl.html', {
NAV: nav('home'),
FOOTER: footer,
VERSION: V,
PLUGIN_COUNT: String(plugins.length),
FEAT_CARDS: featCards,
PLUGIN_CARDS: plugins.slice(0, 6).map((p) => card(p).replace(/^\s+/, ' ')).join('\n'),
DL_CARDS: dlCards,
})
home = home.replace('/assets/style.css', '/assets/style.css?v=' + STAMP).replace('/assets/painting.jpg', '/assets/painting.jpg?v=' + STAMP)
fs.writeFileSync(path.join(site, 'index.html'), home)
let pluginsPage = render('_plugins.tpl.html', {
NAV: nav('plugins'),
FOOTER: footer,
PLUGIN_COUNT: String(plugins.length),
TAG_CHIPS: tagChips,
PLUGIN_CARDS: plugins.map(card).join('\n'),
})
fs.mkdirSync(path.join(site, 'plugins'), { recursive: true })
pluginsPage = pluginsPage.replace('/assets/style.css', '/assets/style.css?v=' + STAMP)
fs.writeFileSync(path.join(site, 'plugins', 'index.html'), pluginsPage)
fs.writeFileSync(path.join(site, 'plugins-index.json'), JSON.stringify(market, null, 2) + '\n')
// 插件开发规范(由 docs/standards/plugin-development.md 生成)
const devMdPath = path.join(root, 'docs', 'standards', 'plugin-development.md')
if (fs.existsSync(devMdPath)) {
const devPage = render('_dev.tpl.html', {
NAV: nav('dev'),
FOOTER: footer,
DEV_CONTENT: mdToHtml(fs.readFileSync(devMdPath, 'utf8')),
}).replace('/assets/style.css', '/assets/style.css?v=' + STAMP)
fs.mkdirSync(path.join(site, 'dev'), { recursive: true })
fs.writeFileSync(path.join(site, 'dev', 'index.html'), devPage)
}
console.log('站点已生成:首页 / 插件页(' + plugins.length + ' 个插件,' + tags.length + ' 个标签,版本 v' + V + ')')