Schedule fr/en

master
Igor Laborie 5 years ago
parent c7083bd9ff
commit 33f2fe4e91
  1. 6
      .gitlab-ci.yml
  2. 2
      content/schedule/_index.fr.md
  3. 2
      content/schedule/_index.md
  4. 38
      tools/pdf.js

@ -11,9 +11,8 @@ before_script:
sandbox: sandbox:
script: script:
- hugo --quiet
- node tools/pdf.js
- hugo -F - hugo -F
- node tools/pdf.js
- node tools/minify.js - node tools/minify.js
- firebase use default - firebase use default
- firebase deploy --token "$FIREBASE_SANDBOX_TOKEN" - firebase deploy --token "$FIREBASE_SANDBOX_TOKEN"
@ -27,9 +26,8 @@ prod:
variables: variables:
HUGO_ENV: production HUGO_ENV: production
script: script:
- hugo --quiet
- node tools/pdf.js
- hugo --baseURL https://2019.devfesttoulouse.fr/ - hugo --baseURL https://2019.devfesttoulouse.fr/
- node tools/pdf.js
- node tools/minify.js - node tools/minify.js
- firebase use prod - firebase use prod
- firebase deploy --token "$FIREBASE_PROD_TOKEN" - firebase deploy --token "$FIREBASE_PROD_TOKEN"

@ -15,7 +15,7 @@ horizontal: false
<svg class="icon icon-calendar"><use xlink:href="#calendar"></use></svg> ICal <svg class="icon icon-calendar"><use xlink:href="#calendar"></use></svg> ICal
</a> </a>
<a class="btn primary btn-lg" href="/schedule/schedule.pdf"> <a class="btn primary btn-lg" href="/schedule/schedule-fr.pdf">
<svg class="icon icon-pdf"><use xlink:href="#pdf"></use></svg> PDF <svg class="icon icon-pdf"><use xlink:href="#pdf"></use></svg> PDF
</a> </a>

@ -14,7 +14,7 @@ horizontal: false
<svg class="icon icon-calendar"><use xlink:href="#calendar"></use></svg> ICal <svg class="icon icon-calendar"><use xlink:href="#calendar"></use></svg> ICal
</a> </a>
<a class="btn primary btn-lg" href="/schedule/schedule.pdf"> <a class="btn primary btn-lg" href="/schedule/schedule-en.pdf">
<svg class="icon icon-pdf"><use xlink:href="#pdf"></use></svg> PDF <svg class="icon icon-pdf"><use xlink:href="#pdf"></use></svg> PDF
</a> </a>

@ -9,7 +9,10 @@ Logger.config.defaultLevel = LogLevel.Debug;
const logger = Logger.getLogger('pdf'); const logger = Logger.getLogger('pdf');
// Configuration // 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 = { const serverConf = {
port: 8765, port: 8765,
options: { options: {
@ -70,13 +73,28 @@ async function cleanupBeforePrint(page) {
await page.$$eval(toHide.join(','), elts => await page.$$eval(toHide.join(','), elts =>
elts.forEach(elt => elts.forEach(elt =>
elt.parentNode.removeChild(elt))); elt && elt.parentNode ? elt.parentNode.removeChild(elt) : elt));
await page.addStyleTag({ await page.addStyleTag({
content: '@page { size: auto; }', 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 () => { (async () => {
const server = await startServer(serverConf); const server = await startServer(serverConf);
@ -87,18 +105,10 @@ async function cleanupBeforePrint(page) {
const page = await browser.newPage(); const page = await browser.newPage();
logger.debug("opened new page"); logger.debug("opened new page");
const file = 'fr/schedule/index.html'; for (let [file, output] of Object.entries(outputs)) {
const url = `http://localhost:${serverConf.port}/${file}`; await renderPdf(page, file, output);
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});
logger.debug("pdf done"); logger.debug("pdf done");
} catch (e) { } catch (e) {

Loading…
Cancel
Save