Add puppeteer to convert to pdf
Some checks failed
Build / Build_And_Publish (push) Failing after 33s
Some checks failed
Build / Build_And_Publish (push) Failing after 33s
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,5 @@
|
||||
node_modules
|
||||
generated_resume.html
|
||||
resume.pdf
|
||||
|
||||
.direnv
|
||||
|
||||
35
build.js
35
build.js
@@ -1,20 +1,37 @@
|
||||
const ejs = require('ejs');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const ejs = require("ejs");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const puppeteer = require("puppeteer");
|
||||
|
||||
// File paths
|
||||
const dataPath = path.join(__dirname, 'content.json');
|
||||
const templatePath = path.join(__dirname, 'template.ejs');
|
||||
const outputPath = path.join(__dirname, 'generated_resume.html');
|
||||
const dataPath = path.join(__dirname, "content.json");
|
||||
const templatePath = path.join(__dirname, "template.ejs");
|
||||
const outputPath = path.join(__dirname, "generated_resume.html");
|
||||
|
||||
// Read data and template
|
||||
const jsonData = JSON.parse(fs.readFileSync(dataPath, 'utf-8'));
|
||||
const template = fs.readFileSync(templatePath, 'utf-8');
|
||||
const jsonData = JSON.parse(fs.readFileSync(dataPath, "utf-8"));
|
||||
const template = fs.readFileSync(templatePath, "utf-8");
|
||||
|
||||
// Render HTML
|
||||
const html = ejs.render(template, jsonData);
|
||||
|
||||
// Write the output
|
||||
fs.writeFileSync(outputPath, html, 'utf-8');
|
||||
fs.writeFileSync(outputPath, html, "utf-8");
|
||||
|
||||
console.log(`Successfully generated resume at ${outputPath}`);
|
||||
|
||||
async function generatePdf(htmlPath) {
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
await page.goto(`file://${htmlPath}`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
// Saves the PDF to hn.pdf.
|
||||
await page.pdf({
|
||||
path: "resume.pdf",
|
||||
});
|
||||
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
generatePdf(outputPath).then(() => console.log("Generated PDF version"));
|
||||
|
||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1764950072,
|
||||
"narHash": "sha256-BmPWzogsG2GsXZtlT+MTcAWeDK5hkbGRZTeZNW42fwA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "f61125a668a320878494449750330ca58b78c557",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
47
flake.nix
Normal file
47
flake.nix
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
description = "Resume builder dev environment";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
nodejs
|
||||
chromium
|
||||
|
||||
jq
|
||||
curl
|
||||
just
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
|
||||
export PUPPETEER_EXECUTABLE_PATH=${pkgs.chromium}/bin/chromium
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "🚀 Resume Build Environment"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "Node version: $( node -v)"
|
||||
echo ""
|
||||
echo "Quick commands:"
|
||||
echo " just build # Build my resume"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
1108
package-lock.json
generated
1108
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@
|
||||
"build": "node build.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"ejs": "^3.1.8"
|
||||
"ejs": "^3.1.8",
|
||||
"puppeteer": "^24.32.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user