#!/bin/bash # ================================================================ # Builds a single-file epub of the Miller documentation from the generated # Markdown files in docs/src, for offline reading (issue #1835). # # Usage: docs/build-epub.sh [output-path] # Default output is ./miller-docs.epub. # # Requires pandoc (https://pandoc.org). This script is invoked on Read the # Docs (see .readthedocs.yaml) to publish an epub download alongside the HTML # docs; Read the Docs' built-in `formats:` support only produces epub/PDF for # Sphinx projects, not MkDocs ones, hence this script. It can also be run # locally by anyone with pandoc installed. It is not part of `make dev` or # any other default build path. # ================================================================ set -euo pipefail output="${1:-miller-docs.epub}" # Make the output path absolute, since we cd around below. case "$output" in /*) ;; *) output="$PWD/$output" ;; esac docs_dir=$(cd "$(dirname "$0")" && pwd) src_dir="$docs_dir/src" if ! command -v pandoc > /dev/null 2>&1; then echo "$0: pandoc not found; please install it (https://pandoc.org)." 1>&2 exit 1 fi # Chapter ordering is the nav order in mkdocs.yml. Nav entries look like # - "Miller in 10 minutes": "10min.md" # and these are the only lines in mkdocs.yml ending with a quoted .md name. chapters=$(sed -n 's/^ *-.*: *"\(.*\.md\)" *$/\1/p' "$docs_dir/mkdocs.yml") if [ -z "$chapters" ]; then echo "$0: could not extract any nav entries from $docs_dir/mkdocs.yml." 1>&2 exit 1 fi tmp_dir=$(mktemp -d) trap 'rm -rf "$tmp_dir"' EXIT # Each generated page starts with a quicklinks navigation block -- raw HTML, # useful on the website but not in an epub -- which we strip here. It is the # only