Files
resume/scripts/serve.mjs
T
wonder 0b9db1d401
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)与重复样式
2026-11-03 12:20:24 +08:00

68 lines
2.2 KiB
JavaScript
Raw 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.
// scripts/serve.mjs —— 本地预览静态服务器(模拟 nginx 路由,含旧地址 301)
import http from 'node:http';
import fs from 'node:fs';
import path from 'node:path';
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',
'.js': 'text/javascript; charset=utf-8',
'.svg': 'image/svg+xml',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.gif': 'image/gif',
'.ico': 'image/x-icon',
'.txt': 'text/plain; charset=utf-8',
};
const REDIRECTS = {
'/resume': '/private/dev/',
'/resume/': '/private/dev/',
'/soe': '/soe/dev/',
'/soe/': '/soe/dev/',
'/txt/resume': '/txt/private/dev',
'/txt/soe': '/txt/soe/dev',
'/other': '/',
'/other/': '/',
'/txt/': '/txt',
};
function send(res, file, forceType) {
if (!fs.existsSync(file) || fs.statSync(file).isDirectory()) {
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
return res.end('404 Not Found');
}
const ext = path.extname(file).toLowerCase();
res.writeHead(200, { 'Content-Type': forceType || MIME[ext] || 'application/octet-stream' });
res.end(fs.readFileSync(file));
}
http
.createServer((req, res) => {
const p = decodeURIComponent(new URL(req.url, 'http://localhost').pathname);
if (REDIRECTS[p]) {
res.writeHead(301, { Location: REDIRECTS[p] });
return res.end();
}
if (p.startsWith('/other/') || p.startsWith('/resume/')) {
res.writeHead(301, { Location: p.startsWith('/resume/') ? '/private/dev/' : '/' });
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'));
let file = path.join(DIST, 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/)`));