Skip to content

Commit

Permalink
feat: Khans of Tarkir
Browse files Browse the repository at this point in the history
  • Loading branch information
bellstrand committed Oct 21, 2024
1 parent 0f013fd commit 9ccaf79
Show file tree
Hide file tree
Showing 41 changed files with 257 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
[Modern Horizon 3](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Modern-Horizon-3-Draft.pdf)<br />
[Outlaws of Thunder Junction](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Outlaws-of-Thunder-Junction-Draft.pdf)<br />
[Murders at Karlov Manor](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Murders-at-Karlov-Manor-Draft.pdf)<br />
[Wilds of Eldraine](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Wilds-of-Eldraine-Draft.pdf)<br />
[Kamigawa: Neon Dynasty](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Kamigawa-Neon-Dynasty-Draft.pdf)<br />
[Lord of the Rings](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Lord-of-the-Rings-Draft.pdf)<br />
[Zendikar Rising](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Zendikar-Rising-Draft.pdf)<br />
[Innistrad: Crimson Vow](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Innistrad-Crimson-Vow-Draft.pdf)<br />
[Khans of Tarkir](https://github.com/bellstrand/mtg-draft-pdf/releases/latest/download/Khans-of-Tarkir-Draft.pdf)<br />
22 changes: 13 additions & 9 deletions generate-pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ const dir = import.meta.dirname;
async function generate() {
const browser = await chromium.launch({ headless: true, args: ["--disable-web-security"] })
const page = await browser.newPage({ bypassCSP: true })
page.addInitScript((dir) => {
window.addEventListener('DOMContentLoaded', () => {
const html = document.querySelector("html") as HTMLHtmlElement
html.innerHTML = html?.innerHTML.replace("/style.css", `file:///${dir}/style.css`).replaceAll("/images/", `file:///${dir}/images/`)
});
}, dir);
await page.route("file:///style.css", async (r) => {
const cssFile = Bun.file(`./style.css`)
const cssText = await cssFile.text()
r.fulfill({ status: 200, contentType: "text/css;charset=utf-8", body: cssText.replaceAll("/images/", `file:///${dir}/images/`) })
});
await page.route(/html$/, async (r, req) => {
const htmlFile = Bun.file(req.url().replace(`file://${dir}/`, "./"))
const htmlText = await htmlFile.text()
r.fulfill({ status: 200, contentType: "text/html;charset=utf-8", body: htmlText.replaceAll("/images/", `file:///${dir}/images/`) })
})

const files = (await readdir("./sets")).filter((f) => f !== "template.html")

for(const file of files) {
page.goto(`file:///${dir}/sets/${file}`)
for (const file of files) {
page.goto(`file://${dir}/sets/${file}`)
await page.waitForLoadState()
// console.info("waitForLoadState")
await page.waitForSelector("page")
Expand All @@ -28,7 +32,7 @@ async function generate() {

await page.pdf({
path: `./storage/${title}.pdf`,
printBackground: false,
printBackground: true,
scale: 1,
width: "21cm",
height: "29.7cm"
Expand Down
4 changes: 4 additions & 0 deletions images/common/colors/b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions images/common/colors/bg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions images/common/colors/bp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions images/common/colors/br.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9ccaf79

Please sign in to comment.