update resume & portfolio
This commit is contained in:
Executable
+28
@@ -0,0 +1,28 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const resumeRoot = resolve(here, "..");
|
||||
const sourceRoot = resolve(resumeRoot, "portfolio/backend");
|
||||
|
||||
function readText(path) {
|
||||
return readFileSync(path, "utf8").trimEnd();
|
||||
}
|
||||
|
||||
function numberSection(markdown, index) {
|
||||
const n = String(index).padStart(2, "0");
|
||||
return markdown.replace(/^#\s+/, `# ${n} · `);
|
||||
}
|
||||
|
||||
for (const profileName of process.argv.slice(2)) {
|
||||
const profilePath = resolve(sourceRoot, "profiles", `${profileName}.json`);
|
||||
const profile = JSON.parse(readText(profilePath));
|
||||
const cover = readText(resolve(sourceRoot, "covers", profile.cover));
|
||||
const sections = profile.sections.map((name, index) =>
|
||||
numberSection(readText(resolve(sourceRoot, "sections", name)), index + 1),
|
||||
);
|
||||
const output = `${cover}\n\n${sections.join("\n\n")}\n`;
|
||||
writeFileSync(resolve(resumeRoot, profile.output), output, "utf8");
|
||||
console.log(`${profileName}: ${profile.output} (${profile.sections.length + 1} pages by section)`);
|
||||
}
|
||||
+47
-2
@@ -248,6 +248,17 @@ function renderMarkdown(source) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const image = /^!\[([^\]]*)\]\(([^)]+)\)$/.exec(line.trim());
|
||||
if (image) {
|
||||
const alt = image[1];
|
||||
const caption = alt.replace(/^(FULL|CHART|WIDE|TOPOLOGY|STATE|SMALL)\s*·?\s*/, "").trim();
|
||||
const imagePath = resolve(dirname(inputPath), image[2]);
|
||||
const figcaption = caption ? `<figcaption>${escapeHtml(caption)}</figcaption>` : "";
|
||||
blocks.push(`<figure><img src="file://${imagePath}" alt="${escapeHtml(alt)}">${figcaption}</figure>`);
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isTableStart(lines, index)) {
|
||||
const rows = [];
|
||||
rows.push(parseTableRow(lines[index]));
|
||||
@@ -300,6 +311,7 @@ function renderMarkdown(source) {
|
||||
!lines[index].startsWith(">") &&
|
||||
!/^- /.test(lines[index]) &&
|
||||
!/^\d+\.\s+/.test(lines[index]) &&
|
||||
!/^!\[[^\]]*\]\([^)]+\)$/.test(lines[index].trim()) &&
|
||||
!isTableStart(lines, index)
|
||||
) {
|
||||
paragraph.push(lines[index].trim());
|
||||
@@ -308,7 +320,38 @@ function renderMarkdown(source) {
|
||||
blocks.push(`<p>${inline(paragraph.join(" "))}</p>`);
|
||||
}
|
||||
|
||||
return groupProjectSections(blocks).map((block) => ` ${block}`).join("\n");
|
||||
return groupPages(groupProjectSections(blocks)).map((block) => ` ${block}`).join("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap every <h1> and the blocks that follow it in a fixed-height page box.
|
||||
* The page box is a flex column, which lets its figure claim whatever vertical
|
||||
* space the text on that page leaves over instead of being capped by a guess.
|
||||
*/
|
||||
function groupPages(blocks) {
|
||||
const pages = [];
|
||||
let current = null;
|
||||
|
||||
for (const block of blocks) {
|
||||
if (block.startsWith("<h1>")) {
|
||||
if (current) {
|
||||
pages.push(current);
|
||||
}
|
||||
current = [block];
|
||||
continue;
|
||||
}
|
||||
if (current) {
|
||||
current.push(block);
|
||||
} else {
|
||||
pages.push([block]);
|
||||
}
|
||||
}
|
||||
|
||||
if (current) {
|
||||
pages.push(current);
|
||||
}
|
||||
|
||||
return pages.map((page) => `<section class="page">${page.join("")}</section>`);
|
||||
}
|
||||
|
||||
function groupProjectSections(blocks) {
|
||||
@@ -363,7 +406,9 @@ function parseTableRow(line) {
|
||||
}
|
||||
|
||||
function renderTable(rows) {
|
||||
return `<table><tbody>${rows
|
||||
const columns = rows[0]?.length ?? 0;
|
||||
const className = columns === 3 ? "metric-table" : columns === 2 ? "two-col-table" : "data-table";
|
||||
return `<table class="${className}"><tbody>${rows
|
||||
.map((row) => `<tr>${row.map((cell) => `<td>${inline(cell)}</td>`).join("")}</tr>`)
|
||||
.join("")}</tbody></table>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user