-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·55 lines (45 loc) · 1.14 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·55 lines (45 loc) · 1.14 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
#!/bin/bash
set -e
SAVEIFS=$IFS
IFS=`echo -en "\n\b"`
host="$1"
[ ! -f template.html ] && cat > template.html << EOL
<!DOCTYPE html>
<html>
<head>
<title>%s</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<main>%s</main>
</body>
</html>
EOL
rm -rf dist
mkdir -p src dist
# https://askubuntu.com/a/295312
urlencode() {
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c"
esac
done
}
[ "`ls -A src`" ] && for path in ./src/* ; do
file=`basename $path`
title="${file%%.*}"
if [[ $file == *.html ]] ; then
echo "$host/`urlencode $title`" >> "dist/sitemap.txt"
printf "`cat template.html`" "$title" "`cat src/$file`" > "dist/$file"
elif [[ $file == *.md ]] ; then
echo "$host/`urlencode $title`" >> "dist/sitemap.txt"
printf "`cat template.html`" "$title" "`pandoc -f markdown -t html src/$file`" > "dist/$title.html"
else
echo "$host/`urlencode $file`" >> "dist/sitemap.txt"
cp "src/$file" "dist/$file"
fi
done