feat: accept any .adoc file in PDF generation script
This commit is contained in:
+39
-18
@@ -1,11 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate the documentation export(s) from README.adoc.
|
||||
# Generate the HTML/PDF export(s) from any .adoc document (README.adoc by default).
|
||||
#
|
||||
# docs/generate-readme-pdf.sh # README.html + README.pdf
|
||||
# docs/generate-readme-pdf.sh --html # README.html only
|
||||
# docs/generate-readme-pdf.sh --pdf # README.pdf only
|
||||
# docs/generate-readme-pdf.sh # README.html + README.pdf
|
||||
# docs/generate-readme-pdf.sh --html # README.html only
|
||||
# docs/generate-readme-pdf.sh --pdf # README.pdf only
|
||||
# docs/generate-readme-pdf.sh DEPLOY.adoc # DEPLOY.html + DEPLOY.pdf
|
||||
# docs/generate-readme-pdf.sh DEPLOY.adoc --pdf # DEPLOY.pdf only
|
||||
#
|
||||
# Both outputs land in the project root and are Git-ignored.
|
||||
# Outputs land in the project root (named after the source) and are Git-ignored.
|
||||
#
|
||||
# Requirements:
|
||||
# - asciidoctor (e.g. gem install asciidoctor)
|
||||
@@ -22,14 +24,41 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
|
||||
MODE="${1:---all}"
|
||||
HTML_OUT="README.html"
|
||||
PDF_OUT="README.pdf"
|
||||
SRC="README.adoc"
|
||||
MODE="--all"
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--html|--pdf|--all)
|
||||
MODE="$arg"
|
||||
;;
|
||||
-h|--help)
|
||||
sed -n '2,12p' "$0"
|
||||
exit 0
|
||||
;;
|
||||
*.adoc)
|
||||
SRC="$arg"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [fichier.adoc] [--html|--pdf|--all]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ! -f "$SRC" ]]; then
|
||||
echo "Erreur : fichier introuvable : $SRC" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE="$(basename "$SRC" .adoc)"
|
||||
HTML_OUT="$BASE.html"
|
||||
PDF_OUT="$BASE.pdf"
|
||||
|
||||
build_html() {
|
||||
asciidoctor -b html5 -a docinfodir=docs -a docinfo=shared README.adoc -o "$1"
|
||||
asciidoctor -b html5 -a docinfodir=docs -a docinfo=shared "$SRC" -o "$1"
|
||||
echo "HTML generated: $1"
|
||||
}
|
||||
|
||||
@@ -58,12 +87,4 @@ case "$MODE" in
|
||||
build_html "$HTML_OUT"
|
||||
build_pdf "$HTML_OUT"
|
||||
;;
|
||||
-h|--help)
|
||||
sed -n '2,10p' "$0"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [--html|--pdf|--all]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user