diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ec91b80 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release +on: + release: + types: [published] + +permissions: + contents: write + +jobs: + release: + timeout-minutes: 5 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install + + - name: Install Playwright Browsers + run: npx playwright install --with-deps chromium + + - name: Generate PDF's + run: bun generate + + - name: Upload PDF's + run: | + for file in ./storage/*.pdf; do + echo "$file" + gh release upload ${{github.event.release.tag_name}} "$file" + done + + env: + GITHUB_TOKEN: ${{ github.TOKEN }} diff --git a/.gitignore b/.gitignore index 66c2997..eff56ea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ +storage/ diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..f24b41e Binary files /dev/null and b/bun.lockb differ diff --git a/generate-pdf.ts b/generate-pdf.ts new file mode 100644 index 0000000..47a207b --- /dev/null +++ b/generate-pdf.ts @@ -0,0 +1,43 @@ +import { readdir } from 'node:fs/promises'; +import { chromium } from "playwright-core"; + +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); + + const files = (await readdir("./sets")).filter((f) => f !== "template.html") + + for(const file of files) { + page.goto(`file:///${dir}/sets/${file}`) + await page.waitForLoadState() + // console.info("waitForLoadState") + await page.waitForSelector("page") + // console.log("waitForSelector") + await page.waitForLoadState("domcontentloaded") + await page.waitForLoadState("networkidle") + + const title = (await page.title()).replaceAll(":", " ") + + await page.pdf({ + path: `./storage/${title}.pdf`, + printBackground: false, + scale: 1, + width: "21cm", + height: "29.7cm" + }) + console.info(`Generated "${title}.pdf" PDF`) + } + await page.close() + + process.exit(0) +} + +void generate() diff --git a/package.json b/package.json index a8fe71d..95c121a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "scripts": { + "generate": "bun ./generate-pdf.ts", "dev:mkm": "browser-sync start --server --no-inject-changes --files './' --startPath '/sets/mkm.html'", - "dev:lotr": "browser-sync start --server --no-inject-changes --files './' --startPath '/sets/lotr.html'", + "dev:ltr": "browser-sync start --server --no-inject-changes --files './' --startPath '/sets/ltr.html'", "dev:vow": "browser-sync start --server --no-inject-changes --files './' --startPath '/sets/vow.html'", "dev:otj": "browser-sync start --server --no-inject-changes --files './' --startPath '/sets/otj.html'", "dev:mh3": "browser-sync start --server --no-inject-changes --files './' --startPath '/sets/mh3.html'", @@ -11,6 +12,10 @@ "dev:dsk": "browser-sync start --server --no-inject-changes --files './' --startPath '/sets/dsk.html'" }, "devDependencies": { + "@types/bun": "^1.1.10", "browser-sync": "^3.0.2" + }, + "dependencies": { + "playwright": "^1.47.2" } } diff --git a/sets/dsk.html b/sets/dsk.html index 0608403..98e2879 100644 --- a/sets/dsk.html +++ b/sets/dsk.html @@ -1,114 +1,135 @@ + + - - -
- - - - - -