1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-02-05 10:44:17 +02:00
Max Heller df2076b111
Upgrade mdbook-pandoc and disable it except during CI workflows (#2212)
Implements the approach summarized in
https://github.com/google/mdbook-i18n-helpers/issues/200#issuecomment-2220035461
to disable running `mdbook-pandoc` even if it is available to avoid
dependency-related issues during local rendering.

Should address https://github.com/google/comprehensive-rust/issues/1911
since `mdbook-pandoc` will no longer run locally.
2024-07-18 13:01:25 +02:00

51 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
# Usage: build.sh <book-lang> <dest-dir>
#
# Build the course as of the date specified specified in the
# POT-Creation-Date header of po/$book_lang.po. The output can be
# found in $dest_dir.
#
# The src/ and third_party/ directories are left in a dirty state so
# you can run `mdbook test` and other commands afterwards.
book_lang=${1:?"Usage: $0 <book-lang> <dest-dir>"}
dest_dir=${2:?"Usage: $0 <book-lang> <dest-dir>"}
if [ "$book_lang" = "en" ]; then
echo "::group::Building English course"
else
pot_creation_date=$(grep --max-count 1 '^"POT-Creation-Date:' "po/$book_lang.po" | sed -E 's/".*: (.*)\\n"/\1/')
pot_creation_date=${pot_creation_date:-now}
echo "::group::Building $book_lang translation as of $pot_creation_date"
# Back-date the sources to POT-Creation-Date. The content lives in two
# directories:
rm -r src/ third_party/
git restore --source "$(git rev-list -n 1 --before "$pot_creation_date" @)" src/ third_party/
# Set language and adjust site URL. Clear the redirects since they are
# in sync with the source files, not the translation.
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
if [ -f ".github/pandoc/$book_lang.yaml" ]; then
export MDBOOK_OUTPUT__PANDOC__PROFILE__PDF__DEFAULTS=".github/pandoc/$book_lang.yaml"
fi
fi
# Enable mdbook-pandoc to build PDF version of the course
export MDBOOK_OUTPUT__PANDOC__DISABLED=false
mdbook build -d "$dest_dir"
# Disable the redbox button in built versions of the course
echo '// Disabled in published builds, see build.sh' > "${dest_dir}/html/theme/redbox.js"
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::"