-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·161 lines (140 loc) · 4.82 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·161 lines (140 loc) · 4.82 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# "docs_src/build.sh" | v0.5.0 | 2020/03/21
# ------------------------------------------------------------------------------
# By Tristano Ajmone, released into the public domain via the Unlicense.
# ------------------------------------------------------------------------------
# This script requires installation of the following applications:
#
# Asciidoctor (Ruby gem):
# https://asciidoctor.org
#
# Highlight >= 3.51:
# http://www.andre-simon.de
# ------------------------------------------------------------------------------
source=hugo-book.asciidoc
HTML_output=hugo-book.html
HTML_outDir=..
HTML_TOCLev=1
WWW=../docs/index.html
ADoc_output=../hugo-book.asciidoc
# Highlight Set-up
# ================
# We need to override Highlight default settings and langDefs with our custom
# versions, and make visible any other custom scripts inside ../assets/hl/.
export HIGHLIGHT_DATADIR="$(pwd)/../assets/hl"
. ../assets/sh/_print-funcs.sh
# Show Build Banner and Info
# ==========================
printBanner "Building The Hugo Book"
# Get Dependencies Version Info
# -----------------------------
vHighlight=$(highlight --version | grep -o -m1 -E '[0-9]\.[0-9][0-9]')
vAsciidoctor=$(asciidoctor --version | grep -o -m1 -E '[0-9]\.[0-9]+\.[0-9]+')
vRuby=$(ruby --version | grep -o -m1 -E '[0-9]\.[0-9]+\.[0-9]+')
echo -e "\n\033[37;1mDependencies version info:"
echo -e "\033[31;1m *\033[35m Ruby v$vRuby"
echo -e "\033[31;1m *\033[35m Asciidoctor v$vAsciidoctor"
echo -e "\033[31;1m *\033[35m Highlight v$vHighlight"
# 1. Build HTML Document
# ======================
printHeading1 "Hugo Book: Build HTML Document"
echo -e "\033[37;1mConverting to standalone HTML document: \033[33;1m$HTML_outDir/$HTML_output\033[0m"
echo -e "\033[31;1m *\033[0m TOC levels: $HTML_TOCLev."
echo -e "\033[31;1m *\033[0m Single document."
echo -e "\033[31;1m *\033[0m Graphics embedded via data-URI."
echo -e "\033[31;1m *\033[0m Custom Haml HTML5 templates."
echo -e "\033[31;1m *\033[0m Syntax highlighting via Highlight (no JS dependencies)."
printSeparator
echo -e "\033[30;1m\c"
asciidoctor \
--failure-level WARN \
--timings \
--verbose \
--safe-mode unsafe \
-a data-uri \
-a experimental \
-a icons=font \
-a sectanchors \
-a toc=left \
-a toclevels=$HTML_TOCLev \
-a reproducible \
-a docinfo=shared-head \
-a source-highlighter=highlight \
--require ../assets/adoc/highlight-treeprocessor_mod.rb \
--template-dir ../assets/adoc/haml \
--destination-dir $HTML_outDir \
-o $HTML_output \
$source || {
printBuildFailed
exit 1
}
printBuildPassed
# 2. Copy HTML Book to "docs/"
# ============================
printHeading1 "Deploy HTML Book to GitHub Pages Folder"
echo -e "\033[37;1mCopying the built HTML document to: \033[33;1m$WWW\033[0m"
printSeparator
echo -en "\033[31;1m"
cp "$HTML_outDir/$HTML_output" $WWW || {
printBuildFailed
exit 1
}
printBuildPassed
# 3. Build AsciiDoc Preprocessed Document
# =======================================
printHeading1 "Hugo Book: Build Standalone AsciiDoc Document"
echo -e "\033[37;1mPreprocessing to single-file AsciiDoc document: \033[33;1m$ADoc_output\033[0m"
# (pipe coalescer output to SED to strip "// EOF //" lines)
coalescerLog=$(mktemp)
ruby ../assets/adoc/asciidoc-coalescer.rb \
-a coalescer \
$source 2> $coalescerLog | sed -e '/^\/\/ EOF \/\/$/d' > $ADoc_output
result=$(<$coalescerLog)
if [ -n "$result" ]
then # if $result contains any text conversion failed:
printSeparator
echo -en "\033[31;1m"
cat $coalescerLog
printBuildFailed
rm $coalescerLog
exit 1
fi
printBuildPassed
rm $coalescerLog
# Post-Processing Fixes
# ---------------------
# Restore final "// EOF //" & guarantee empty line for EditorConfig compliance:
echo -e "\n// EOF //" >> $ADoc_output
# If running under Windows OS normalize EOLs to CRLF:
if [[ $(uname -s) == MINGW* ]];then
unix2dos $ADoc_output
fi
# 4. Tests AsciiDoc Preprocessed Document
# =======================================
# Run a quick conversion of the new coalesced doc to ensure that it builds
# without errors. The main goal is to check that it can locate images correctly,
# via the embedded `imagesdir` attribute, for the benefit of previewing on
# GitHub WebUI. No need to use the syntax highlighter for this test.
# Asciidoctor output is sent to STDOUT and redirected to /dev/null.
printHeading1 "Hugo Book: Tests Standalone AsciiDoc Document"
echo -e "\033[37;1mTesting HTML5 conversion of single-file AsciiDoc document: \033[33;1m$ADoc_output\033[0m"
# We'll need to test conversion from the project root:
cd ../
testSrc=${ADoc_output#../}
printSeparator
echo -e "\033[30;1m\c"
asciidoctor \
--failure-level WARN \
--timings \
--verbose \
--safe-mode unsafe \
-a data-uri \
-a experimental \
-o - \
$testSrc >/dev/null || {
printBuildFailed
exit 1
}
printBuildPassed
exit
# EOF #