Created
April 17, 2024 13:59
-
-
Save pawarherschel/7ef2514d2aaf6ac6ca574daa909c935f to your computer and use it in GitHub Desktop.
cursed fuckin method to embed my cv, downloads the git repo in node_modules and then compiles the typst code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MainGridLayout from "../layouts/MainGridLayout.astro"; | |
import {i18n} from "../i18n/translation"; | |
import I18nKey from "../i18n/i18nKey"; | |
import {exec} from "child_process"; | |
import * as typst from "typst"; | |
import * as fs from "node:fs"; | |
import {DOMParser} from "xmldom"; | |
const gitVersion = exec("git --version", (e, out, err) => { | |
if (e !== null) { | |
console.error(`git version exception: ${e}`); | |
} | |
if (err !== "") { | |
console.log(`git version log: ${out}`); | |
} | |
if (err !== "") { | |
console.error(`git version error: ${err}`); | |
} | |
}); | |
console.log("Trying to pull typst"); | |
let exit = null; | |
const gitPull = exec("git -C node_modules/git/typst pull", (e, out, err) => { | |
if (e !== null) { | |
console.error(`git pull exception: ${e}`); | |
exit = e; | |
} | |
if (err !== "") { | |
console.log(`git pull log: ${out}`); | |
} | |
if (err !== "") { | |
console.error(`git pull error: ${err}`); | |
} | |
}); | |
if (exit != null){ | |
console.log("Trying to clone typst"); | |
const gitClone = exec("git clone https://github.com/pawarherschel/typst.git node_modules/git/typst", (e, out, err) => { | |
if (e !== null) { | |
console.error(`git clone exception: ${e}`); | |
} | |
if (err !== "") { | |
console.log(`git clone log: ${out}`); | |
} | |
if (err !== "") { | |
console.error(`git clone error: ${err}`); | |
} | |
}); | |
} | |
// typst compile ./cv.typ ./output/CV.pdf --font-path ./src/fonts/ | |
typst.compile("node_modules/git/typst/cv.typ", "node_modules/git/typst/output/cv.svg", { | |
fontPath: "node_modules/git/typst/src/fonts/", | |
}).then(() => { | |
console.log("compiled"); | |
}).catch((err) => { | |
console.error(`compile err: ${err}`); | |
}); | |
const svgString = fs.readFileSync("node_modules/git/typst/output/cv.svg", "utf-8"); | |
while (svgString === "") { | |
console.error("svg is empty"); | |
} | |
const parser = new DOMParser(); | |
const dom = parser.parseFromString(svgString, "image/svg+xml"); | |
const svgElement = dom.documentElement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment