From 33f2fe4e91ca2c3b0aaaf3a4d03c9864a8278ac1 Mon Sep 17 00:00:00 2001 From: Igor Laborie Date: Sat, 31 Aug 2019 13:31:36 +0200 Subject: [PATCH] Schedule fr/en --- .gitlab-ci.yml | 6 ++---- content/schedule/_index.fr.md | 2 +- content/schedule/_index.md | 2 +- tools/pdf.js | 38 ++++++++++++++++++++++------------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index afd8760..dcaab09 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,9 +11,8 @@ before_script: sandbox: script: - - hugo --quiet - - node tools/pdf.js - hugo -F + - node tools/pdf.js - node tools/minify.js - firebase use default - firebase deploy --token "$FIREBASE_SANDBOX_TOKEN" @@ -27,9 +26,8 @@ prod: variables: HUGO_ENV: production script: - - hugo --quiet - - node tools/pdf.js - hugo --baseURL https://2019.devfesttoulouse.fr/ + - node tools/pdf.js - node tools/minify.js - firebase use prod - firebase deploy --token "$FIREBASE_PROD_TOKEN" diff --git a/content/schedule/_index.fr.md b/content/schedule/_index.fr.md index 1912030..3ae1467 100644 --- a/content/schedule/_index.fr.md +++ b/content/schedule/_index.fr.md @@ -15,7 +15,7 @@ horizontal: false ICal - + PDF diff --git a/content/schedule/_index.md b/content/schedule/_index.md index eb2d210..3d72e8b 100644 --- a/content/schedule/_index.md +++ b/content/schedule/_index.md @@ -14,7 +14,7 @@ horizontal: false ICal - + PDF diff --git a/tools/pdf.js b/tools/pdf.js index cfd1ae9..879b3b2 100644 --- a/tools/pdf.js +++ b/tools/pdf.js @@ -9,7 +9,10 @@ Logger.config.defaultLevel = LogLevel.Debug; const logger = Logger.getLogger('pdf'); // Configuration -const output = 'static/schedule/schedule.pdf'; +const outputs = { + 'schedule/index.html': 'public/schedule/schedule-en.pdf', + 'fr/schedule/index.html': 'public/schedule/schedule-fr.pdf', +}; const serverConf = { port: 8765, options: { @@ -70,13 +73,28 @@ async function cleanupBeforePrint(page) { await page.$$eval(toHide.join(','), elts => elts.forEach(elt => - elt.parentNode.removeChild(elt))); + elt && elt.parentNode ? elt.parentNode.removeChild(elt) : elt)); await page.addStyleTag({ content: '@page { size: auto; }', }); } +async function renderPdf(page, file, output) { + const url = `http://localhost:${serverConf.port}/${file}`; + logger.info("go to", url); + const pageResponse = await page.goto(url, {waitUntil: 'networkidle2'}); + logger.debug("done", pageResponse.statusText()); + + await cleanupBeforePrint(page); + + logger.info('export pdf', output); + const format = 'A3'; + const scale = .4; + const printBackground = true; + return page.pdf({path: output, format, scale, printBackground}); +} + (async () => { const server = await startServer(serverConf); @@ -87,18 +105,10 @@ async function cleanupBeforePrint(page) { const page = await browser.newPage(); logger.debug("opened new page"); - const file = 'fr/schedule/index.html'; - const url = `http://localhost:${serverConf.port}/${file}`; - logger.info("go to", url); - const pageResponse = await page.goto(url, {waitUntil: 'networkidle2'}); - logger.debug("done", pageResponse.statusText()); - - await cleanupBeforePrint(page); - logger.info('export pdf', output); - const format = 'A3'; - const scale = .4; - const printBackground = true; - await page.pdf({path:output, format, scale, printBackground}); + for (let [file, output] of Object.entries(outputs)) { + await renderPdf(page, file, output); + } + logger.debug("pdf done"); } catch (e) {