-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.sh
executable file
·49 lines (33 loc) · 1.34 KB
/
generate.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
#!/bin/bash
# generate.sh
# Usage
#
DIR=$(dirname $(readlink -f $0))
source $DIR/scripts/util.sh
MESSAGE_DEBUG=1
# Required programs
dependencies=(pandoc)
message notify "generate-html.sh checking for necessary dependencies: $dependencies"
is-program-installed pandoc
message notify "MD files will be converted to HTML using pandoc..."
FILE_COUNT_HTML_GENERATED=0
# Create an array containing all .md files
mapfile -t md_files_array < <(find ./build/leadership ./build/technology ./build/html -type f -name "*.md")
FILE_COUNT_HTML_POSSIBLE=${#md_files_array[@]}
# Iterate over the array, checking each file for the pattern and updating if present
for md_file in "${md_files_array[@]}"; do
message debug "Found file: $md_file and will attempt to generate HTML..."
file_raw_name=$(basename "$md_file" .md)
file_html_name="${file_raw_name}.html"
file_dir=$(dirname "$md_file")
# Iterate over Markdown (.md) files and generate HTML
HEAD_HTML=$(cat ./src/html/template-header.html)
BODY_HTML=$(pandoc --from gfm --to html $md_file --no-highlight)
FOOT_HTML=$(cat ./src/html/template-footer.html)
# echo "$BODY_HTML"
DOCUMENT_HTML="${HEAD_HTML}${BODY_HTML}${FOOT_HTML}"
file_html="$file_dir/$file_html_name"
echo "$DOCUMENT_HTML" > $file_html
message debug "HTML generated and saved as: ${file_html}"
((FILE_COUNT_HTML_GENERATED+=1))
done