From eb00adeca5af43dfb93cde1ee71afd9b78626e30 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 22 Sep 2017 01:42:05 +0100 Subject: [PATCH] Fix PDF export script messing up order --- utils/convert_to_pdf.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/utils/convert_to_pdf.js b/utils/convert_to_pdf.js index 5e2474f..c4c5ada 100644 --- a/utils/convert_to_pdf.js +++ b/utils/convert_to_pdf.js @@ -2,6 +2,15 @@ --- "use strict"; +Number.prototype.pad = function(size) { + size = size || 2; + var s = String(this) + while (s.length < size) { + s = "0" + s; + } + return s; +} + const puppeteer = require("puppeteer") const fs = require("fs") const os = require("os") @@ -24,8 +33,9 @@ var links = {{ site.data.links_en | jsonify }}; // page.pdf() is currently supported only in headless mode. // @see https://bugs.chromium.org/p/chromium/issues/detail?id=753118 const margin = "0.2in" + const file_seg = link.num ? link.num.pad() : ("0_" + link.title.replace(".", "_")) await page.pdf({ - path: "tmp/page_" + (link.num || ("0_" + link.title.replace(".", "_"))) + ".pdf", + path: "tmp/page_" + file_seg + ".pdf", format: "A5", margin: { top: margin,