2022-09-24 18:07:46 -04:00
|
|
|
#!/bin/bash
|
2022-10-04 17:42:16 -04:00
|
|
|
# render.sh: part of the tape-and-string framework.
|
2023-02-06 23:00:03 -05:00
|
|
|
# v3.0
|
2023-02-08 12:17:45 -05:00
|
|
|
enable -f /usr/lib/bash/csv csv
|
|
|
|
declare -A title
|
|
|
|
while read -r ii; do
|
|
|
|
csv -a i "$ii"
|
|
|
|
title[in/${i[0]}]=${i[1]}
|
|
|
|
done <title.csv
|
2023-02-06 23:00:03 -05:00
|
|
|
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 12:59:45 -05:00
|
|
|
function tape {
|
2023-02-06 23:00:03 -05:00
|
|
|
if test -d "$1"; then
|
|
|
|
err "tape: Passed directory, $1"
|
|
|
|
return 1
|
|
|
|
fi
|
2023-02-01 12:59:45 -05:00
|
|
|
case $1 in
|
2023-02-06 23:00:03 -05:00
|
|
|
*.txti) redcloth "$1" ;;
|
|
|
|
*.org) org-ruby --translate html "$1" ;;
|
|
|
|
*.md) comrak --gfm "$1" ;;
|
2023-02-01 12:59:45 -05:00
|
|
|
*.html) cat $1 ;;
|
2023-02-06 23:00:03 -05:00
|
|
|
*) pandoc --columns 168 -t html "$1" || echo "Skipping $i, unknown format" ;;
|
2023-02-01 12:59:45 -05:00
|
|
|
esac
|
|
|
|
}
|
2023-02-05 06:47:27 -05: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-08 12:17:45 -05:00
|
|
|
doc=(`find in -type f -name '*.txti' -o -name '*.org' -o -name '*.md'`)
|
|
|
|
sass=(`find in -type f -name '*.sass'`)
|
|
|
|
scss=(`find in -type f -name '*.scss'`)
|
|
|
|
rest=(`find in -type f ! \( -name '*.org' -o -name '*.txti' -o -name '*.md' -o -name .hg \)`)
|
|
|
|
dir=(`find in -type d`)
|
2023-02-05 06:47:27 -05:00
|
|
|
|
2023-02-06 22:09:21 -05:00
|
|
|
inf "Creating directory structure..."
|
2023-02-08 12:17:45 -05:00
|
|
|
echo ${dir[@]}
|
2023-02-06 22:09:21 -05:00
|
|
|
for i in ${dir[@]}; do
|
2023-02-08 12:17:45 -05:00
|
|
|
o="${i/in/out}"
|
|
|
|
mkdir -pv $o
|
2023-02-06 22:09:21 -05:00
|
|
|
done
|
|
|
|
inf "Rendering document files..."
|
2023-02-06 23:00:03 -05:00
|
|
|
for i in ${doc[@]}; do
|
2023-02-08 12:17:45 -05:00
|
|
|
o="${i/in/out}"
|
|
|
|
echo "$i => $o"
|
|
|
|
if test -z "${title[$i]}"; then
|
|
|
|
tape $i | m4 main.html.m4 > ${o%.*}.html
|
|
|
|
else
|
|
|
|
tape $i | m4 -DTITLE="${title[$i]}" main.html.m4 > ${o%.*}.html
|
|
|
|
fi
|
2023-02-06 22:09:21 -05: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
|
2023-02-08 12:17:45 -05:00
|
|
|
o="${i/in/out}"
|
|
|
|
echo "$i => $o"
|
|
|
|
sassc -a $i $o
|
2023-02-06 22:09:21 -05:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
if test -z "${scss[@]}"; then
|
|
|
|
inf "No .scss files detected, skipping."
|
|
|
|
unset scss
|
|
|
|
else
|
|
|
|
for i in ${scss[@]}; do
|
2023-02-08 12:17:45 -05:00
|
|
|
o="${i/in/out}"
|
|
|
|
echo "$i => $o"
|
|
|
|
sassc $i $o
|
2023-02-06 22:09:21 -05:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
inf "Copying other files..."
|
2023-02-08 12:17:45 -05:00
|
|
|
cp -rv 'in'/* out/
|