-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_html.sh
More file actions
executable file
·50 lines (44 loc) · 1.72 KB
/
generate_html.sh
File metadata and controls
executable file
·50 lines (44 loc) · 1.72 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
#!/bin/bash
# Generate html files from a markdown files in docs directory in the web directory
CSS_HEADER='<link rel="stylesheet" href="https:\/\/www\.w3schools\.com\/w3css\/4\/w3\.css">'
# validate src directory exists
if [ ! -d "guide" ]; then
echo "Error: guide directory does not exist"
exit 1
fi
rm -rf docs
echo "Generating HTML files"
echo "---------------------"
# make sure web directory exists
mkdir -p docs
# Read the files in guide directory
for src_file in guide/*/*.md; do
# create directory in web directory without the guide directory
dir=$(dirname "${src_file#guide/}")
# remove md extension from filename
dest_file="${src_file%.md}"
# create directory
mkdir -p "docs/$dir"
# extrect the header from the markdown file
header=$(head -n 1 "$src_file")
# remove #, * from the header
header=$(echo "$header" | sed 's/#//g' | sed 's/\*//g')
# remove prefix and suffix spaces
header=$(echo "$header" | sed 's/^[ \t]*//;s/[ \t]*$//')
# print what is being generated
echo "Generating $header using $src_file"
# convert to html
pandoc "$src_file" -f markdown -t slidy -so "docs/${dest_file#guide/}.html" --quiet
done
# convert README.md to index.html basic html
pandoc README.md -f markdown -t html -o docs/index.html
# replace links to html files and update from src to web directory
sed -i 's/\.md/\.html/g' docs/index.html
# remove guide directory from links
sed -i 's/guide\///g' docs/index.html
# remove any line in index.html that contains the char 🔗
sed -i '/🔗/d' docs/index.html
# prefix css header to index.html
sed -i "1s/^/${CSS_HEADER}\n/" docs/index.html
# update images paths releative one level up
sed -i 's/src="image/src="\.\.\/image/g' docs/index.html