@@ -168,18 +168,20 @@ if [ $# -ne 1 ]; then
168
168
fi
169
169
170
170
# input file check
171
- input_file =$1
172
- if [ ! -e " ${input_file } " ]; then
173
- >&2 echo " ${input_file } does not exist, exiting..."
171
+ INPUT_FILE =$1
172
+ if [ ! -e " ${INPUT_FILE } " ]; then
173
+ >&2 echo " ${INPUT_FILE } does not exist, exiting..."
174
174
exit 1
175
175
fi
176
176
177
+ # at least one output must be requested
177
178
if [ -z " ${PDF_OUTPUT}${LATEX_OUTPUT}${DOCX_OUTPUT}${HTML_OUTPUT} " ]; then
178
179
>&2 echo " Expected --pdf, --docx, --html, or --latex option"
179
180
print_usage
180
181
exit 1
181
182
fi
182
183
184
+ # the pdf engine must be supported
183
185
if [ " ${PDF_ENGINE} " != " xelatex" -a " ${PDF_ENGINE} " != " lualatex" ]; then
184
186
>&2 echo " Unsupported PDF engine '${PDF_ENGINE} ', expected one of: xelatex, lualatex"
185
187
print_usage
@@ -206,7 +208,7 @@ if ! browser=$(command -v "chromium-browser"); then
206
208
fi
207
209
208
210
# figure out git version and revision if needed.
209
- extra_pandoc_options =" "
211
+ EXTRA_PANDOC_OPTIONS =" "
210
212
if test " ${DO_GITVERSION} " == " yes" ; then
211
213
git config --global --add safe.directory /workspace
212
214
@@ -269,25 +271,25 @@ if test "${DO_GITVERSION}" == "yes"; then
269
271
270
272
if [ ! -z " ${PR_NUMBER} " ]; then
271
273
# In the case of a PR, always just provide the PR number and commit
272
- extra_pandoc_options +=" --metadata=PR_NUMBER:${PR_NUMBER} "
273
- extra_pandoc_options +=" --metadata=revision:${GIT_COMMIT} "
274
+ EXTRA_PANDOC_OPTIONS +=" --metadata=PR_NUMBER:${PR_NUMBER} "
275
+ EXTRA_PANDOC_OPTIONS +=" --metadata=revision:${GIT_COMMIT} "
274
276
status=" Pull Request"
275
277
if [ ! -z " ${PR_REPO} " ]; then
276
- extra_pandoc_options +=" --metadata=PR_REPO_url:https://github.com/${PR_REPO} "
278
+ EXTRA_PANDOC_OPTIONS +=" --metadata=PR_REPO_url:https://github.com/${PR_REPO} "
277
279
fi
278
280
else
279
281
# Otherwise, populate the full context based on what git show said.
280
- extra_pandoc_options +=" --metadata=version:${GIT_VERSION} "
282
+ EXTRA_PANDOC_OPTIONS +=" --metadata=version:${GIT_VERSION} "
281
283
282
284
if [ ! -z " ${GIT_PRERELEASE} " ]; then
283
- extra_pandoc_options +=" --metadata=prerelease:${GIT_PRERELEASE} "
285
+ EXTRA_PANDOC_OPTIONS +=" --metadata=prerelease:${GIT_PRERELEASE} "
284
286
fi
285
287
286
288
# Omit the revision if there isn't one (i.e., we are at straight-up Version)
287
289
if [ ! -z " ${GIT_REVISION} " ]; then
288
- extra_pandoc_options +=" --metadata=revision:${GIT_REVISION} "
290
+ EXTRA_PANDOC_OPTIONS +=" --metadata=revision:${GIT_REVISION} "
289
291
elif [ -z " ${GIT_VERSION} " ]; then
290
- extra_pandoc_options +=" --metadata=revision:${GIT_COMMIT} "
292
+ EXTRA_PANDOC_OPTIONS +=" --metadata=revision:${GIT_COMMIT} "
291
293
fi
292
294
293
295
# Do we set document status based on git version?
@@ -304,7 +306,7 @@ if test "${DO_GITVERSION}" == "yes"; then
304
306
fi
305
307
fi
306
308
fi
307
- extra_pandoc_options +=" --metadata=status:\" ${status} \" "
309
+ EXTRA_PANDOC_OPTIONS +=" --metadata=status:\" ${status} \" "
308
310
309
311
fi # Done with git version handling
310
312
@@ -359,7 +361,7 @@ readonly HTML_OUTPUT
359
361
readonly LATEX_OUTPUT
360
362
361
363
echo " Starting Build with"
362
- echo " file: ${input_file } "
364
+ echo " file: ${INPUT_FILE } "
363
365
echo " docx: ${DOCX_OUTPUT:- none} "
364
366
echo " pdf: ${PDF_OUTPUT:- none} (engine: ${PDF_ENGINE} )"
365
367
echo " latex: ${latex_ouput:- none} "
@@ -413,7 +415,7 @@ cat <<- EOF > ./.puppeteer.json
413
415
EOF
414
416
415
417
if [ " ${BLOCK_QUOTES_ARE_INFORMATIVE_TEXT} " == " yes" ]; then
416
- extra_pandoc_options +=" --lua-filter=informative-quote-blocks.lua"
418
+ EXTRA_PANDOC_OPTIONS +=" --lua-filter=informative-quote-blocks.lua"
417
419
fi
418
420
419
421
# Hacks
422
424
# Transform horizontal rules into \newpages.
423
425
# Exception: the YAML front matter of the document, so undo the instance on the first line.
424
426
# TODO: Turn this into a Pandoc filter.
425
- sed -i.bak ' s/^---$/\\newpage/g;1s/\\newpage/---/g' " ${BUILD_DIR} /${input_file } "
427
+ sed -i.bak ' s/^---$/\\newpage/g;1s/\\newpage/---/g' " ${BUILD_DIR} /${INPUT_FILE } "
426
428
427
429
# Transform sections before the table of contents into section*, which does not number them.
428
430
# While we're doing this, transform the case to all-caps.
429
431
# TODO: Turn this into a Pandoc filter.
430
- sed -i.bak ' 0,/\\tableofcontents/s/^# \(.*\)/\\section*\{\U\1\}/g' " ${BUILD_DIR} /${input_file } "
432
+ sed -i.bak ' 0,/\\tableofcontents/s/^# \(.*\)/\\section*\{\U\1\}/g' " ${BUILD_DIR} /${INPUT_FILE } "
431
433
432
434
if test " ${DO_GITVERSION} " == " yes" ; then
433
435
# If using the git information for versioning, grab the date from there
434
436
DATE=" $( git show -s --date=format:' %Y/%m/%d' --format=%ad) "
435
437
else
436
438
# Else, grab the date from the front matter and generate the full date and year.
437
- DATE=" $( grep date: " ${input_file } " | head -n 1 | cut -d ' ' -f 2) "
439
+ DATE=" $( grep date: " ${INPUT_FILE } " | head -n 1 | cut -d ' ' -f 2) "
438
440
fi
439
441
440
442
YEAR=" $( date --date=" ${DATE} " +%Y) "
@@ -542,7 +544,7 @@ do_latex() {
542
544
--metadata=colorlinks:true
543
545
--metadata=contact:
[email protected]
544
546
--from=${FROM}
545
- ${extra_pandoc_options }
547
+ ${EXTRA_PANDOC_OPTIONS }
546
548
--to=latex
547
549
--output=" '${output} '"
548
550
" '${input} '" )
@@ -563,24 +565,24 @@ do_pdf() {
563
565
564
566
local logfile=$3
565
567
# LaTeX engines choose this filename based on TEMP_TEX_FILE's basename. It also emits a bunch of other files.
566
- readonly temp_pdf_file=" $( basename ${input} ) .pdf"
568
+ readonly temp_pdf_file=" $( basename ${input% . * } ) .pdf"
567
569
568
570
echo " Rendering PDF"
569
- start=$( date +%s)
571
+ local start=$( date +%s)
570
572
# latexmk takes care of repeatedly calling the PDF engine. A run may take multiple passes due to the need to
571
573
# update .toc and other files.
572
574
latexmk " ${input} " -pdflatex=" ${PDF_ENGINE} " -pdf -diagnostics > " ${logfile} "
573
575
if [ $? -ne 0 ]; then
574
576
FAILED=true
575
577
echo " PDF output failed"
576
578
fi
577
- end=$( date +%s)
579
+ local end=$( date +%s)
578
580
# Write any LaTeX errors to stderr.
579
581
>&2 grep -A 5 " ] ! " " ${logfile} "
580
582
581
583
# Copy aux, lof, lot, and toc files back to the source directory so they can be cached and speed up future runs.
582
584
if [ -n " ${PDFLOG_OUTPUT} " ]; then
583
- cp " ${logfile} " " ${PDFLOG_OUTPUT} "
585
+ cp " ${logfile} " " ${SOURCE_DIR} / ${ PDFLOG_OUTPUT}"
584
586
fi
585
587
cp * .aux " ${SOURCE_DIR} "
586
588
cp * .lof " ${SOURCE_DIR} "
@@ -603,7 +605,7 @@ do_docx() {
603
605
local output=$2
604
606
mkdir -p " $( dirname ${output} ) "
605
607
# Prepare the title-page for the docx version.
606
- subtitle=" Version ${GIT_VERSION:- ${DATE} } , Revision ${GIT_REVISION:- 0} "
608
+ local subtitle=" Version ${GIT_VERSION:- ${DATE} } , Revision ${GIT_REVISION:- 0} "
607
609
# Prefix the document with a Word page-break, since Pandoc doesn't do docx
608
610
# title pages.
609
611
cat << - 'EOF ' > "${input}.prefixed"
@@ -615,7 +617,7 @@ do_docx() {
615
617
</w:p>
616
618
```
617
619
EOF
618
- cat " ${BUILD_DIR} /${input_file } " >> " ${input} .prefixed"
620
+ cat " ${BUILD_DIR} /${INPUT_FILE } " >> " ${input} .prefixed"
619
621
620
622
echo " Generating DOCX Output"
621
623
cmd=(pandoc
@@ -634,7 +636,7 @@ do_docx() {
634
636
--from=' ${FROM}+raw_attribute'
635
637
--metadata=subtitle:" '${subtitle} '"
636
638
--reference-doc=/resources/templates/tcg.docx
637
- ${extra_pandoc_options }
639
+ ${EXTRA_PANDOC_OPTIONS }
638
640
--to=docx
639
641
--output=" '${output} '"
640
642
" '${input} .prefixed'" )
@@ -653,7 +655,7 @@ do_html() {
653
655
local output=$2
654
656
mkdir -p " $( dirname ${output} ) "
655
657
echo " Generating HTML Output"
656
- cmd=(pandoc
658
+ local cmd=(pandoc
657
659
--toc
658
660
-V colorlinks=true
659
661
-V linkcolor=blue
@@ -682,7 +684,7 @@ do_html() {
682
684
--metadata=colorlinks:true
683
685
--metadata=contact:
[email protected]
684
686
--from=${FROM}
685
- ${extra_pandoc_options }
687
+ ${EXTRA_PANDOC_OPTIONS }
686
688
--to=html
687
689
--output=" '${output} '"
688
690
" '${input} '" )
@@ -697,9 +699,9 @@ do_html() {
697
699
698
700
# Generate .tex output if either latex or pdf formats were requested, because
699
701
# the .tex is an intermediate requirement to the pdf.
700
- readonly TEMP_TEX_FILE=" ${BUILD_DIR} /${input_file } .tex"
702
+ readonly TEMP_TEX_FILE=" ${BUILD_DIR} /${INPUT_FILE } .tex"
701
703
if [ -n " ${PDF_OUTPUT} " -o -n " ${LATEX_OUTPUT} " ]; then
702
- do_latex " ${BUILD_DIR} /${input_file } " " ${TEMP_TEX_FILE} "
704
+ do_latex " ${BUILD_DIR} /${INPUT_FILE } " " ${TEMP_TEX_FILE} "
703
705
fi
704
706
if [ -n " ${LATEX_OUTPUT} " ]; then
705
707
cp " ${TEMP_TEX_FILE} " " ${SOURCE_DIR} /${LATEX_OUTPUT} "
713
715
714
716
# Generate the docx output
715
717
if [ -n " ${DOCX_OUTPUT} " ]; then
716
- do_docx " ${BUILD_DIR} /${input_file } " " ${SOURCE_DIR} /${DOCX_OUTPUT} "
718
+ do_docx " ${BUILD_DIR} /${INPUT_FILE } " " ${SOURCE_DIR} /${DOCX_OUTPUT} "
717
719
fi
718
720
719
721
# Generate the html output
720
722
export MERMAID_FILTER_FORMAT=" svg"
721
723
if [ -n " ${HTML_OUTPUT} " ]; then
722
- do_html " ${BUILD_DIR} /${input_file } " " ${SOURCE_DIR} /${HTML_OUTPUT} "
724
+ do_html " ${BUILD_DIR} /${INPUT_FILE } " " ${SOURCE_DIR} /${HTML_OUTPUT} "
723
725
fi
724
726
725
727
if [ " ${FAILED} " = " true" ]; then
0 commit comments