116 lines
2.0 KiB
Bash
Executable File
116 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Builds the website.
|
|
#
|
|
|
|
extract () {
|
|
files=""
|
|
directories=""
|
|
paths=""
|
|
|
|
while read -r line; do
|
|
fn="${line##*/}"
|
|
dr="${line%%$fn}"
|
|
dr="${dr##./src/}"
|
|
fn="${fn%%'.md'}"
|
|
files="${files}${fn}
|
|
"
|
|
directories="${directories}${dr}
|
|
"
|
|
paths="${paths}${dr}${fn}
|
|
"
|
|
done
|
|
case "$1" in
|
|
"d")
|
|
printf "$directories" ;;
|
|
"f")
|
|
printf "$files" ;;
|
|
"p")
|
|
printf "$paths" ;;
|
|
esac
|
|
}
|
|
|
|
mk_templates () {
|
|
paths=$( find ./src/ -type f -name "*.md" )
|
|
printf "$paths\n" | extract d | {
|
|
while read -r line; do
|
|
mkdir -p "./out/$line"
|
|
done
|
|
}
|
|
|
|
printf "$paths\n" | extract p | {
|
|
while read -r line; do
|
|
cat header.html > ./out/$line.html
|
|
markdown2 ./src/$line.md >> ./out/$line.html
|
|
cat footer.html >> ./out/$line.html
|
|
done
|
|
}
|
|
}
|
|
|
|
cp_static () {
|
|
cp -r ./static/* ./out/
|
|
}
|
|
|
|
eee () {
|
|
paths=$( find ./src/ -type f -name "*.md" )
|
|
printf "$paths\n"
|
|
printf "$paths\n" | extract p
|
|
}
|
|
|
|
usage () {
|
|
cat << EOF
|
|
Usage: buildsite [CWD] [OPTIONS]...
|
|
|
|
Options:
|
|
-s only copy static files
|
|
-m only render markdown
|
|
-h display this epic usage message
|
|
|
|
CWD is the root where all files are stored.
|
|
EOF
|
|
}
|
|
|
|
main () {
|
|
todo="a"
|
|
cwd=""
|
|
while [ "$1" != "" ]; do
|
|
case "$1" in
|
|
"-s")
|
|
todo="s" ;;
|
|
"-m")
|
|
todo="m" ;;
|
|
"-h")
|
|
usage
|
|
exit 0 ;;
|
|
*)
|
|
if [ -z "$cwd" ]; then
|
|
cwd="$1"
|
|
else
|
|
usage
|
|
exit 1
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
shift 1
|
|
done
|
|
|
|
[ -z "$cwd" ] || cd $cwd
|
|
case "$todo" in
|
|
"a")
|
|
rm -rf ./out
|
|
|
|
mk_templates
|
|
cp_static
|
|
;;
|
|
"s")
|
|
cp_static
|
|
;;
|
|
"m")
|
|
mk_templates
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main $@
|