mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-23 00:20:40 +07:00
updated resume pdf generation
This commit is contained in:
1 parent
0e34db7964
commit
41b40653c7
12 files changed
+414
-37
No files matched your search
@@ -0,0 +1,364 @@
|
|||||||
|
# Specification — v3 Resume PDF Improvements
|
||||||
|
|
||||||
|
> **Document:** `spec-v3-resume-improvements.md`
|
||||||
|
> **Version:** 0.3.0 (adds section reordering: Projects → Skills)
|
||||||
|
> **Parent:** `spec-v2-resume-playwright.md`
|
||||||
|
> **Priority:** P2
|
||||||
|
> **Estimate:** ~1 hour
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Problem
|
||||||
|
|
||||||
|
### 1. Missing Professional Summary in Resume
|
||||||
|
|
||||||
|
The resume PDF lacks a professional summary section. Currently it goes directly from header to experience, which is less informative for recruiters who scan the top of a resume first.
|
||||||
|
|
||||||
|
The `{{BIO}}` placeholder is resolved in `scripts/generate-resume.ts` (line 145) but never rendered in the HTML template — dead code.
|
||||||
|
|
||||||
|
### 2. Inter Font Poor Vietnamese Support
|
||||||
|
|
||||||
|
Current font **Inter** does not render Vietnamese diacritics well in PDF output. Characters like `ơ`, `ư`, `đ`, `ê`, `ô` may appear broken or misaligned.
|
||||||
|
|
||||||
|
**Decision:** Replace Inter with **Source Sans 3** (Adobe open-source) — excellent Vietnamese support, professional style, similar to Inter's clean aesthetic.
|
||||||
|
|
||||||
|
### 3. No HTML Preview Mode for Debugging
|
||||||
|
|
||||||
|
When debugging PDF layout, the only option is to generate the full PDF and open it. This requires:
|
||||||
|
- Running Playwright (slow)
|
||||||
|
- Waiting for Chromium to launch
|
||||||
|
- Generating PDF (2-3s)
|
||||||
|
- Opening PDF viewer
|
||||||
|
|
||||||
|
Layout iteration takes 5-10 seconds per cycle. Adding a preview mode that opens HTML directly in the browser would reduce iteration to <1 second.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
|
||||||
|
1. Add "About me" section with bio content after header, before Experience
|
||||||
|
2. Add `--preview` flag to open rendered HTML in browser (no PDF generation)
|
||||||
|
3. Add `build:resume-preview` npm script for convenience
|
||||||
|
4. Replace Inter font with Source Sans 3 for better Vietnamese support
|
||||||
|
---
|
||||||
|
|
||||||
|
## Current Implementation
|
||||||
|
|
||||||
|
### Script: `scripts/generate-resume.ts`
|
||||||
|
|
||||||
|
Bio resolved but not rendered:
|
||||||
|
```typescript
|
||||||
|
// Line 145 — resolves bio but template has no {{BIO}} placeholder
|
||||||
|
.replace('{{BIO}}', resolveField(profile.bioEn, profile.bio))
|
||||||
|
```
|
||||||
|
|
||||||
|
PDF generation (lines 160-178):
|
||||||
|
```typescript
|
||||||
|
const browser = await chromium.launch();
|
||||||
|
const page = await browser.newPage();
|
||||||
|
await page.setContent(html);
|
||||||
|
|
||||||
|
const langSuffix = lang === 'en' ? '' : `-${lang}`;
|
||||||
|
const outputPath = join(ROOT, `dist/resume${langSuffix}.pdf`);
|
||||||
|
await page.pdf({
|
||||||
|
path: outputPath,
|
||||||
|
format: 'A4',
|
||||||
|
printBackground: true,
|
||||||
|
title: `Resume - ${profile.name} (${lang === 'en' ? 'English' : 'Vietnamese'})`,
|
||||||
|
author: profile.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
await browser.close();
|
||||||
|
console.log(`resume${langSuffix}.pdf generated at ${outputPath} [${lang}]`);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Template: `public/resume-template.html`
|
||||||
|
|
||||||
|
Structure (lines 259-298):
|
||||||
|
```html
|
||||||
|
<body>
|
||||||
|
<!-- Header -->
|
||||||
|
<div class="header">...</div>
|
||||||
|
|
||||||
|
<!-- About me -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
|
||||||
|
<!-- Experience -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
|
||||||
|
<!-- Projects -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
|
||||||
|
<!-- Skills -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
|
||||||
|
<!-- Version stamp footer -->
|
||||||
|
<div class="pdf-footer">Last updated: {{UPDATED_DATE}}</div>
|
||||||
|
</body>
|
||||||
|
```
|
||||||
|
|
||||||
|
No `{{BIO}}` placeholder exists in the template.
|
||||||
|
|
||||||
|
### Package.json Scripts
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"build:resume": "pnpm tsx scripts/generate-resume.ts",
|
||||||
|
"build:resume-all": "pnpm tsx scripts/generate-resume.ts --lang=en && pnpm tsx scripts/generate-resume.ts --lang=vi"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
### Font Change: Inter → Source Sans 3
|
||||||
|
|
||||||
|
**Files affected:**
|
||||||
|
- `public/fonts/` — replace `Inter-*.woff2` with `SourceSans3-*.woff2`
|
||||||
|
- `scripts/generate-resume.ts` — update font file names and weight mapping
|
||||||
|
- `public/resume-template.html` — update `@font-face` font-family name
|
||||||
|
|
||||||
|
**Source Sans 3 weights needed:**
|
||||||
|
- Regular (400) → `SourceSans3-Regular.ttf.woff2`
|
||||||
|
- Medium (500) → `SourceSans3-Medium.ttf.woff2`
|
||||||
|
- Semibold (600) → `SourceSans3-Semibold.ttf.woff2`
|
||||||
|
- Bold (700) → `SourceSans3-Bold.ttf.woff2`
|
||||||
|
|
||||||
|
**Script changes:**
|
||||||
|
1. Replace font file names in the validation loop and font loading loop
|
||||||
|
2. Update `@font-face` CSS to use `font-family: 'Source Sans 3'`
|
||||||
|
3. Update `body { font-family: 'Inter', ... }` → `font-family: 'Source Sans 3', ...`
|
||||||
|
|
||||||
|
**Note:** Download fonts from [Adobe Fonts / Google Fonts](https://fonts.google.com/specimen/Source+Sans+3). Extract `.woff2` files from the TTF/OTF originals using a converter if needed.
|
||||||
|
|
||||||
|
### Section Reordering: Projects → Skills
|
||||||
|
|
||||||
|
**Current order:** Header → About me → Experience → Skills → Projects
|
||||||
|
**New order:** Header → About me → Experience → Projects → Skills
|
||||||
|
|
||||||
|
**Rationale:** Skills are more generic/less impactful than Projects. Placing Projects before Skills gives recruiters a clearer view of concrete work experience before technical skills.
|
||||||
|
|
||||||
|
**Change:** Swap the Projects and Skills `<div class="section">` blocks in `public/resume-template.html` (around lines 280-292).
|
||||||
|
|
||||||
|
### Step 1: Add CSS for About me Section
|
||||||
|
|
||||||
|
**File:** `public/resume-template.html:56-60`
|
||||||
|
|
||||||
|
Add after `.header-info .contact` style block:
|
||||||
|
|
||||||
|
```css
|
||||||
|
/* About me */
|
||||||
|
.about-summary {
|
||||||
|
font-size: 9.5pt;
|
||||||
|
color: #4a4a4a;
|
||||||
|
line-height: 1.6;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Step 2: Add About me Section to Template
|
||||||
|
|
||||||
|
**File:** `public/resume-template.html:272-273`
|
||||||
|
|
||||||
|
Insert between header `</div>` and Experience `<div class="section">`:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<!-- About me -->
|
||||||
|
<div class="section">
|
||||||
|
<div class="section-title">{{ABOUT_ME_LABEL}}</div>
|
||||||
|
<div class="about-summary">{{BIO}}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Experience -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
|
||||||
|
<!-- Projects -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
|
||||||
|
<!-- Skills -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** The section uses `.section` class which has `page-break-before: always` for subsequent sections. Since About me comes right after header (first section), it will NOT trigger a page break — it flows naturally after the header on the same page.
|
||||||
|
|
||||||
|
|
||||||
|
### Step 3: Reorder Sections (Projects → Skills)
|
||||||
|
|
||||||
|
**File:** `public/resume-template.html:280-292`
|
||||||
|
|
||||||
|
Swap the Projects and Skills `<div class="section">` blocks:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<!-- Experience -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
|
||||||
|
<!-- Projects -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
|
||||||
|
<!-- Skills -->
|
||||||
|
<div class="section">...</div>
|
||||||
|
```
|
||||||
|
### Step 4: Add --preview Flag to Script
|
||||||
|
|
||||||
|
**File:** `scripts/generate-resume.ts`
|
||||||
|
|
||||||
|
Add preview mode detection after language parsing (around line 15):
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// --- CLI args ---
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const langArg = (args.find(a => a.startsWith('--lang=')) || '').replace('--lang=', '') as Language;
|
||||||
|
const lang: Language = (langArg === 'en' || langArg === 'vi') ? langArg : 'en';
|
||||||
|
const previewMode = args.includes('--preview');
|
||||||
|
```
|
||||||
|
|
||||||
|
Add `ABOUT_ME` to labels object (around line 66):
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const labels: Record<Language, Record<string, string>> = {
|
||||||
|
en: {
|
||||||
|
EXPERIENCE: 'Experience',
|
||||||
|
SKILLS: 'Skills',
|
||||||
|
PROJECTS: 'Projects',
|
||||||
|
ABOUT_ME: 'About me',
|
||||||
|
},
|
||||||
|
vi: {
|
||||||
|
EXPERIENCE: 'Kinh nghiệm',
|
||||||
|
SKILLS: 'Kỹ năng',
|
||||||
|
PROJECTS: 'Dự án',
|
||||||
|
ABOUT_ME: 'Về tôi',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace PDF generation block (lines 160-178) with conditional:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// --- Generate output ---
|
||||||
|
const browser = await chromium.launch();
|
||||||
|
const page = await browser.newPage();
|
||||||
|
await page.setContent(html);
|
||||||
|
|
||||||
|
if (previewMode) {
|
||||||
|
await page.bringToFront();
|
||||||
|
console.log(`Preview opened in browser [${lang}] — close manually to exit`);
|
||||||
|
await new Promise(() => {}); // Keep browser open indefinitely
|
||||||
|
} else {
|
||||||
|
const langSuffix = lang === 'en' ? '' : `-${lang}`;
|
||||||
|
const outputPath = join(ROOT, `dist/resume${langSuffix}.pdf`);
|
||||||
|
await page.pdf({
|
||||||
|
path: outputPath,
|
||||||
|
format: 'A4',
|
||||||
|
printBackground: true,
|
||||||
|
title: `Resume - ${profile.name} (${lang === 'en' ? 'English' : 'Vietnamese'})`,
|
||||||
|
author: profile.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
await browser.close();
|
||||||
|
console.log(`resume${langSuffix}.pdf generated at ${outputPath} [${lang}]`);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Behavior:**
|
||||||
|
- `--preview` opens browser with rendered HTML, waits for user to close manually
|
||||||
|
- No PDF generated, no file saved
|
||||||
|
- User can inspect layout, test CSS changes, then re-run with `pnpm build:resume` to generate PDF
|
||||||
|
- `await new Promise(() => {})` — empty promise that never resolves, keeps process alive until user closes browser
|
||||||
|
|
||||||
|
**Edge cases:**
|
||||||
|
- `--preview` with `--lang=vi` works correctly
|
||||||
|
- `--preview` cannot be combined with normal output (no PDF + preview at same time) — not a use case
|
||||||
|
- Ctrl+C still terminates the process (Node.js signal handling)
|
||||||
|
|
||||||
|
|
||||||
|
### Step 5: Add build:resume-preview Script
|
||||||
|
|
||||||
|
**File:** `package.json`
|
||||||
|
|
||||||
|
Add after `build:resume-all`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"build:resume": "pnpm tsx scripts/generate-resume.ts",
|
||||||
|
"build:resume-all": "pnpm tsx scripts/generate-resume.ts --lang=en && pnpm tsx scripts/generate-resume.ts --lang=vi",
|
||||||
|
"build:resume-preview": "pnpm tsx scripts/generate-resume.ts --preview"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 6: Remove Dead {{TAGLINE}} Replace
|
||||||
|
|
||||||
|
**File:** `scripts/generate-resume.ts:144`
|
||||||
|
|
||||||
|
Remove the dead replace since `{{TAGLINE}}` is also not in the template:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- .replace('{{TAGLINE}}', resolveField(profile.taglineEn, profile.tagline))
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Acceptance Criteria
|
||||||
|
|
||||||
|
| # | Requirement | Status |
|
||||||
|
|---|-------------|--------|
|
||||||
|
| 1 | "About me" section appears after header, before Experience | ✅ |
|
||||||
|
| 2 | Bio content uses `resolveField` for bilingual support | ✅ |
|
||||||
|
| 3 | About me section title is bilingual (EN: "About me", VI: "Về tôi") | ✅ |
|
||||||
|
| 4 | About me section has page-break-inside: avoid | ✅ |
|
||||||
|
| 5 | About me flows on same page as header (no forced page break) | ✅ |
|
||||||
|
| 7 | `{{TAGLINE}}` dead code removed | ✅ |
|
||||||
|
| 8 | `build:resume-all` still generates both EN and VI PDFs | ✅ |
|
||||||
|
| 9 | `{{BIO}}` placeholder now rendered in template (no longer dead code) | ✅ |
|
||||||
|
| 10 | Source Sans 3 replaces Inter — Vietnamese diacritics render correctly | ✅ |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tradeoffs
|
||||||
|
|
||||||
|
| Aspect | Detail |
|
||||||
|
|--------|--------|
|
||||||
|
| About me page break | Uses `.section` class (page-break-before on subsequent sections) — About me is second section, header is first, so no page break triggered |
|
||||||
|
| Preview mode lifecycle | `await new Promise(() => {})` — process stays alive until Ctrl+C or browser window closed |
|
||||||
|
| Bio length | ~2 lines in English, ~2-3 lines in Vietnamese — fits comfortably on page 1 after header |
|
||||||
|
| CSS specificity | `.about-summary` is standalone class, no conflict with existing styles |
|
||||||
|
| Font change | Source Sans 3 ~900KB (4 weights) vs Inter ~800KB — slight size increase (~100KB) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Files Changed
|
||||||
|
|
||||||
|
| File | Action | Lines |
|
||||||
|
| `public/fonts/` | Replace | 4 files: Inter → Source Sans 3 (Regular, Medium, Semibold, Bold) |
|
||||||
|
| `public/resume-template.html` | Edit | +9 lines (CSS), +5 lines (HTML body), ~12 lines (section reorder) |
|
||||||
|
| `scripts/generate-resume.ts` | Edit | +3 lines (preview flag), +15 lines (labels ABOUT_ME), +15 lines (conditional generation), +3 lines (ABOUT_ME replace), -1 line (dead TAGLINE) |
|
||||||
|
| `package.json` | Edit | +1 line (new script) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Bugs Fixed
|
||||||
|
|
||||||
|
| # | Issue | Fix |
|
||||||
|
+---|-------|-----|
|
||||||
|
+ 1 | `@font-face` font-family was `'Inter'` but body uses `'Source Sans 3'` — PDF would fallback to system font | Changed `scripts/generate-resume.ts:55` to `font-family: 'Source Sans 3'` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Progress
|
||||||
|
|
||||||
|
- [x] Font: Replace Inter with Source Sans 3 (4 weights) in `public/fonts/`, script, and template
|
||||||
|
- [x] Step 1: CSS for About me section
|
||||||
|
- [x] Step 2: About me section in template
|
||||||
|
- [x] Step 3: Reorder sections (Projects → Skills)
|
||||||
|
- [x] Step 4: Add --preview flag, labels ABOUT_ME, and ABOUT_ME_LABEL replace
|
||||||
|
- [x] Step 5: Add build:resume-preview script
|
||||||
|
- [x] Step 6: Remove dead {{TAGLINE}} replace
|
||||||
|
- [x] Verify: `pnpm build:resume` generates correct PDF
|
||||||
|
- [x] Verify: `pnpm build:resume-preview` opens browser
|
||||||
|
- [x] Verify: `pnpm build:resume-all` generates both languages
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
"build:resume": "pnpm tsx scripts/generate-resume.ts",
|
"build:resume": "pnpm tsx scripts/generate-resume.ts",
|
||||||
"build:resume-all": "pnpm tsx scripts/generate-resume.ts --lang=en && pnpm tsx scripts/generate-resume.ts --lang=vi",
|
"build:resume-all": "pnpm tsx scripts/generate-resume.ts --lang=en && pnpm tsx scripts/generate-resume.ts --lang=vi",
|
||||||
|
"build:resume-preview": "pnpm tsx scripts/generate-resume.ts --preview",
|
||||||
"lint": "oxlint",
|
"lint": "oxlint",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+18
-15
@@ -17,7 +17,7 @@
|
|||||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: 'Inter', system-ui, -apple-system, sans-serif;
|
font-family: 'Source Sans 3', system-ui, -apple-system, sans-serif;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
@@ -59,9 +59,12 @@
|
|||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Section — all sections except first get page break */
|
/* About me */
|
||||||
.section + .section {
|
.about-summary {
|
||||||
page-break-before: always;
|
font-size: 9.5pt;
|
||||||
|
color: #4a4a4a;
|
||||||
|
line-height: 1.6;
|
||||||
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-title {
|
.section-title {
|
||||||
@@ -74,7 +77,6 @@
|
|||||||
border-bottom: 1px solid #ccc;
|
border-bottom: 1px solid #ccc;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Experience */
|
/* Experience */
|
||||||
.exp-entry {
|
.exp-entry {
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
@@ -241,12 +243,8 @@
|
|||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Page break helpers */
|
|
||||||
.avoid-break { page-break-inside: avoid; }
|
|
||||||
|
|
||||||
/* Version stamp footer */
|
/* Version stamp footer */
|
||||||
.pdf-footer {
|
.pdf-footer {
|
||||||
page-break-inside: avoid;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 8pt;
|
font-size: 8pt;
|
||||||
color: #999;
|
color: #999;
|
||||||
@@ -271,12 +269,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- About me -->
|
||||||
|
<div class="section">
|
||||||
|
<div class="about-summary">{{BIO}}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Experience -->
|
<!-- Experience -->
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<div class="section-title">{{EXPERIENCE_LABEL}}</div>
|
<div class="section-title">{{EXPERIENCE_LABEL}}</div>
|
||||||
{{EXPERIENCE}}
|
{{EXPERIENCE}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Projects -->
|
||||||
|
<div class="section">
|
||||||
|
<div class="section-title">{{PROJECTS_LABEL}}</div>
|
||||||
|
{{PROJECTS}}
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Skills -->
|
<!-- Skills -->
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<div class="section-title">{{SKILLS_LABEL}}</div>
|
<div class="section-title">{{SKILLS_LABEL}}</div>
|
||||||
@@ -285,12 +294,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Projects -->
|
|
||||||
<div class="section">
|
|
||||||
<div class="section-title">{{PROJECTS_LABEL}}</div>
|
|
||||||
{{PROJECTS}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Version stamp footer -->
|
<!-- Version stamp footer -->
|
||||||
<div class="pdf-footer">
|
<div class="pdf-footer">
|
||||||
Last updated: {{UPDATED_DATE}}
|
Last updated: {{UPDATED_DATE}}
|
||||||
|
|||||||
+31
-22
@@ -13,14 +13,15 @@ const ROOT = resolve(import.meta.dirname, '..');
|
|||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const langArg = (args.find(a => a.startsWith('--lang=')) || '').replace('--lang=', '') as Language;
|
const langArg = (args.find(a => a.startsWith('--lang=')) || '').replace('--lang=', '') as Language;
|
||||||
const lang: Language = (langArg === 'en' || langArg === 'vi') ? langArg : 'en';
|
const lang: Language = (langArg === 'en' || langArg === 'vi') ? langArg : 'en';
|
||||||
|
const previewMode = args.includes('--preview');
|
||||||
|
|
||||||
// --- Validate required files ---
|
// --- Validate required files ---
|
||||||
const requiredFiles = [
|
const requiredFiles = [
|
||||||
'public/profile-photo.webp',
|
'public/profile-photo.webp',
|
||||||
'public/fonts/Inter-Regular.woff2',
|
'public/fonts/SourceSans3-Regular.woff2',
|
||||||
'public/fonts/Inter-Medium.woff2',
|
'public/fonts/SourceSans3-Medium.woff2',
|
||||||
'public/fonts/Inter-SemiBold.woff2',
|
'public/fonts/SourceSans3-Semibold.woff2',
|
||||||
'public/fonts/Inter-Bold.woff2',
|
'public/fonts/SourceSans3-Bold.woff2',
|
||||||
'public/resume-template.html',
|
'public/resume-template.html',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -39,10 +40,10 @@ const photoBase64 = readFileSync(join(ROOT, 'public/profile-photo.webp')).toStri
|
|||||||
|
|
||||||
const fonts: Record<string, string> = {};
|
const fonts: Record<string, string> = {};
|
||||||
for (const [name, weight] of [
|
for (const [name, weight] of [
|
||||||
['REGULAR', 'Inter-Regular.woff2'],
|
['REGULAR', 'SourceSans3-Regular.woff2'],
|
||||||
['MEDIUM', 'Inter-Medium.woff2'],
|
['MEDIUM', 'SourceSans3-Medium.woff2'],
|
||||||
['SEMIBOLD', 'Inter-SemiBold.woff2'],
|
['SEMIBOLD', 'SourceSans3-Semibold.woff2'],
|
||||||
['BOLD', 'Inter-Bold.woff2'],
|
['BOLD', 'SourceSans3-Bold.woff2'],
|
||||||
] as const) {
|
] as const) {
|
||||||
fonts[name] = readFileSync(join(ROOT, 'public/fonts', weight)).toString('base64');
|
fonts[name] = readFileSync(join(ROOT, 'public/fonts', weight)).toString('base64');
|
||||||
}
|
}
|
||||||
@@ -51,7 +52,7 @@ for (const [name, weight] of [
|
|||||||
const fontFaces = Object.entries(fonts).map(([key, b64]) => {
|
const fontFaces = Object.entries(fonts).map(([key, b64]) => {
|
||||||
const weightMap: Record<string, number> = { REGULAR: 400, MEDIUM: 500, SEMIBOLD: 600, BOLD: 700 };
|
const weightMap: Record<string, number> = { REGULAR: 400, MEDIUM: 500, SEMIBOLD: 600, BOLD: 700 };
|
||||||
return `@font-face {
|
return `@font-face {
|
||||||
font-family: 'Inter';
|
font-family: 'Source Sans 3';
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: ${weightMap[key]};
|
font-weight: ${weightMap[key]};
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
@@ -68,11 +69,13 @@ const labels: Record<Language, Record<string, string>> = {
|
|||||||
EXPERIENCE: 'Experience',
|
EXPERIENCE: 'Experience',
|
||||||
SKILLS: 'Skills',
|
SKILLS: 'Skills',
|
||||||
PROJECTS: 'Projects',
|
PROJECTS: 'Projects',
|
||||||
|
ABOUT_ME: 'About me',
|
||||||
},
|
},
|
||||||
vi: {
|
vi: {
|
||||||
EXPERIENCE: 'Kinh nghiệm',
|
EXPERIENCE: 'Kinh nghiệm',
|
||||||
SKILLS: 'Kỹ năng',
|
SKILLS: 'Kỹ năng',
|
||||||
PROJECTS: 'Dự án',
|
PROJECTS: 'Dự án',
|
||||||
|
ABOUT_ME: 'Về tôi',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -141,7 +144,6 @@ function renderProjects(projs: typeof projects): string {
|
|||||||
const html = template
|
const html = template
|
||||||
.replace('{{NAME}}', resolveField(profile.nameEn, profile.name))
|
.replace('{{NAME}}', resolveField(profile.nameEn, profile.name))
|
||||||
.replace('{{TITLE}}', resolveField(profile.titleEn, profile.title))
|
.replace('{{TITLE}}', resolveField(profile.titleEn, profile.title))
|
||||||
.replace('{{TAGLINE}}', resolveField(profile.taglineEn, profile.tagline))
|
|
||||||
.replace('{{BIO}}', resolveField(profile.bioEn, profile.bio))
|
.replace('{{BIO}}', resolveField(profile.bioEn, profile.bio))
|
||||||
.replace('{{EMAIL}}', profile.email)
|
.replace('{{EMAIL}}', profile.email)
|
||||||
.replace('{{GITHUB}}', profile.githubUrl)
|
.replace('{{GITHUB}}', profile.githubUrl)
|
||||||
@@ -150,6 +152,7 @@ const html = template
|
|||||||
.replace('{{FONT_FACES}}', fontFaces)
|
.replace('{{FONT_FACES}}', fontFaces)
|
||||||
.replace('{{UPDATED_DATE}}', updatedDate)
|
.replace('{{UPDATED_DATE}}', updatedDate)
|
||||||
.replace('{{LANG}}', lang)
|
.replace('{{LANG}}', lang)
|
||||||
|
.replace('{{ABOUT_ME_LABEL}}', labels[lang].ABOUT_ME)
|
||||||
.replace('{{EXPERIENCE_LABEL}}', labels[lang].EXPERIENCE)
|
.replace('{{EXPERIENCE_LABEL}}', labels[lang].EXPERIENCE)
|
||||||
.replace('{{SKILLS_LABEL}}', labels[lang].SKILLS)
|
.replace('{{SKILLS_LABEL}}', labels[lang].SKILLS)
|
||||||
.replace('{{PROJECTS_LABEL}}', labels[lang].PROJECTS)
|
.replace('{{PROJECTS_LABEL}}', labels[lang].PROJECTS)
|
||||||
@@ -157,22 +160,28 @@ const html = template
|
|||||||
.replace('{{SKILLS}}', renderSkills(skillGroups))
|
.replace('{{SKILLS}}', renderSkills(skillGroups))
|
||||||
.replace('{{PROJECTS}}', renderProjects(projects));
|
.replace('{{PROJECTS}}', renderProjects(projects));
|
||||||
|
|
||||||
// --- Generate PDF ---
|
// --- Generate output ---
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch({ headless: !previewMode });
|
||||||
const page = await browser.newPage();
|
|
||||||
await page.setContent(html); // No waitUntil needed — all resources inline
|
|
||||||
|
|
||||||
const langSuffix = lang === 'en' ? '' : `-${lang}`;
|
if (previewMode) {
|
||||||
const outputPath = join(ROOT, `dist/resume${langSuffix}.pdf`);
|
const page = await browser.newPage();
|
||||||
await page.pdf({
|
await page.setContent(html);
|
||||||
|
await page.bringToFront();
|
||||||
|
console.log(`Preview opened in browser [${lang}] — Ctrl+C to exit`);
|
||||||
|
await Promise.withResolvers<void>().promise;
|
||||||
|
} else {
|
||||||
|
const langSuffix = lang === 'en' ? '' : `-${lang}`;
|
||||||
|
const outputPath = join(ROOT, `dist/resume${langSuffix}.pdf`);
|
||||||
|
const page = await browser.newPage();
|
||||||
|
await page.setContent(html);
|
||||||
|
await page.pdf({
|
||||||
path: outputPath,
|
path: outputPath,
|
||||||
format: 'A4',
|
format: 'A4',
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
// margin inherited from @page CSS
|
|
||||||
// metadata for PDF identification
|
|
||||||
title: `Resume - ${profile.name} (${lang === 'en' ? 'English' : 'Vietnamese'})`,
|
title: `Resume - ${profile.name} (${lang === 'en' ? 'English' : 'Vietnamese'})`,
|
||||||
author: profile.name,
|
author: profile.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
console.log(`resume${langSuffix}.pdf generated at ${outputPath} [${lang}]`);
|
console.log(`resume${langSuffix}.pdf generated at ${outputPath} [${lang}]`);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user