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
Binary file not shown.
|
After Width: | Height: | Size: 132 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 139 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 134 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 94 KiB |
+41
-53
@@ -112,20 +112,20 @@
|
|||||||
.shot-bar i{width:11px;height:11px;border-radius:50%}
|
.shot-bar i{width:11px;height:11px;border-radius:50%}
|
||||||
.shot-bar i:nth-child(1){background:#ff5f57}.shot-bar i:nth-child(2){background:#febc2e}.shot-bar i:nth-child(3){background:#28c840}
|
.shot-bar i:nth-child(1){background:#ff5f57}.shot-bar i:nth-child(2){background:#febc2e}.shot-bar i:nth-child(3){background:#28c840}
|
||||||
.shot-bar span{margin-left:12px;font-size:12.5px;color:var(--ink-3)}
|
.shot-bar span{margin-left:12px;font-size:12.5px;color:var(--ink-3)}
|
||||||
.shot-body{display:grid;grid-template-columns:172px 1fr 162px;min-height:330px}
|
|
||||||
.shot-side,.shot-out{padding:16px 12px;font-size:13px;color:var(--ink-3);border-right:1px solid var(--line);background:#fcfcfe}
|
/* 真实截图 */
|
||||||
.shot-out{border-right:0;border-left:1px solid var(--line)}
|
.shot img,.dark-shot img{display:block;width:100%;height:auto}
|
||||||
.shot-side b,.shot-out b{display:block;font-size:10.5px;letter-spacing:.14em;text-transform:uppercase;margin-bottom:10px;color:var(--ink-3)}
|
.shot{border-radius:18px 18px 0 0}
|
||||||
.shot-side div,.shot-out div{padding:5px 9px;border-radius:7px;margin-bottom:3px}
|
.gal{display:grid;grid-template-columns:1fr 1fr;gap:22px}
|
||||||
.shot-side div.on{background:var(--blue-bg);color:var(--blue-d);font-weight:600}
|
@media(max-width:860px){.gal{grid-template-columns:1fr}}
|
||||||
.shot-main{padding:18px 22px;font:13.5px/1.9 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:var(--ink-2);
|
.gal figure{
|
||||||
white-space:pre-wrap;tab-size:2}
|
border:1px solid var(--line);border-radius:16px;overflow:hidden;background:#fff;
|
||||||
.shot-main .h{color:var(--blue);font-weight:700}
|
box-shadow:var(--shadow);transition:.2s;
|
||||||
.hl{background:#fff3c4;border-radius:3px;padding:0 1px}
|
|
||||||
.cur{background:#ffd7a8;border-radius:3px}
|
|
||||||
@media(max-width:780px){
|
|
||||||
.shot-body{grid-template-columns:1fr}.shot-side,.shot-out{display:none}
|
|
||||||
}
|
}
|
||||||
|
.gal figure:hover{box-shadow:var(--shadow-lg);transform:translateY(-3px)}
|
||||||
|
.gal img{display:block;width:100%;height:auto}
|
||||||
|
.gal figcaption{padding:16px 20px 18px;font-size:14.6px;color:var(--ink-2);line-height:1.65}
|
||||||
|
.gal figcaption b{display:block;color:var(--ink);font-size:15.5px;margin-bottom:4px}
|
||||||
|
|
||||||
/* ───────── 通用区块 ───────── */
|
/* ───────── 通用区块 ───────── */
|
||||||
section{padding:96px 0}
|
section{padding:96px 0}
|
||||||
@@ -182,9 +182,6 @@
|
|||||||
}
|
}
|
||||||
.dark-shot .shot-bar{background:#161616;border-bottom-color:rgba(255,255,255,.1)}
|
.dark-shot .shot-bar{background:#161616;border-bottom-color:rgba(255,255,255,.1)}
|
||||||
.dark-shot .shot-bar span{color:rgba(255,255,255,.4)}
|
.dark-shot .shot-bar span{color:rgba(255,255,255,.4)}
|
||||||
.dk-main{padding:22px;font:13.5px/1.95 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:rgba(255,255,255,.72);
|
|
||||||
white-space:pre-wrap;tab-size:2}
|
|
||||||
.dk-main .h{color:var(--blue-l);font-weight:700}
|
|
||||||
@media(max-width:880px){.dark-in{grid-template-columns:1fr;gap:36px}}
|
@media(max-width:880px){.dark-in{grid-template-columns:1fr;gap:36px}}
|
||||||
|
|
||||||
/* 功能网格 */
|
/* 功能网格 */
|
||||||
@@ -283,30 +280,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="shot">
|
<div class="shot">
|
||||||
<div class="shot-bar"><i></i><i></i><i></i><span>未命名 — 小银 Markdown</span></div>
|
<div class="shot-bar"><i></i><i></i><i></i><span>周报-2026-11-19.md — 小银 Markdown</span></div>
|
||||||
<div class="shot-body">
|
<img src="/img/app-light.jpg" width="1600" height="1000" decoding="async"
|
||||||
<div class="shot-side">
|
alt="小银 Markdown 主界面:左侧文件树、中间 Markdown 源码、右侧实时预览与章节大纲">
|
||||||
<b>目录</b>
|
|
||||||
<div class="on">README.md</div>
|
|
||||||
<div>notes.md</div>
|
|
||||||
<div>todo.txt</div>
|
|
||||||
</div>
|
|
||||||
<div class="shot-main">
|
|
||||||
<span class="h"># 小银 Markdown</span>
|
|
||||||
纯本地的编辑器,<span class="hl">左边写</span>、<span class="hl">右边看</span>。
|
|
||||||
<br>
|
|
||||||
<span class="h">## 功能</span>
|
|
||||||
- 实时预览:编辑 / 分栏 / 阅读<span class="cur">|</span>
|
|
||||||
- 多标签 · 多窗口,切换不丢内容
|
|
||||||
- 章节大纲 · 查找高亮
|
|
||||||
</div>
|
|
||||||
<div class="shot-out">
|
|
||||||
<b>大纲</b>
|
|
||||||
<div>小银 Markdown</div>
|
|
||||||
<div>功能</div>
|
|
||||||
<div>快捷键</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -401,19 +377,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="dark-shot">
|
<div class="dark-shot">
|
||||||
<div class="shot-bar"><i></i><i></i><i></i><span>notes.md — 小银 Markdown</span></div>
|
<div class="shot-bar"><i></i><i></i><i></i><span>深色主题 · 周报-2026-11-19.md</span></div>
|
||||||
<div class="dk-main">
|
<img src="/img/app-dark.jpg" width="1600" height="1000" loading="lazy" decoding="async"
|
||||||
<span class="h">## 今天要做的</span>
|
alt="小银 Markdown 深色主题">
|
||||||
- [x] 写完周报
|
|
||||||
- [ ] 整理接口文档
|
|
||||||
- [ ] 把 <span style="color:#7ba7ff">README</span> 补一节示例
|
|
||||||
<br>
|
|
||||||
<span class="h">### 代码示例</span>
|
|
||||||
const app = createEditor({
|
|
||||||
theme: 'dark',
|
|
||||||
preview: true,
|
|
||||||
})
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -469,6 +435,28 @@ const app = createEditor({
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- ══════════ 真实界面 ══════════ -->
|
||||||
|
<section id="gallery" class="sec-white">
|
||||||
|
<div class="wrap">
|
||||||
|
<div class="sec-head">
|
||||||
|
<h2>这些<em>都是真实界面</em></h2>
|
||||||
|
<p>不是效果图 —— 就是把程序跑起来截的,一张没修。</p>
|
||||||
|
</div>
|
||||||
|
<div class="gal">
|
||||||
|
<figure>
|
||||||
|
<img src="/img/app-find.jpg" width="1600" height="1000" loading="lazy" decoding="async"
|
||||||
|
alt="查找功能:正文中所有命中标黄、当前命中标橙,右侧预览同步高亮">
|
||||||
|
<figcaption><b>查找与高亮</b>正文里所有命中标黄、当前命中标橙,并自动滚到可视区;计数在右上角</figcaption>
|
||||||
|
</figure>
|
||||||
|
<figure>
|
||||||
|
<img src="/img/app-read.jpg" width="1600" height="1000" loading="lazy" decoding="async"
|
||||||
|
alt="阅读模式:隐藏编辑区,只保留排版后的正文">
|
||||||
|
<figcaption><b>阅读模式</b>收起编辑区只留正文,长文按排版稿看,章节大纲随时跳转</figcaption>
|
||||||
|
</figure>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- ══════════ 下载 ══════════ -->
|
<!-- ══════════ 下载 ══════════ -->
|
||||||
<section id="download" class="sec-white">
|
<section id="download" class="sec-white">
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
|
|||||||
@@ -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