- 新增 scripts/pdf.mjs:构建期 Chromium 渲染 4 份 PDF(printBackground 保留蓝色底色) - 微软雅黑字库(msyh.ttc/msyhbd.ttc)随仓库分发,构建阶段 fc-match 自检;最终镜像保持干净 nginx(无 Chromium/字体/Node) - Dockerfile 加 pdf 中间阶段;deploy.yml 加部署后 PDF 链接验证 - 导航卡片与简历页页脚加「下载 PDF」入口 - 排版对齐 v19/soe-v3 参考稿:@page 页边距 57/55/70px,私企 1 页饱满收口、国企 2 页宽松排版 (迭代求解缩放比例,测量版面宽度与 page.pdf 缩放语义一致) - 页数目标写入变体清单 pdf.pages
This commit is contained in:
@@ -12,7 +12,7 @@ jobs:
|
||||
- name: Setup Environment
|
||||
run: |
|
||||
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
apk add --no-cache docker-cli
|
||||
apk add --no-cache docker-cli curl
|
||||
|
||||
- name: Checkout
|
||||
run: |
|
||||
@@ -37,5 +37,17 @@ jobs:
|
||||
-p 8080:80 \
|
||||
resume-site:latest
|
||||
|
||||
- name: Verify Deployment (页面 + PDF)
|
||||
run: |
|
||||
sleep 3
|
||||
curl -fsS http://127.0.0.1:8080/ > /dev/null
|
||||
for f in private-dev private-support soe-dev soe-support; do
|
||||
ct=$(curl -fsS -o /dev/null -w '%{content_type}' http://127.0.0.1:8080/pdf/$f.pdf)
|
||||
case "$ct" in
|
||||
application/pdf*) echo "PDF OK: $f ($ct)" ;;
|
||||
*) echo "PDF BAD: $f (content-type: $ct)"; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
- name: Cleanup Dangling Images
|
||||
run: docker image prune -f
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ blob-report/
|
||||
resume_output.jpg
|
||||
dist/
|
||||
|
||||
# Fonts (downloaded/generated)
|
||||
fonts/
|
||||
# Fonts (downloaded/generated at root; assets/fonts/ 字库入库)
|
||||
/fonts/
|
||||
|
||||
# OS files
|
||||
.DS_Store
|
||||
|
||||
+19
-3
@@ -14,14 +14,30 @@ RUN pnpm install --frozen-lockfile
|
||||
COPY . .
|
||||
RUN node scripts/build.mjs && node scripts/check.mjs
|
||||
|
||||
# ---- 运行阶段:Nginx 托管 dist/ ----
|
||||
# ---- PDF 阶段(仅构建期中间依赖:Chromium + 微软雅黑,产出 dist/pdf/)----
|
||||
FROM node:22-alpine AS pdf
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
|
||||
&& apk add --no-cache chromium fontconfig
|
||||
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
|
||||
CHROMIUM_PATH=/usr/bin/chromium
|
||||
# 微软雅黑字库(仅本阶段使用,不进入最终镜像)
|
||||
COPY assets/fonts/ /usr/share/fonts/yahei/
|
||||
RUN fc-cache -f
|
||||
WORKDIR /app
|
||||
COPY package.json ./
|
||||
COPY --from=build /app/node_modules ./node_modules
|
||||
COPY --from=build /app/dist ./dist
|
||||
COPY scripts/ scripts/
|
||||
RUN node scripts/pdf.mjs
|
||||
|
||||
# ---- 运行阶段:Nginx 托管 dist/(干净镜像:无 Chromium/字体/Node) ----
|
||||
FROM nginx:alpine
|
||||
|
||||
# 复制 Nginx 配置
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 复制构建产物(HTML + txt + css + img)
|
||||
COPY --from=build /app/dist/ /usr/share/nginx/html/
|
||||
# 复制构建产物(HTML + txt + css + img + pdf)
|
||||
COPY --from=pdf /app/dist/ /usr/share/nginx/html/
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 80
|
||||
|
||||
@@ -49,6 +49,7 @@ resume/
|
||||
| 国企 · 技术支持/交付实施 | http://47.121.181.112:8080/soe/support/ |
|
||||
| 纯文本选择页 | http://47.121.181.112:8080/txt |
|
||||
| 纯文本简历(4 份) | http://47.121.181.112:8080/txt/private/dev 等 |
|
||||
| PDF 简历(4 份,构建期自动生成) | http://47.121.181.112:8080/pdf/private-dev.pdf 等 |
|
||||
|
||||
旧地址 301 兼容(面试官已收到的链接不失效):`/resume` → `/private/dev/`,`/soe` → `/soe/dev/`,`/txt/resume`、`/txt/soe`、`/other/` 等同理。
|
||||
|
||||
@@ -65,8 +66,9 @@ resume/
|
||||
# 2. 本地构建 + 自检 + 预览
|
||||
pnpm install # 首次
|
||||
pnpm run serve # 构建并在 http://localhost:4173/ 预览
|
||||
pnpm run pdf # 生成 dist/pdf/ 下 4 份 PDF(首次需 npx playwright install chromium)
|
||||
|
||||
# 3. 提交推送 main,Gitea Actions 自动构建镜像并部署
|
||||
# 3. 提交推送 main,Gitea Actions 自动构建镜像并部署(PDF 在构建期生成并随站点发布)
|
||||
```
|
||||
|
||||
新增岗位/企业维度:在 `data/roles/` 或 `data/companies/` 加文件,在 `data/variants/` 加对应清单(声明板块顺序),重新构建即可;导航页、路由、纯文本版全部自动生成。
|
||||
@@ -77,6 +79,14 @@ pnpm run serve # 构建并在 http://localhost:4173/ 预览
|
||||
- 字段归属:事实与默认措辞 → `base.yaml`/`experiences/`;展示方式 → `companies/`;求职意向/技能 → `roles/`;措辞的岗位/组合级差异 → `roles/` 或 `variants/*-*.yaml` 的 `overrides`(以 `experiences.<id>.bullets` 等键覆盖);
|
||||
- `pnpm run check` 会对跨层同键(改一层被另一层覆盖的风险)和 override 数量给出警告。
|
||||
|
||||
## PDF 生成
|
||||
|
||||
- PDF 在**构建期**由 Docker 中间阶段(Chromium + 微软雅黑字库 `assets/fonts/`)渲染 `dist/pdf/<企业>-<岗位>.pdf`,随站点发布到 `/pdf/*.pdf`;**运行容器是干净的 nginx 静态镜像**(无 Chromium/字体/Node,不在服务时渲染)。
|
||||
- 字体使用微软雅黑(msyh.ttc / msyhbd.ttc),构建阶段自检 `fc-match` 必须命中字库,否则构建失败。
|
||||
- 导航页卡片与简历页页脚提供「下载 PDF」入口;PDF 与浏览器打印一致(A4、微软雅黑、蓝色底色、条目不跨页、无页脚/悬浮按钮)。
|
||||
- 页数目标写在变体清单 `pdf.pages`(私企 1 页 / 国企 2 页),构建时迭代求解缩放比例收进目标页数并尽量铺满;页边距为 @page 几何(左右 57px、上 55px、下 70px,与 v19/soe-v3 参考稿一致)。
|
||||
- PDF 生成失败 = 流水线失败 = 不部署;部署后 CI 会 curl 校验 4 条 PDF 链接的 200 与 `application/pdf`。
|
||||
|
||||
## 部署方式
|
||||
|
||||
推送到 `main` 分支后,Gitea Actions 自动执行:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+14
-1
@@ -442,14 +442,27 @@ body {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
/* Print:保留底色(浏览器需开启"背景图形"或由 print-color-adjust 保证)、条目不跨页截断、隐藏页脚与悬浮入口 */
|
||||
/* Print:保留底色、条目不跨页截断、隐藏页脚与悬浮入口
|
||||
页边距参考 v19/soe-v3 简历:左右 57px、上 55px、下 70px(@page 几何,不随缩放变化) */
|
||||
@media print {
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 55px 57px 70px 57px;
|
||||
}
|
||||
|
||||
* {
|
||||
-webkit-print-color-adjust: exact !important;
|
||||
print-color-adjust: exact !important;
|
||||
color-adjust: exact !important;
|
||||
}
|
||||
|
||||
/* 内容流宽度 = 纸面内容区(680px),由 PDF 缩放收进目标页数 */
|
||||
.page {
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.section-title,
|
||||
.edu-header,
|
||||
.exp-header,
|
||||
|
||||
@@ -13,5 +13,9 @@ nav:
|
||||
# 板块清单与顺序(基本信息 header 恒在首位,无需声明)
|
||||
sections: [education, honors, internships, projects, skills]
|
||||
|
||||
# PDF 目标页数(构建期自适应缩放收进该页数)
|
||||
pdf:
|
||||
pages: 1
|
||||
|
||||
# 组合级覆盖(仅放确需单独措辞的内容;默认应共享维度层)
|
||||
overrides: {}
|
||||
|
||||
@@ -11,4 +11,8 @@ nav:
|
||||
|
||||
sections: [education, honors, internships, projects, skills]
|
||||
|
||||
# PDF 目标页数(构建期自适应缩放收进该页数)
|
||||
pdf:
|
||||
pages: 1
|
||||
|
||||
overrides: {}
|
||||
|
||||
@@ -11,6 +11,10 @@ nav:
|
||||
|
||||
sections: [education, honors, internships, campus, projects, certificates, studentWork, socialPractice, skills, selfEval]
|
||||
|
||||
# PDF 目标页数(国企版两页双面排版)
|
||||
pdf:
|
||||
pages: 2
|
||||
|
||||
# 国企口径措辞:与私企版共享事实(experiences/),此处覆盖技术向表述为业务/价值向表述
|
||||
overrides:
|
||||
experiences:
|
||||
|
||||
@@ -13,4 +13,8 @@ nav:
|
||||
|
||||
sections: [education, honors, internships, campus, projects, certificates, studentWork, socialPractice, skills, selfEval]
|
||||
|
||||
# PDF 目标页数(国企版两页双面排版)
|
||||
pdf:
|
||||
pages: 2
|
||||
|
||||
overrides: {}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"scripts": {
|
||||
"build": "node scripts/build.mjs",
|
||||
"check": "node scripts/check.mjs",
|
||||
"pdf": "node scripts/build.mjs && node scripts/pdf.mjs",
|
||||
"serve": "node scripts/build.mjs && node scripts/serve.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -58,6 +58,7 @@ for (const view of views) {
|
||||
selfUrl: view.selfUrl,
|
||||
baseUrl: view.merged.site.baseUrl,
|
||||
txtUrl: view.txtPath,
|
||||
pdfUrl: view.pdfUrl,
|
||||
headerHtml,
|
||||
bodyHtml,
|
||||
});
|
||||
|
||||
@@ -210,6 +210,8 @@ export function buildView(v, data) {
|
||||
role,
|
||||
path: `${variantPath}/`,
|
||||
txtPath: `/txt${variantPath}`,
|
||||
pdfUrl: `/pdf/${v.company}-${v.role}.pdf`,
|
||||
pdfPages: (v.pdf && v.pdf.pages) || 1,
|
||||
selfUrl,
|
||||
theme: company.theme || v.company,
|
||||
meta: { title, description },
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
// scripts/pdf.mjs —— 构建期生成 4 份简历 PDF(微软雅黑渲染)
|
||||
// 仅在构建阶段运行(Docker pdf 中间阶段 / 本地 pnpm run pdf),运行容器不参与渲染
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { chromium } from 'playwright';
|
||||
import { DIST, loadAll, buildView } from './lib.mjs';
|
||||
import { createStaticServer } from './serve.mjs';
|
||||
|
||||
const OUT = path.join(DIST, 'pdf');
|
||||
const MIN_SIZE = 20 * 1024; // PDF 有效体积下限
|
||||
|
||||
// ---------- 字体自检:Linux 构建容器内必须命中微软雅黑 ----------
|
||||
if (process.platform === 'linux') {
|
||||
let matched = '';
|
||||
try {
|
||||
matched = execSync('fc-match "Microsoft YaHei"', { encoding: 'utf8' }).trim();
|
||||
} catch {
|
||||
console.error('[pdf] fc-match 不可用(fontconfig 未安装?),中止构建');
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`[pdf] 字体匹配:${matched}`);
|
||||
if (!/msyh/i.test(matched)) {
|
||||
console.error('[pdf] 未命中微软雅黑字库(assets/fonts/),中文字形将回退,中止构建');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 视图清单 ----------
|
||||
const data = loadAll();
|
||||
const views = data.variants.map((v) => buildView(v, data));
|
||||
|
||||
// ---------- 本地静态服务 + Chromium ----------
|
||||
const server = createStaticServer(DIST);
|
||||
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
||||
const port = server.address().port;
|
||||
|
||||
const browser = await chromium.launch({
|
||||
executablePath: process.env.CHROMIUM_PATH || undefined,
|
||||
args: ['--no-sandbox', '--disable-dev-shm-usage'],
|
||||
});
|
||||
|
||||
fs.mkdirSync(OUT, { recursive: true });
|
||||
|
||||
const CONTENT_W = 680; // 纸面内容区宽(A4 793.7 - 左右边距 57×2)
|
||||
const PAGE_H = 997.5; // 纸面内容区高(A4 1122.5 - 上 55 - 下 70)
|
||||
|
||||
try {
|
||||
for (const view of views) {
|
||||
const page = await browser.newPage({ viewport: { width: CONTENT_W, height: 997 } });
|
||||
await page.emulateMedia({ media: 'print' });
|
||||
await page.goto(`http://127.0.0.1:${port}${view.path}`, { waitUntil: 'networkidle' });
|
||||
|
||||
// page.pdf 的 scale < 1 时版面按 CONTENT_W/scale 宽度重排后整体缩放;
|
||||
// 迭代求满足"渲染后高度 ≤ 目标页可用高度"的最大缩放(内容尽可能铺满)
|
||||
const targetPages = view.pdfPages || 1;
|
||||
const budget = PAGE_H * targetPages * 0.985;
|
||||
let scale = 1;
|
||||
const candidates = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await page.setViewportSize({ width: Math.round(CONTENT_W / scale), height: 997 });
|
||||
const height = await page.evaluate(() => document.querySelector('.page').scrollHeight);
|
||||
candidates.push({ scale, extent: height * scale });
|
||||
const next = Math.min(1, budget / height);
|
||||
if (Math.abs(next - scale) < 0.004) {
|
||||
scale = next;
|
||||
break;
|
||||
}
|
||||
scale = next;
|
||||
}
|
||||
const fitting = candidates.filter((c) => c.extent <= budget);
|
||||
if (fitting.length) scale = Math.max(...fitting.map((c) => c.scale));
|
||||
else scale = Math.min(...candidates.map((c) => c.scale));
|
||||
|
||||
const file = path.join(OUT, `${view.id}.pdf`);
|
||||
await page.pdf({
|
||||
path: file,
|
||||
format: 'A4',
|
||||
preferCSSPageSize: true, // 采用 @page 边距与尺寸
|
||||
printBackground: true, // 保留小节蓝色底色
|
||||
displayHeaderFooter: false,
|
||||
scale,
|
||||
});
|
||||
await page.close();
|
||||
const size = fs.statSync(file).size;
|
||||
console.log(`[pdf] ${view.id}.pdf ${(size / 1024).toFixed(0)}KB 缩放 ${scale.toFixed(3)} 目标 ${targetPages} 页 ${view.meta.title}`);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
server.close();
|
||||
}
|
||||
|
||||
// ---------- 产物自检 ----------
|
||||
let failed = false;
|
||||
for (const view of views) {
|
||||
const file = path.join(OUT, `${view.id}.pdf`);
|
||||
if (!fs.existsSync(file) || fs.statSync(file).size < MIN_SIZE) {
|
||||
console.error(`[pdf] 产物缺失或过小:${file}`);
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
if (failed) process.exit(1);
|
||||
console.log(`[pdf] 完成:${views.length} 份 PDF → dist/pdf/`);
|
||||
+16
-9
@@ -1,11 +1,11 @@
|
||||
// scripts/serve.mjs —— 本地预览静态服务器(模拟 nginx 路由,含旧地址 301)
|
||||
// 也导出 createStaticServer() 供 scripts/pdf.mjs 在构建期复用
|
||||
import http from 'node:http';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { DIST } from './lib.mjs';
|
||||
|
||||
const PORT = Number(process.env.PORT || 4173);
|
||||
|
||||
const MIME = {
|
||||
'.html': 'text/html; charset=utf-8',
|
||||
'.css': 'text/css; charset=utf-8',
|
||||
@@ -17,6 +17,7 @@ const MIME = {
|
||||
'.gif': 'image/gif',
|
||||
'.ico': 'image/x-icon',
|
||||
'.txt': 'text/plain; charset=utf-8',
|
||||
'.pdf': 'application/pdf',
|
||||
};
|
||||
|
||||
const REDIRECTS = {
|
||||
@@ -41,8 +42,8 @@ function send(res, file, forceType) {
|
||||
res.end(fs.readFileSync(file));
|
||||
}
|
||||
|
||||
http
|
||||
.createServer((req, res) => {
|
||||
export function createStaticServer(root = DIST) {
|
||||
return http.createServer((req, res) => {
|
||||
const p = decodeURIComponent(new URL(req.url, 'http://localhost').pathname);
|
||||
if (REDIRECTS[p]) {
|
||||
res.writeHead(301, { Location: REDIRECTS[p] });
|
||||
@@ -53,15 +54,21 @@ http
|
||||
return res.end();
|
||||
}
|
||||
const txtMatch = p.match(/^\/txt\/(private|soe)\/(dev|support)$/);
|
||||
if (txtMatch) return send(res, path.join(DIST, 'txt', txtMatch[1], txtMatch[2], 'index.txt'));
|
||||
if (p === '/txt') return send(res, path.join(DIST, 'txt', 'index.html'));
|
||||
if (txtMatch) return send(res, path.join(root, 'txt', txtMatch[1], txtMatch[2], 'index.txt'));
|
||||
if (p === '/txt') return send(res, path.join(root, 'txt', 'index.html'));
|
||||
|
||||
let file = path.join(DIST, p);
|
||||
let file = path.join(root, p);
|
||||
if (p.endsWith('/')) file = path.join(file, 'index.html');
|
||||
else if (fs.existsSync(file) && fs.statSync(file).isDirectory()) {
|
||||
res.writeHead(301, { Location: `${p}/` });
|
||||
return res.end();
|
||||
}
|
||||
send(res, file);
|
||||
})
|
||||
.listen(PORT, () => console.log(`本地预览:http://localhost:${PORT}/ (dist/)`));
|
||||
});
|
||||
}
|
||||
|
||||
// 直接运行时启动预览服务
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
const PORT = Number(process.env.PORT || 4173);
|
||||
createStaticServer().listen(PORT, () => console.log(`本地预览:http://localhost:${PORT}/ (dist/)`));
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<div class="card-desc">{{nav.desc}}</div>
|
||||
<div class="card-links">
|
||||
<a class="card-link" href="{{path}}">查看简历 →</a>
|
||||
<a class="card-link-sub" href="{{pdfUrl}}">下载 PDF</a>
|
||||
<a class="card-link-sub" href="{{txtPath}}">纯文本版</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
{{{bodyHtml}}}
|
||||
<div class="page-footer">
|
||||
<a href="/">简历导航(其他版本)</a>
|
||||
<a href="{{pdfUrl}}">PDF 版</a>
|
||||
<a href="{{txtUrl}}">纯文本版</a>
|
||||
<span class="footer-hint">打印 / 另存 PDF:浏览器 Ctrl+P</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user