feat(site): 官网换成真实界面截图(4 张)+ 截图生成工具
老板要求:用真实的软件界面图,不要 CSS 画的效果图。 做法:把仓库里**真实的渲染层**跑起来截 —— src/renderer 下的 index.html / style.css / app.js / markdown.js 一字未改,只用 tools/screenshots/mock-api.js 把 Windows 侧的文件、剪贴板、对话框接口换成假数据, 再用无头 Chrome + CDP 在 1440x900@2x 下渲染。 产出 4 张(压到 1600 宽 JPEG q88,共 508KB): site/img/app-light.jpg 浅色分栏:文件树 + 源码 + 实时预览 + 章节大纲 + 状态栏 site/img/app-dark.jpg 深色主题 site/img/app-find.jpg 查找「安装包」:正文全标黄、当前标橙、计数 2/4 site/img/app-read.jpg 阅读模式 页面改动: · HERO 的假窗口 → 真实截图(保留窗口标题栏样式) · 深色区块的假代码窗 → 真实深色截图 · 新增「这些都是真实界面」区块,放查找/阅读两张 + 说明 · 清掉改版后失效的假窗口 CSS(-1213 字节) tools/screenshots/ 里留了完整流程(含「等 2.8 秒让 toast 消失」这个坑), 以后界面改了可以直接重出图。
This commit is contained in:
1 parent
2b7e39c3d9
commit
f53abeb0c8
8 files changed
+256
-53
No files matched your search
@@ -0,0 +1,43 @@
|
||||
# 官网截图生成
|
||||
|
||||
官网 `site/index.html` 里那几张「真实界面」图是这么来的:
|
||||
|
||||
用**仓库里真实的渲染层**(`src/renderer/{index.html,style.css,app.js,markdown.js}`)跑起来截图,
|
||||
只把 Windows 侧的文件/剪贴板接口换成 `mock-api.js` 里的假数据 ——
|
||||
界面、排版、渲染引擎全是线上那份代码,不是画的效果图。
|
||||
|
||||
## 步骤
|
||||
|
||||
```bash
|
||||
# 1. 复制渲染层 + 挂上 mock
|
||||
rm -rf /tmp/shots/app && mkdir -p /tmp/shots/app
|
||||
cp src/renderer/* /tmp/shots/app/
|
||||
# 在 index.html 里把 <script src="mock-api.js"> 插到 app.js 之前
|
||||
cp tools/screenshots/mock-api.js /tmp/shots/app/
|
||||
|
||||
# 2. 起静态服务
|
||||
cd /tmp/shots/app && python3 -m http.server 8901 &
|
||||
|
||||
# 3. 起无头 Chrome(开 CDP)
|
||||
CH=$(ls ~/.cache/ms-playwright/chromium-*/chrome-linux64/chrome | head -1)
|
||||
$CH --headless=new --no-sandbox --hide-scrollbars --disable-gpu \
|
||||
--force-device-scale-factor=2 --remote-debugging-port=9222 \
|
||||
--window-size=1440,900 about:blank &
|
||||
|
||||
# 4. 截 4 张(浅色分栏 / 深色 / 查找高亮 / 阅读模式)
|
||||
node tools/screenshots/take.mjs
|
||||
|
||||
# 5. 压成网页尺寸(1600 宽,JPEG q88)
|
||||
python3 - <<'PY'
|
||||
from PIL import Image; import os
|
||||
for s, d in {'shot-split':'app-light','shot-dark':'app-dark',
|
||||
'shot-find':'app-find','shot-read':'app-read'}.items():
|
||||
im = Image.open(f'/tmp/shots/out/{s}.png').convert('RGB')
|
||||
w, h = im.size; tw = 1600
|
||||
im.resize((tw, round(h*tw/w)), Image.LANCZOS).save(
|
||||
f'site/img/{d}.jpg', 'JPEG', quality=88, optimize=True, progressive=True)
|
||||
PY
|
||||
```
|
||||
|
||||
> 截图里打开的是一篇样例「周报」文档,内容在 `mock-api.js` 的 `DOC` 常量里,改文案就改那里。
|
||||
> 注意 `take.mjs` 里打开文件后要等 ~2.8 秒再截 —— 否则底部的「已打开」toast 会留在图上。
|
||||
@@ -0,0 +1,104 @@
|
||||
/* 截图专用 mock:把 Windows 侧的文件/剪贴板接口换成假数据,
|
||||
界面部分(index.html / style.css / app.js / markdown.js)全是仓库里的真实代码。 */
|
||||
(function () {
|
||||
const q = new URLSearchParams(location.search);
|
||||
const theme = q.get('theme') || 'light';
|
||||
const mode = q.get('mode') || 'split';
|
||||
|
||||
// app.js 自己用的状态键,预先写好,避免出现欢迎页
|
||||
localStorage.setItem('md-editor-theme', theme);
|
||||
localStorage.setItem('md-editor-mode', mode);
|
||||
localStorage.setItem('md-editor-outline', '1');
|
||||
localStorage.setItem('md-editor-sb', '0'); // 侧栏展开
|
||||
localStorage.setItem('md-editor-dir', 'D:\\notes');
|
||||
localStorage.setItem('md-editor-welcome-closed', '1');
|
||||
|
||||
const DOC = `# 周报 · 2026 第 46 周
|
||||
|
||||
本周主要在收尾 **小银 Markdown** 的安装包与官网,顺手把几个老问题清了。
|
||||
|
||||
## 这周做了什么
|
||||
|
||||
- 安装包从 Electron 换成 Tauri,体积从 152 MB 降到 **1.6 MB**
|
||||
- 装完双击 \`.md\` 就直接用本程序打开
|
||||
- 官网改版,配色参照 UU 远程
|
||||
- 修掉 \`Ctrl+F\` 在长文档里的滚动抖动
|
||||
|
||||
## 待办
|
||||
|
||||
- [x] 交叉编译出 Windows 安装包
|
||||
- [x] 文件关联默认打开
|
||||
- [ ] 补一段更新日志
|
||||
- [ ] 录个 30 秒的演示视频
|
||||
|
||||
## 关键代码
|
||||
|
||||
\`\`\`js
|
||||
// 打开文件后同步到当前标签
|
||||
applyOpened({
|
||||
ok: true,
|
||||
path: 'D:\\\\notes\\\\周报.md',
|
||||
text,
|
||||
eol: '\\n',
|
||||
})
|
||||
\`\`\`
|
||||
|
||||
## 数据对比
|
||||
|
||||
| 项目 | 之前 | 现在 |
|
||||
| --- | --- | --- |
|
||||
| 安装包体积 | 152 MB | 1.6 MB |
|
||||
| 启动时间 | 1.2 s | 0.3 s |
|
||||
|
||||
> 下周把 README 补一节「用 Tauri 打包」,再把这套截图换到官网上。
|
||||
`;
|
||||
|
||||
const TREE = [
|
||||
{ name: '项目', path: 'D:\\notes\\项目', isDir: true },
|
||||
{ name: '日记', path: 'D:\\notes\\日记', isDir: true },
|
||||
{ name: '周报-2026-11-19.md', path: 'D:\\notes\\周报-2026-11-19.md', isDir: false },
|
||||
{ name: '读书笔记.md', path: 'D:\\notes\\读书笔记.md', isDir: false },
|
||||
{ name: '待办.txt', path: 'D:\\notes\\待办.txt', isDir: false },
|
||||
];
|
||||
|
||||
const DOC_PATH = 'D:\\notes\\周报-2026-11-19.md';
|
||||
const ok = (o) => Object.assign({ ok: true }, o || {});
|
||||
const opened = () => ok({ path: DOC_PATH, name: '周报-2026-11-19.md', text: DOC, eol: '\n' });
|
||||
|
||||
window.api = {
|
||||
// ——— 文件 ———
|
||||
open: async () => opened(),
|
||||
openPath: async () => opened(),
|
||||
readFileText: async () => ok({ text: DOC, eol: '\n' }),
|
||||
save: async () => ok({ path: DOC_PATH, name: '周报-2026-11-19.md' }),
|
||||
dirOpen: async () => ok({ path: 'D:\\notes', name: 'notes', entries: TREE }),
|
||||
dirRead: async (p) => ok({ path: p || 'D:\\notes', name: (p || '').split('\\').pop() || 'notes', entries: TREE }),
|
||||
|
||||
// ——— 窗口/标签 ———
|
||||
getOpenMode: async () => ({ mode: 'tabs' }),
|
||||
setOpenMode: async () => ok(),
|
||||
newWindow: async () => ok(),
|
||||
openNewWindow: async () => ok(),
|
||||
closeWindow: async () => ok(),
|
||||
syncDoc: async () => ok(),
|
||||
setDirty: () => {},
|
||||
|
||||
// ——— 提示/对话框 ———
|
||||
message: async () => 0,
|
||||
reveal: async () => ok(),
|
||||
revealPath: async () => ok(),
|
||||
openExternal: async () => ok(),
|
||||
|
||||
// ——— 剪贴板 ———
|
||||
copyFile: async () => ok(),
|
||||
readClipboard: async () => '',
|
||||
writeClipboard: async () => ok(),
|
||||
|
||||
// ——— 事件订阅(真实主进程里由 IPC 推来)———
|
||||
onCommand: () => {},
|
||||
onCloseConfirm: () => {},
|
||||
onExport: () => {},
|
||||
saveFinished: () => {},
|
||||
exportDocs: async () => ok(),
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,68 @@
|
||||
// 用真实界面截三张图:浅色分栏 / 深色分栏 / 查找高亮
|
||||
import fs from 'node:fs';
|
||||
|
||||
const BASE = 'http://127.0.0.1:8901/index.html';
|
||||
const OUT = '/tmp/shots/out';
|
||||
fs.mkdirSync(OUT, { recursive: true });
|
||||
|
||||
const list = await (await fetch('http://127.0.0.1:9222/json/list')).json();
|
||||
const page = list.find((t) => t.type === 'page');
|
||||
if (!page) { console.error('没有 page target'); process.exit(1); }
|
||||
|
||||
const ws = new WebSocket(page.webSocketDebuggerUrl);
|
||||
let seq = 0;
|
||||
const pending = new Map();
|
||||
const send = (method, params = {}) => new Promise((res) => {
|
||||
const id = ++seq;
|
||||
pending.set(id, res);
|
||||
ws.send(JSON.stringify({ id, method, params }));
|
||||
});
|
||||
ws.addEventListener('message', (ev) => {
|
||||
const m = JSON.parse(ev.data);
|
||||
if (m.id && pending.has(m.id)) { pending.get(m.id)(m.result || m.error); pending.delete(m.id); }
|
||||
});
|
||||
await new Promise((r) => ws.addEventListener('open', r, { once: true }));
|
||||
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
const evaluate = async (expression) => {
|
||||
const r = await send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
|
||||
if (r && r.exceptionDetails) console.error(' JS 错误:', JSON.stringify(r.exceptionDetails).slice(0, 200));
|
||||
return r && r.result ? r.result.value : undefined;
|
||||
};
|
||||
|
||||
await send('Page.enable');
|
||||
await send('Emulation.setDeviceMetricsOverride', {
|
||||
width: 1440, height: 900, deviceScaleFactor: 2, mobile: false,
|
||||
});
|
||||
|
||||
const shots = [
|
||||
{ name: 'shot-split', q: '?theme=light&mode=split', after: null },
|
||||
{ name: 'shot-dark', q: '?theme=dark&mode=split', after: null },
|
||||
{ name: 'shot-read', q: '?theme=light&mode=read', after: null },
|
||||
{
|
||||
name: 'shot-find', q: '?theme=light&mode=split',
|
||||
after: `
|
||||
document.getElementById('btn-find').click();
|
||||
const fi = document.getElementById('find-input');
|
||||
fi.value = '安装包';
|
||||
fi.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
document.getElementById('find-next').click();
|
||||
`,
|
||||
},
|
||||
];
|
||||
|
||||
for (const s of shots) {
|
||||
await send('Page.navigate', { url: BASE + s.q });
|
||||
await sleep(1400);
|
||||
// 走真实代码路径打开文件(mock 的 api.open 返回样例文档)
|
||||
await evaluate("document.getElementById('btn-open').click()");
|
||||
await sleep(2800);
|
||||
if (s.after) { await evaluate(s.after); await sleep(600); }
|
||||
const dims = await evaluate("JSON.stringify({tabs: document.querySelectorAll('.tab').length, text: document.getElementById('editor').value.length, ol: document.getElementById('ol-body').children.length})");
|
||||
console.log(` ${s.name} → ${dims}`);
|
||||
const shot = await send('Page.captureScreenshot', { format: 'png' });
|
||||
fs.writeFileSync(`${OUT}/${s.name}.png`, Buffer.from(shot.data, 'base64'));
|
||||
console.log(` ✓ ${s.name}.png ${(fs.statSync(`${OUT}/${s.name}.png`).size / 1024).toFixed(0)}KB`);
|
||||
}
|
||||
|
||||
ws.close();
|
||||
Reference in new issue
Block a user