Skip to content

Commit

Permalink
PDF spec generation script fixups, & add to Travis
Browse files Browse the repository at this point in the history
also includes:
* Fix JS issue in spec PDF building
* Generate HTML for PDF in a separate folder

Co-authored-by: Sakib Hadziavdic <sake.etf@gmail.com>
  • Loading branch information
SethTisue and sake92 committed Dec 9, 2020
1 parent d9b2018 commit 6fb0680
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
@@ -1,7 +1,8 @@
version: ~> 1.0 # needed for imports

import: scala/scala-dev:travis/default.yml

dist: bionic # for generating spec PDF; see #7432

language: scala

stages:
Expand Down Expand Up @@ -105,10 +106,19 @@ jobs:
- gem install bundler
- bundler --version
- bundle install
# cribbed from https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/master/.travis.yml
- sudo apt-get update
- sudo apt-get install -y build-essential xorg xfonts-75dpi libpng16-16 libssl1.1
- wget --quiet "https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb"
- sudo dpkg -i "wkhtmltox_0.12.6-1.bionic_amd64.deb"
- rm "wkhtmltox_0.12.6-1.bionic_amd64.deb"
script:
- set -e
- (cd admin && ./init.sh)
- bundle exec jekyll build -s spec/ -d build/spec
- export JEKYLL_ENV=spec-pdf
- bundle exec jekyll build -s spec/ -d build/spec-pdf
- ./scripts/generate-spec-pdf.sh
after_success:
- ./scripts/travis-publish-spec.sh

Expand Down
29 changes: 23 additions & 6 deletions scripts/generate-spec-pdf.sh 100644 → 100755
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

set -e
set -v

# NOTES:
# "toc" -> treated just like another page, its location can be changed
# "--window-status loaded" -> when window.status is set to "loaded", wkhtmltopdf knows js is loaded
Expand All @@ -8,15 +11,29 @@ THIS_SCRIPT_DIR=$(dirname $0)
ROOT_DIR=$THIS_SCRIPT_DIR/..
SPEC_SRC_DIR=$ROOT_DIR/spec
SPEC_BUILD_DIR=$ROOT_DIR/build/spec
SPEC_PDF_BUILD_DIR=$ROOT_DIR/build/spec-pdf
PDF=$SPEC_BUILD_DIR/spec.pdf

mkdir -p $SPEC_PDF_BUILD_DIR


WKHTML_OPTS='--print-media-type --window-status loaded --footer-center [page] --javascript-delay 1000 --footer-font-name "Luxi Sans"'
WKHTML_OPTS='--print-media-type --window-status loaded --javascript-delay 1000 --load-error-handling ignore --enable-local-file-access --footer-center [page] --footer-font-name "Luxi Sans"'
WKHTML_TOC="toc --xsl-style-sheet $SPEC_SRC_DIR/spec-toc.xslt"

# exclude index.html, prepend SPEC_BUILD_DIR path
HTML_FILES=$(ls $SPEC_BUILD_DIR -I 'index.html' | grep '\.html$' | while read line; do echo "$SPEC_BUILD_DIR/$line"; done)
# exclude index.html, prepend SPEC_PDF_BUILD_DIR path
HTML_FILES=$(ls $SPEC_PDF_BUILD_DIR | grep -vx 'index.html' | grep '\.html$' | while read line; do echo "$SPEC_PDF_BUILD_DIR/$line"; done)
echo "Making Spec.pdf with HTML files: "
echo $SPEC_BUILD_DIR/index.html $HTML_FILES
echo "Making spec.pdf with HTML files: "
echo $SPEC_PDF_BUILD_DIR/index.html $HTML_FILES
# first goes index.html, then TOC, then rest
wkhtmltopdf $WKHTML_OPTS $SPEC_BUILD_DIR/index.html $WKHTML_TOC $HTML_FILES $SPEC_BUILD_DIR/Spec.pdf
rm -f $PDF
wkhtmltopdf $WKHTML_OPTS $SPEC_PDF_BUILD_DIR/index.html $WKHTML_TOC $HTML_FILES $PDF || true
# the '|| true' thing is because we get:
# Error: Failed to load http:/, with network status code 3 and http status code 0 - Host not found
# Warning: Failed loading page http: (ignored)
# as long we have `--load-error-handling ignore` we still get a PDF, but we also get a nonzero exit code
# fail if we didn't get a PDF file out
if [ ! -f $PDF ] ; then exit 1 ; fi
4 changes: 2 additions & 2 deletions spec/_layouts/default.yml
Expand Up @@ -8,8 +8,7 @@

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.min.css" integrity="sha384-9eLZqc9ds8eNjO3TmqPeYcDj8n+Qfa4nuSiGYa6DjLNcv9BtN69ZIulL9+8CqC9Y" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.min.js" integrity="sha384-K3vbOmF2BtaVai+Qk37uypf7VrgBubhQreNQe9aGsz9lB63dIFiQVlJbr92dw2Lx" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/contrib/auto-render.min.js" integrity="sha384-kmZOZB5ObwgQnS/DuDg6TScgOiWWBiVt0plIRkZCmE6rDZGrEOQeHM5PcHi+nyqe" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/contrib/auto-render.min.js" integrity="sha384-kmZOZB5ObwgQnS/DuDg6TScgOiWWBiVt0plIRkZCmE6rDZGrEOQeHM5PcHi+nyqe" crossorigin="anonymous"></script>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/styles/default.min.css">
Expand Down Expand Up @@ -44,6 +43,7 @@
{{ content }}
</main>

<script>window.jekyllEnv = '{{jekyll.environment}}';</script>
<script src="public/scripts/toc.js"></script>
<script src="public/scripts/highlight.pack.js"></script>
<script src="public/scripts/main.js"></script>
Expand Down
23 changes: 13 additions & 10 deletions spec/public/scripts/main.js
Expand Up @@ -27,16 +27,19 @@ function heading(i, heading, $heading) {
}
}

$('#toc').toc(
{
'selectors': 'h1,h2,h3',
'smoothScrolling': false,
'chapter': currentChapter(),
'headerLevel': 1,
'headerCounts': [-1, currentChapter() - 1, 1, 1],
'headerText': heading
}
);
// ignore when using wkhtmltopdf, or it won't work...
if(window.jekyllEnv !== 'spec-pdf') {
$('#toc').toc(
{
'selectors': 'h1,h2,h3',
'smoothScrolling': false,
'chapter': currentChapter(),
'headerLevel': 1,
'headerCounts': [-1, currentChapter() - 1, 1, 1],
'headerText': heading
}
);
}

// no language auto-detect so that EBNF isn't detected as scala
hljs.configure({
Expand Down

0 comments on commit 6fb0680

Please sign in to comment.