From 2ccd0e1404572ee5c0087980933b57deb4f57e73 Mon Sep 17 00:00:00 2001 From: Max Heller Date: Sat, 16 Mar 2024 12:26:54 -0400 Subject: [PATCH] feat: render PDF version of book with `mdbook-pandoc` (#394) --- .github/workflows/install-mdbook/action.yml | 9 +++++++++ .github/workflows/publish.yml | 5 ++++- book.toml | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/install-mdbook/action.yml b/.github/workflows/install-mdbook/action.yml index e1482c3..30bb2b7 100644 --- a/.github/workflows/install-mdbook/action.yml +++ b/.github/workflows/install-mdbook/action.yml @@ -27,3 +27,12 @@ runs: - name: Install i18n-helpers run: cargo install mdbook-i18n-helpers --locked --version '${{ steps.mdbook-i18n-helpers-version.outputs.version }}' shell: bash + + - name: Install mdbook-pandoc and related dependencies + run: | + cargo install mdbook-pandoc --locked --version 0.5.0 + sudo apt-get update + 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.12.2/pandoc-3.1.12.2-linux-amd64.tar.gz | tar zxf - + echo "$PWD/pandoc-3.1.12.2/bin" >> $GITHUB_PATH + shell: bash diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 952a031..1b34358 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -40,7 +40,10 @@ jobs: uses: ./.github/workflows/install-mdbook - name: Build course in English - run: mdbook build -d book + run: | + mdbook build -d book + mv book/html/* book/pandoc/pdf/patterns.pdf book/ + rm -r book/html book/pandoc # TODO: Activate when first translation is available # - name: Build all translations diff --git a/book.toml b/book.toml index d927fac..34fb1e7 100644 --- a/book.toml +++ b/book.toml @@ -38,3 +38,20 @@ editable = false # Redirects in the form of "old-path" = "new-path", where the new path # is relative to the old path. "functional/lenses.html" = "optics.html" + +[output.pandoc] +optional = true +hosted-html = "https://rust-unofficial.github.io/patterns/" + +[output.pandoc.profile.pdf] +output-file = "patterns.pdf" +pdf-engine = "lualatex" + +[output.pandoc.profile.pdf.variables] +mainfont = "Noto Serif" +sansfont = "Noto Sans" +monofont = "Noto Sans Mono" +mainfontfallback = ["NotoSerifCJKSC:"] +geometry = ["margin=1.25in"] +linkcolor = "blue" +urlcolor = "red"