-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·147 lines (96 loc) · 4.73 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash -evx
# Support generation of HTML, PDF, and other versions of a single master CV,
# which is kept under source control in Markdown format.
#
# Inspired by Mark Szepieniec's project, "The Markdown Resume":
#
# https://mszep.github.io/pandoc_resume/
# Ensure that the current working directory is the script parent directory (the
# directory in which this Bash script resides); this is necessary for proper
# file access in the Docker container used for the conversions.
cd "$(dirname "${BASH_SOURCE[0]}")"
# Name of the directory in which to place generated files, relative to the
# script parent directory.
output_dir='output'
# Name of the directory containing generic content for inclusion in generated
# files, relative to the script parent directory.
include_dir='include'
# Filename prefix of master input file.
input='cv'
# Master input file, in Markdown format.
input_md="$input.md"
# Output file consisting of master input file with full contact information
# added, if available, in Markdown format.
output_md="$output_dir/$input_md"
# Microsoft Word, HTML, PDF, RTF, and LaTeX output documents.
output_docx="$output_dir/$input.docx"
output_html="$output_dir/$input.html"
output_pdf="$output_dir/$input.pdf"
output_rtf="$output_dir/$input.rtf"
output_tex="$output_dir/$input.tex"
# Pattern in the CV to be replaced with full contact information, if available.
contact_search='^<https://www[.]linkedin[.]com/.*>$'
# Optional file containing full contact information.
contact_replace="$include_dir/contact.md"
# String of sed commands for transforming the ASCII representations " - " and
# "--" of en and em dashes, respectively, into the "--" and "---" expected by
# LaTeX. Note that word boundaries ("\b") behave differently in the BSD
# (MacOs) and GNU (Linux) versions of sed, so we match non-hyphen characters
# instead.
dash_munge='s|\([^-]\)--\([^-]\)|\1---\2|g;s|\([^-]\) - \([^-]\)|\1--\2|g'
# Intermediate file for dash transformation.
munged_md="$output_dir/$input.munged.md"
# Command to run Pandoc in a Docker container, mounting a Docker volume in
# order to allow access to files in the current directory and its
# subdirectories. The output file is a standalone document, not a fragment,
# and "smart" processing of apostrophes, quotation marks, hyphens, and dashes
# is enabled. The MSYS_NO_PATHCONV variable is set to allow proper operation
# in the Windows Git Bash environment.
pandoc="MSYS_NO_PATHCONV=1 docker run --volume='$PWD:/source' \
jagregory/pandoc --standalone --smart"
# Generic HTML header specifying formatting options like the default typeface
# style.
header_html="$include_dir/header.html"
# Generic LaTeX header specifying formatting options like like the margins and
# the default typeface style.
header_tex="$include_dir/header.tex"
# Generic Microsoft Word reference document specifying formatting options like
# the default typeface style.
reference_docx="$include_dir/reference.docx"
# Create the output directory if it doesn't already exist.
mkdir -p "$output_dir"
# Remove output and intermediate files, if present, to ensure a clean build.
rm -f "$munged_md" "$output_docx" "$output_html" "$output_md" "$output_pdf" \
"$output_rtf" "$output_tex"
# Generate final Markdown file with full contact information, if available.
if [ -r "$contact_replace" ]; then
sed "\|$contact_search|{r $contact_replace
d;}" "$input_md" > "$output_md"
else
cp "$input_md" "$output_md"
fi
# Generate intermediate Markdown file for processing into LaTeX document,
# transforming ASCII representations of dashes.
sed "$dash_munge" "$output_md" > "$munged_md"
# Generate Microsoft Word document intermediate Markdown file and generic
# reference document.
eval $pandoc --reference-doc="$reference_docx" \
--from='markdown' --to='docx' --output="$output_docx" "$munged_md"
# Generate HTML document intermediate Markdown file and generic HTML header.
eval $pandoc --include-in-header="$header_html" \
--from='markdown' --to='html5' --output="$output_html" "$munged_md"
# Generate PDF document from intermediate Markdown file and generic LaTeX
# header; as documented here, the output format must be specified as "latex"
# instead of "pdf":
#
# https://hub.docker.com/r/jagregory/pandoc/
eval $pandoc --include-in-header="$header_tex" \
--from='markdown' --to='latex' --output="$output_pdf" "$munged_md"
# Generate RTF document from intermediate Markdown file.
eval $pandoc \
--from='markdown' --to='rtf' --output="$output_rtf" "$munged_md"
# Generate LaTeX document from intermediate Markdown file.
eval $pandoc \
--from='markdown' --to='latex' --output="$output_tex" "$munged_md"
# Remove intermediate file.
rm -f "$munged_md"