-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocs_templating.sh
More file actions
executable file
·41 lines (34 loc) · 960 Bytes
/
docs_templating.sh
File metadata and controls
executable file
·41 lines (34 loc) · 960 Bytes
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
#!/usr/bin/env bash
set -euo pipefail
# Reads a file with variables to insert into templates, and templates all .*.j2 files
# in the 'docs' directory.
#
# dependencies
# pip install jinja2-cli
docs_dir="$(dirname "$0")/../docs"
templating_vars_file="$docs_dir/templating_vars.yaml"
# Check if files need templating
if [[ -z $(find "$docs_dir" -name '*.j2') ]];
then
echo "No files need templating, exiting."
exit
fi
# Check if jinja2 is there
if ! command -v jinja2 &> /dev/null
then
echo "jinja2 could not be found. Use 'pip install jinja2-cli' to install it."
exit 1
fi
# Check if templating vars file exists
if [[ ! -f "$templating_vars_file" ]];
then
echo "$templating_vars_file does not exist, cannot start templating."
fi
find "$docs_dir" -name '*.j2' |
while read -r file
do
new_file_name=${file%.j2} # Remove .j2 suffix
echo "templating $new_file_name"
jinja2 "$file" "$templating_vars_file" -o "$new_file_name"
done
echo "done"