Skip to content

Commit

Permalink
Render book as PDF in publish.yml workflow (#1572)
Browse files Browse the repository at this point in the history
Renders the book as a PDF and includes it in the published HTML bundle
as `comprehensive-rust.pdf`.

Closes #1543
  • Loading branch information
max-heller authored Jan 15, 2024
1 parent 3f1957c commit 9ed01cc
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
set -Eeuo pipefail

# Usage: build.sh <book-lang> <dest-dir>
Expand Down Expand Up @@ -29,9 +29,13 @@ else
export MDBOOK_BOOK__LANGUAGE=$book_lang
export MDBOOK_OUTPUT__HTML__SITE_URL=/comprehensive-rust/$book_lang/
export MDBOOK_OUTPUT__HTML__REDIRECT='{}'

# Include language-specific Pandoc configuration
[ -f "pandoc/$book_lang.yaml" ] && export MDBOOK_OUTPUT__PANDOC__PROFILE__PDF__DEFAULTS="pandoc/$book_lang.yaml"
fi

mdbook build -d "$dest_dir"
[ -f "$dest_dir/pandoc/pdf/comprehensive-rust.pdf" ] && mv "$dest_dir/pandoc/pdf/comprehensive-rust.pdf" "$dest_dir/html/"
(cd "$dest_dir/exerciser" && zip --recurse-paths ../html/comprehensive-rust-exercises.zip comprehensive-rust-exercises/)

echo "::endgroup::"
7 changes: 7 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ jobs:
- name: Install mdbook
uses: ./.github/workflows/install-mdbook

- name: Install mdbook-pandoc and related dependencies
run: |
cargo install mdbook-pandoc --locked --version 0.4.0
sudo apt-get install -y texlive texlive-luatex texlive-lang-cjk librsvg2-bin fonts-noto
curl -LsSf https://github.com/jgm/pandoc/releases/download/3.1.11/pandoc-3.1.11-linux-amd64.tar.gz | tar zxf -
echo "$PWD/pandoc-3.1.11/bin" >> $GITHUB_PATH
- name: Build course in English
run: .github/workflows/build.sh en book

Expand Down
15 changes: 15 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ verbose = false # Report timing information.
# [preprocessor.aspect-ratio-helper]
# command = "./aspect-ratio-helper.py"

[output.pandoc]
optional = true

[output.pandoc.profile.pdf]
output-file = "comprehensive-rust.pdf"
pdf-engine = "lualatex"

[output.pandoc.profile.pdf.variables]
mainfont = "Noto Serif"
sansfont = "Noto Sans"
monofont = "Noto Sans Mono"
geometry = ["margin=1.25in"]
linkcolor = "blue"
urlcolor = "red"

[output.html]
curly-quotes = true
additional-js = ["theme/speaker-notes.js"]
Expand Down
4 changes: 4 additions & 0 deletions pandoc/ja.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variables:
CJKmainfont: "Noto Serif CJK JP"
CJKsansfont: "Noto Sans CJK JP"
CJKmonofont: "Noto Sans Mono CJK JP"
4 changes: 4 additions & 0 deletions pandoc/ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variables:
CJKmainfont: "Noto Serif CJK KR"
CJKsansfont: "Noto Sans CJK KR"
CJKmonofont: "Noto Sans Mono CJK KR"
4 changes: 4 additions & 0 deletions pandoc/zh-CN.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variables:
CJKmainfont: "Noto Serif CJK SC"
CJKsansfont: "Noto Sans CJK SC"
CJKmonofont: "Noto Sans Mono CJK SC"
4 changes: 4 additions & 0 deletions pandoc/zh-TW.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variables:
CJKmainfont: "Noto Serif CJK TC"
CJKsansfont: "Noto Sans CJK TC"
CJKmonofont: "Noto Sans Mono CJK TC"

0 comments on commit 9ed01cc

Please sign in to comment.