site-neo/render.sh

73 lines
1.8 KiB
Bash
Raw Normal View History

2022-09-24 22:07:46 +00:00
#!/bin/bash
2022-10-04 21:42:16 +00:00
# render.sh: part of the tape-and-string framework.
2023-02-07 04:00:03 +00:00
# v3.0
. titles.sh
function inf { echo -e "\x1B[1;32mINF\x1B[0m: $*"; }
function wrn { echo -e "\x1B[1;93mWRN\x1B[0m: $*"; }
function err { echo -e "\x1B[1;31mERR\x1B[0m: $*"; }
2023-02-01 17:59:45 +00:00
function tape {
2023-02-07 04:00:03 +00:00
if test -d "$1"; then
err "tape: Passed directory, $1"
return 1
fi
2023-02-01 17:59:45 +00:00
case $1 in
2023-02-07 04:00:03 +00:00
*.txti) redcloth "$1" ;;
*.org) org-ruby --translate html "$1" ;;
*.md) comrak --gfm "$1" ;;
2023-02-01 17:59:45 +00:00
*.html) cat $1 ;;
2023-02-07 04:00:03 +00:00
*) pandoc --columns 168 -t html "$1" || echo "Skipping $i, unknown format" ;;
2023-02-01 17:59:45 +00:00
esac
}
2023-02-05 11:47:27 +00:00
function yn {
while true; do
read -p "$* [y/n]:" yn
case $yn in
[Yy]*) return 0;;
[Nn]*)
echo "Aborted."
return 1;;
*) echo "Please answer Yes or No.";;
esac
done
}
2023-02-07 04:00:03 +00:00
doc=(`find . -wholename './.hg' -prune , -type f -name '*.txti' -o -name '*.org' -o -name '*.md'`)
2023-02-07 03:09:21 +00:00
sass=(`find . -wholename './.hg' -prune , -type f -name '*.sass'`)
scss=(`find . -wholename './.hg' -prune , -type f -name '*.scss'`)
2023-02-07 04:00:03 +00:00
rest=(`find . -wholename './.hg' -prune , -type f ! \( -name '*.org' -o -name '*.txti' -o -name '*.md' -o -name .hg \)`)
2023-02-07 03:09:21 +00:00
dir=(`find . -wholename './.hg' -prune , -type d -not -name .hg`)
2023-02-05 11:47:27 +00:00
2023-02-07 03:09:21 +00:00
inf "Creating directory structure..."
for i in ${dir[@]}; do
2023-02-01 17:59:45 +00:00
echo $i
2023-02-07 03:09:21 +00:00
mkdir -p out/$i
done
inf "Rendering document files..."
2023-02-07 04:00:03 +00:00
for i in ${doc[@]}; do
2023-02-07 03:09:21 +00:00
echo $i
2023-02-07 04:00:03 +00:00
tape $i | m4 -DTITLE="${title[$i]}" main.html.m4 > out/${i%.*}.html
2023-02-07 03:09:21 +00:00
done
inf "Rendering sass files..."
if test -z "${sass[@]}"; then
inf "No .sass files detected, skipping"
unset sass
else
for i in ${sass[@]}; do
echo $i
sassc -a $i out/$i
done
fi
if test -z "${scss[@]}"; then
inf "No .scss files detected, skipping."
unset scss
else
for i in ${scss[@]}; do
echo $i
sassc $i out/$i
done
fi
inf "Copying other files..."
# Probably a more efficient way to do this.
for i in ${rest[@]}; do
cp -v $i out/$i
2022-09-24 22:07:46 +00:00
done