-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.sh
executable file
·64 lines (58 loc) · 1.56 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
author='Wang Heng'
email='[email protected]'
homepage='https://eastack.me'
compile() {
echo compiling "$1" ...
asciidoctor "$1" \
--source-dir=asciidoc \
--destination-dir=public \
--attribute=favicon=/favicon.ico \
--attribute=lang=zh-Hans \
--attribute=source-highlighter=rouge \
--attribute=icons=font \
--attribute=toc=left@ \
--attribute=toc-title=目录 \
--attribute=docinfo=shared \
--attribute=nofooter \
--attribute=linkcss \
--attribute=stylesdir=.asciidoctor \
--attribute=copycss \
--attribute=author="$author" \
--attribute=email="$email" \
--require asciidoctor-diagram \
--require asciidoctor-mathematical
rm -rf \?
}
build() {
compile 'asciidoc/**/*.adoc'
find asciidoc/posts/publish -name '*.adoc' \
| sed 's/^asciidoc//;s/.adoc$$/.html/' \
| xargs -I {} echo '$(homepage){}' \
| cat - <(echo '$(homepage)') \
| cat - <(echo '$(homepage)/robots.txt') \
| cat - <(echo '$(homepage)/sitemap.txt') \
> static/sitemap.txt
cp -rT static public
}
serve() {
trap 'echo Asciidoctor server exited.' TERM INT
python3 -m http.server -d public &
echo 'Asciidoctor server starting...'
inotifywait -qmr -e 'modify' \
--format '%w%f%0' --no-newline \
--include '.*\.adoc$' asciidoc | \
while IFS= read -r -d '' file
do
compile $file
done &
wait $!
}
main() {
if [[ $1 == 'build' ]]; then
build
elif [[ $1 == 'serve' ]]; then
serve
fi
}
main "$@"