Skip to content

Instantly share code, notes, and snippets.

@pawarherschel
Last active April 20, 2024 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawarherschel/6518d61cbac57528776b2dfd1550506e to your computer and use it in GitHub Desktop.
Save pawarherschel/6518d61cbac57528776b2dfd1550506e to your computer and use it in GitHub Desktop.
import MainGridLayout from "../layouts/MainGridLayout.astro";
import {i18n} from "../i18n/translation";
import I18nKey from "../i18n/i18nKey";
import {exec} from "node:child_process";
import {readFile, access} from "node:fs/promises";
import * as typst from "typst";
import {DOMParser} from "xmldom";
import * as util from "node:util";
import * as fs from "node:fs";
const execPromise = util.promisify(exec);
await execPromise("git --version").then(() => {
console.log("git is installed");
}).catch(() => {
throw new Error("git is not available");
});
const folder: "exists" | "not" = await access("node_modules/git/typst", fs.constants.F_OK)
.then(() => {
return "exists";
})
.catch(() => {
return "not";
});
if (folder === "exists") {
const {gitCloneOut, gitCloneErr} = await execPromise("git -C node_modules/git/typst pull");
} else if ("not") {
console.log("Cloning typst");
const {
gitCloneOut,
gitCloneErr
} = await execPromise("git clone https://github.com/pawarherschel/typst.git node_modules/git/typst");
}
await typst.compile("node_modules/git/typst/cv.typ", "node_modules/git/typst/output/cv.svg", {
fontPath: "node_modules/git/typst/src/fonts/",
});
const svgString = await readFile("node_modules/git/typst/output/cv.svg", "utf-8");
if (svgString === "") {
throw new Error("Empty svg string");
} else {
const svgStringPreview = svgString.substring(0, 20);
console.log(`svg string: ${svgStringPreview}}`);
}
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