blob: c18af74db41a37fd28eaf1ed1f048507e7ccba52 (
plain) (
blame)
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
|
#!/bin/sh
set -e -a
: ${SRC:=$PWD/src}
: ${DST:=./website}
: ${URL:=https://syndamia.com}
: ${AWK:="mawk"}
condition() {
if [ -z "$FORCE_GEN" ] \
&& [ -d "$DST" ] \
&& [ -f "$DST/.commit" ] \
&& command -v git >/dev/null 2>&1 \
&& [ -z "$(git status -s)" ] \
&& [ "$(cat "$DST"/.commit)" = "$(git rev-parse HEAD)" ]
then
echo "Output '$DST' is up to date with website source '$SRC'!"
exit 0
fi
}
patch() {
while read -r folder
do
if [ -f "$folder.du" ] && [ ! "$folder.du" -ef "$folder/index.du" ]
then
rm "$folder/index.du" >/dev/null 2>&1
ln "$folder.du" "$folder/index.du"
fi
done << EOF
$(find "$SRC" -maxdepth 1 -type d)
EOF
if [ ! "src/favicon.ico" -ef "src/img/favicon.ico" ]
then
rm "src/favicon.ico" >/dev/null 2>&1
ln "src/img/favicon.ico" "src/favicon.ico"
fi
}
prepare() {
mkdir -p "$DST"
rm -r "$DST"/* 2>/dev/null || true
cp -a "$SRC/." "$DST"
rm "$DST/INIT.du"
}
build() {
"$AWK" \
-f ./dunbar/dunbar_awk/dunbar.awk \
./dunbar/stdenv/lang/html.du ./dunbar/stdenv/code.du \
-c "$SRC/INIT.du" \
$(find "$DST" -type f -name '*.du')
date '+%e.%m.%Y %H:%M:%S %Z' > "$DST"/.build
if command -v git >/dev/null 2>&1
then
git rev-parse HEAD > "$DST"/.commit
fi
}
build_sitemap() {
cat <<SITEMAP >"$DST"/sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
$("$AWK" -v date="$(date +%Y-%m-%d)" '
{
URL = ENVIRON["URL"] substr($0, length(ENVIRON["DST"]) + 1)
print "<url><loc>" URL "</loc><lastmod>" date "</lastmod><priority>1.0</priority></url>"
}
' <<FILES
$(find "$DST" -type f -name '*.html')
FILES
)
</urlset>
SITEMAP
}
build_tiny() {
mkdir -p "$DST.tiny"
rm -r "$DST.tiny"/* 2>/dev/null || true
cp -a "$DST/." "$DST.tiny"
rm -rf "$DST.tiny"/*.css "$DST.tiny"/fonts/
sed -i \
-e '/rel="stylesheet"/d' \
-e '/<script/d' \
-e '/id="settingsWrapper"/,/<\/nav>/d' \
-e '/id="scrollBtn"/d' \
$(find "$DST.tiny" -type f -name "*.html")
}
fixup_local() {
while read -r f
do
root="$(echo "$f" | sed 's|^./website\(.*\)/.*.html$|./\1/|g;s|[^/.]\+|..|g;s|//|/|g;s|\.\.\.\+|..|g')"
sed -i 's \(\(href\|src\)="[^"]*/[^"./]*\)" \1/index.html" g;s \(\(href\|src\)="\)/ \1'"$root"' g;s \(\(href\|src\)="\([^/"][^/"]\|/[^/]\)*[^/"]\?\)/\+ \1/ g' "$f"
done <<EOF
$(find "$DST" -type f -name '*.html')
EOF
}
#---#
[ -z "$1" ] && set prod
stages=''
C=0
for arg in "$@"
do
case "$arg" in
(*=*)
eval "$arg"
;;
(common)
stages="$stages condition patch prepare build"
: $((C = C + 4))
;;
(local)
stages="$stages condition patch prepare build build_sitemap fixup_local"
: $((C = C + 6))
;;
(prod)
stages="$stages condition patch prepare build build_sitemap build_tiny"
: $((C = C + 6))
;;
(*)
stages="$stages $arg"
: $((C = C + 1))
esac
done
N=1
for stage in $stages
do
printf "[%d/%d] %s\n" "$N" "$C" "$stage"
if "$stage"
then
: $((N = N + 1))
else
exit $?
fi
done
|