This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_alphagov_tech_docs_template.sh
56 lines (47 loc) · 2.26 KB
/
build_alphagov_tech_docs_template.sh
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
#!/bin/sh
# If `jq` is installed, get the latest commit hash from the `alphagov/tech-docs-template` repository using GitHub API
if hash jq 2>/dev/null ; then
LATEST_COMMIT=$(curl https://api.github.com/repos/alphagov/tech-docs-template/commits/master -s | jq .sha -r)
if [ $? -ne 0 ]; then
echo 'Could not get latest commit hash from `alphagov/tech-docs-template` GitHub repository!'
exit 1
fi
else
echo '`jq` package not installed! See https://stedolan.github.io/jq/'
exit 127
fi
# Delete any existing local build of `alphagov/tech-docs-template`
if [ -d ${DIR_SOURCE_ALPHAGOV_TECH_DOCS_TEMPLATE} ]; then rm -rf ${DIR_SOURCE_ALPHAGOV_TECH_DOCS_TEMPLATE}; fi
# If `middleman` is installed, initialise the Middleman `alphagov/tech-docs-template` with some default settings, move
# into the local build directory, and build the template. Then delete everything except the `build` folder, and the
# `.template_version` file
if hash middleman 2>/dev/null ; then
FIRST_TIME=true USE_PAAS=true APPLICATION_NAME=source CANONICAL_HOST=source middleman init ${DIR_SOURCE_ALPHAGOV_TECH_DOCS_TEMPLATE} -T alphagov/tech-docs-template &&
cd ${DIR_SOURCE_ALPHAGOV_TECH_DOCS_TEMPLATE} &&
bundle exec middleman build &&
ls -A | grep -v 'build\|.template_version' | xargs rm -rf &&
cd $(pwd)
# Raise an error if the build does not complete
if [ $? -ne 0 ]; then
echo 'Could not build Middleman `alphagov/tech-docs-template` template!'
exit 1
fi
else
echo 'Middleman is not installed! See https://github.com/alphagov/tech-docs-template'
exit 127
fi
if [ $? -eq 0 ]; then
# Iterate over all .css and .html files, which need to have referenced file paths amended
for file in $(find ${DIR_SOURCE_ALPHAGOV_TECH_DOCS_TEMPLATE} -type f | grep '\(\.css\|\.html\)$')
do
# Find and replace referenced file paths to relative paths, depending on the file type
if [[ ${file} == *.html ]]; then
sed -i '' 's|src="/assets/|src="./assets/|g' ${file}
sed -i '' 's|src="/javascripts/|src="./javascripts/|g' ${file}
sed -i '' 's|href="/stylesheets/|href="./stylesheets/|g' ${file}
elif [[ ${file} == *.css ]]; then
sed -i '' 's|url("/assets/|url("../assets/|g' ${file}
sed -i '' 's|url("/images/|url("../images/|g' ${file}
fi
done
fi