Deploy Resume / deploy (push) Failing after 36s
- 数据分层:base/experiences(事实) + companies(企业维度) + roles(岗位维度) + variants(变体覆盖),Handlebars 模板构建生成 4 份 HTML + 4 份纯文本 + 导航页
- 路由:根路由导航页(默认推荐 私企-全栈),/private/{dev,support}、/soe/{dev,support},旧地址 301 兼容
- 支持/交付岗不改写经历 bullet(与私企-dev 逐字一致),仅专业技能适配
- 移除 CSDN 与文档站链接
- 样式拆分 base + theme-private/theme-soe,打印样式去底色、条目不跨页
- Docker 多阶段构建(node 构建 → nginx 托管),新增 check.mjs 自检与 serve.mjs 本地预览
- 删除旧手写简历(resume/soe/other/txt)与重复样式
84 lines
3.1 KiB
JavaScript
84 lines
3.1 KiB
JavaScript
// scripts/build.mjs —— 构建入口:合并数据 → 渲染 HTML + 纯文本 → 输出 dist/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import Handlebars from 'handlebars';
|
|
import { ROOT, DIST, loadAll, buildView, buildNav, banner } from './lib.mjs';
|
|
|
|
// ---------- Handlebars 辅助 ----------
|
|
const esc = (s) => Handlebars.escapeExpression(s ?? '');
|
|
Handlebars.registerHelper('br', (arr) => new Handlebars.SafeString((arr || []).map((x) => esc(x)).join('<br>')));
|
|
Handlebars.registerHelper('nl', (arr) => (arr || []).join('\n'));
|
|
Handlebars.registerHelper('joinComma', (arr) => (arr || []).join(', '));
|
|
Handlebars.registerHelper('add1', (i) => Number(i) + 1);
|
|
|
|
// ---------- 模板(txt 模板关闭 HTML 转义) ----------
|
|
const tplCache = new Map();
|
|
function tpl(rel) {
|
|
if (!tplCache.has(rel)) {
|
|
const file = path.join(ROOT, 'templates', rel);
|
|
const isTxt = rel.includes('/txt/') || rel.endsWith('.txt.hbs');
|
|
tplCache.set(rel, Handlebars.compile(fs.readFileSync(file, 'utf8'), { strict: false, noEscape: isTxt }));
|
|
}
|
|
return tplCache.get(rel);
|
|
}
|
|
|
|
function writeOut(rel, content) {
|
|
const file = path.join(DIST, rel);
|
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
fs.writeFileSync(file, content);
|
|
}
|
|
|
|
// ---------- 构建 ----------
|
|
const data = loadAll();
|
|
const views = data.variants.map((v) => buildView(v, data));
|
|
const matrix = buildNav(views);
|
|
const navCtx = {
|
|
name: data.base.name,
|
|
contact: data.base.contact,
|
|
links: data.base.links || [],
|
|
site: data.base.site,
|
|
matrix,
|
|
views,
|
|
};
|
|
|
|
const pageTpl = tpl('page.html.hbs');
|
|
const resumeTxtTpl = tpl('resume.txt.hbs');
|
|
|
|
for (const view of views) {
|
|
// HTML:逐板块渲染后拼装(第一板块为基本信息 header)
|
|
const rendered = view.sections.map((s) => ({
|
|
id: s.id,
|
|
html: tpl(`html/${s.html}.hbs`)(s.ctx),
|
|
}));
|
|
const headerHtml = rendered[0].html;
|
|
const bodyHtml = rendered.slice(1).map((r) => r.html).join('\n');
|
|
const html = pageTpl({
|
|
meta: view.meta,
|
|
theme: view.theme,
|
|
selfUrl: view.selfUrl,
|
|
baseUrl: view.merged.site.baseUrl,
|
|
txtUrl: view.txtPath,
|
|
headerHtml,
|
|
bodyHtml,
|
|
});
|
|
writeOut(path.join(view.companyId, view.roleId, 'index.html'), html);
|
|
|
|
// 纯文本:逐板块渲染 + 横幅标题(板块间空一行)
|
|
const blocks = view.sections.map((s) => banner(s.title) + tpl(`txt/${s.txt}.txt.hbs`)(s.ctx).trimEnd() + '\n\n');
|
|
const txt = resumeTxtTpl({ sections: blocks }).trimEnd() + '\n';
|
|
writeOut(path.join('txt', view.companyId, view.roleId, 'index.txt'), txt);
|
|
}
|
|
|
|
// 导航页与纯文本选择页
|
|
writeOut('index.html', tpl('nav.html.hbs')(navCtx));
|
|
writeOut('txt/index.html', tpl('txt-index.html.hbs')(navCtx));
|
|
|
|
// 静态资源
|
|
fs.cpSync(path.join(ROOT, 'css'), path.join(DIST, 'css'), { recursive: true });
|
|
fs.cpSync(path.join(ROOT, 'img'), path.join(DIST, 'img'), { recursive: true });
|
|
|
|
console.log(`构建完成:${views.length} 份简历(HTML + txt)+ 导航页 → ${path.relative(ROOT, DIST)}/`);
|
|
for (const v of views) {
|
|
console.log(` ${v.path.padEnd(20)} ${v.meta.title}${v.isDefault ? '(默认)' : ''}`);
|
|
}
|