diff --git a/.gitignore b/.gitignore index 46e77f4..0892a54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -book.pdf - -# Created by https://www.gitignore.io/api/ruby,linux,jekyll +# Created by https://www.gitignore.io/api/node,ruby,linux,jekyll ### Jekyll ### _site/ @@ -22,6 +20,67 @@ _site/ # .nfs files are created when an open file is removed but is still being accessed .nfs* +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + ### Ruby ### *.gem *.rbc @@ -34,6 +93,7 @@ _site/ /test/tmp/ /test/version_tmp/ /tmp/ +package-lock.json # Used by dotenv library to load environment variables. # .env @@ -74,4 +134,4 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc -# End of https://www.gitignore.io/api/ruby,linux,jekyll +# End of https://www.gitignore.io/api/node,ruby,linux,jekyll diff --git a/utils/convert_to_pdf.js b/utils/convert_to_pdf.js new file mode 100644 index 0000000..5e2474f --- /dev/null +++ b/utils/convert_to_pdf.js @@ -0,0 +1,41 @@ +--- +--- +"use strict"; + +const puppeteer = require("puppeteer") +const fs = require("fs") +const os = require("os") + +var links = {{ site.data.links_en | jsonify }}; + +(async() => { + const browser = await puppeteer.launch() + const page = await browser.newPage() + + var root = "file:///" + __dirname + "/../en/" + console.log("Root is: " + root) + + for (var i = 0; i < links.length; i++) { + var link = links[i] + if (link.link) { + console.log("Rendering " + link.title) + await page.goto(root + link.link, {waitUntil: "networkidle"}) + + // page.pdf() is currently supported only in headless mode. + // @see https://bugs.chromium.org/p/chromium/issues/detail?id=753118 + const margin = "0.2in" + await page.pdf({ + path: "tmp/page_" + (link.num || ("0_" + link.title.replace(".", "_"))) + ".pdf", + format: "A5", + margin: { + top: margin, + right: margin, + bottom: margin, + left: margin, + } + }) + } + } + browser.close() + +})() diff --git a/utils/convert_to_pdf.sh b/utils/convert_to_pdf.sh index 935bd17..1687d30 100755 --- a/utils/convert_to_pdf.sh +++ b/utils/convert_to_pdf.sh @@ -1,25 +1,6 @@ ---- ---- #!/bin/sh -oldCWD="$PWD" -cd $(dirname $0) -cd ../en/ - -#wkhtmltopdf --print-media-type {% for link in site.data.links_en %}{% if link.link %}{{ link.link }} {% endif %}{% endfor %} out.pdf -#mv out.pdf $oldCWD/book.pdf - -{% for link in site.data.links_en %} -{% if link.link %} -/opt/google/chrome/google-chrome --headless --disable-gpu --print-to-pdf file:///${PWD}/{{ link.link }} - -{% if link.num %} -mv output.pdf page_{{ link.num }}.pdf -{% else %} -mv output.pdf page_0_{{ link.link | replace:".","_" }}.pdf -{% endif %} - -{% endif %} -{% endfor %} - -pdfunite page*.pdf ${oldCWD}/book.pdf +jekyll build +mkdir -p tmp +n use latest _site/utils/convert_to_pdf.js +pdfunite tmp/page*.pdf tmp/book.pdf