-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.sh
More file actions
executable file
·91 lines (72 loc) · 1.9 KB
/
Copy pathgen.sh
File metadata and controls
executable file
·91 lines (72 loc) · 1.9 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
#!/bin/sh
RS=""
sources_root="$(dirname "$0")"
site_template="$sources_root/site.html.template"
cd "$sources_root" || exit 1
# Clean before we start
find "$sources_root" -type f -name '*.html' -delete
find "$sources_root" -type f -name 'sitemap*' -delete
if [ "$1" = "clean" ]
then
exit
fi
# Generate pages
{
find . -type f -name '*.md' >tmp
while IFS= read -r content
do
path="$(dirname "$content")"
TITLE="$(basename "$content" | cut -d '.' -f 1 | tr '-' ' ')"
postname="$(basename "$content" .md | tr '[:upper:]' '[:lower:]')"
case "$postname" in
*.index) dest=index.html ;;
*) filename="$(echo "$postname" | rev | cut -d '.' -f 1 | rev)"
mkdir -p "$path/$filename"
dest="$filename/index.html" ;;
esac
CONTENT="$(pandoc --from commonmark --to html5 "$content")"
ROOT="$(dirname "$path/$dest" | sed -E 's/\/[^\/]+/\/../g')"
SOURCE="/edit/core/$(echo "$content" | sed -E 's/^\.\///')"
export TITLE
export CONTENT
export ROOT
export SOURCE
envsubst \
<"$site_template" \
>"$path/$dest"
echo "$(echo "$dest" | sed 's/index\.html$//')$RS$TITLE" >> "$path/sitemap"
done <tmp
rm tmp
}
# Generate page lists
{
find . -type f -name sitemap >tmp
while IFS= read -r list
do
path="$(dirname "$list")"
dest=index.html
if [ -f "$path/$dest" ]
then
dest=sitemap.html
fi
if [ -f "$path/.title" ]
then
things="$(cat "$path/.title")"
else
things=Things
fi
TITLE="Nobody Uses these $things"
CONTENT="<ul>$(sort "$list" | awk -F "$RS" 'NF { print("<li><a href=\"./"$1"\">"$2"</a></li>") }')</ul>"
ROOT="$(dirname "$path/$dest" | sed -E 's/\/[^\/]+/\/../g')"
SOURCE=""
export TITLE
export CONTENT
export ROOT
export SOURCE
envsubst \
<"$site_template" \
>"$path/$dest"
rm "$list"
done <tmp
rm tmp
}