Files
Resume/scripts/build-backend-portfolios.mjs

29 lines
1.1 KiB
JavaScript
Executable File

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)`);
}