Reformat render.sh

This commit is contained in:
Atlas Cove 2023-02-11 22:26:39 +00:00
parent 483108408d
commit 6dd2694808

162
render.sh
View File

@ -10,121 +10,121 @@ function inf { echo -e "\x1B[1;32mINF\x1B[0m: $*"; }
function wrn { echo -e "\x1B[1;93mWRN\x1B[0m: $*"; } function wrn { echo -e "\x1B[1;93mWRN\x1B[0m: $*"; }
function err { echo -e "\x1B[1;31mERR\x1B[0m: $*"; } function err { echo -e "\x1B[1;31mERR\x1B[0m: $*"; }
function tape { function tape {
if test -d "$1"; then if test -d "$1"; then
err "tape: Passed directory, $1" err "tape: Passed directory, $1"
return 1 return 1
fi fi
case $1 in case $1 in
*.txti) redcloth "$1" ;; *.txti) redcloth "$1" ;;
*.org) org-ruby --translate html "$1" ;; *.org) org-ruby --translate html "$1" ;;
*.md) comrak --gfm "$1" ;; *.md) comrak --gfm "$1" ;;
*.html) cat $1 ;; *.html) cat $1 ;;
*.s[ac]ss) err "Told to render $1, shouldn't happen"; return 1 ;; *.s[ac]ss) err "Told to render $1, shouldn't happen"; return 1 ;;
*) pandoc --columns 168 -t html "$1" || echo "Skipping $i, unknown format" ;; *) pandoc --columns 168 -t html "$1" || echo "Skipping $i, unknown format" ;;
esac esac
} }
function dirs { function dirs {
if test -d out; then if test -d out; then
wrn "Directory 'out' already exists." wrn "Directory 'out' already exists."
return 0 return 0
fi fi
local i o dir local i o dir
dir=(`./pfiles.rb dir`) dir=(`./pfiles.rb dir`)
inf "Creating directory structure..." inf "Creating directory structure..."
echo ${dir[@]} echo ${dir[@]}
for i in ${dir[@]}; do for i in ${dir[@]}; do
o="${i/in/out}" o="${i/in/out}"
mkdir -pv $o mkdir -pv $o
done done
} }
function docs { function docs {
if ! test -d out; then if ! test -d out; then
err "Cannot render, directory 'out' does not exist, run ./render.sh dir" err "Cannot render, directory 'out' does not exist, run ./render.sh dir"
return 1 return 1
fi fi
local i o doc local i o doc
doc=(`./pfiles.rb doc`) doc=(`./pfiles.rb doc`)
inf "Rendering document files..." inf "Rendering document files..."
for i in ${doc[@]}; do for i in ${doc[@]}; do
o="${i/in/out}" o="${i/in/out}"
echo "$i => $o" echo "$i => $o"
if test -z "${title[$i]}"; then if test -z "${title[$i]}"; then
tape $i | m4 -DCSSI=$(awk -f get_sd.awk <<< "$i") m4/main.html.m4 > ${o%.*}.html tape $i | m4 -DCSSI=$(awk -f get_sd.awk <<< "$i") m4/main.html.m4 > ${o%.*}.html
else else
tape $i | m4 -DCSSI=$(awk -f get_sd.awk <<< "$i") -DTITLE="${title[$i]}" m4/main.html.m4 > ${o%.*}.html tape $i | m4 -DCSSI=$(awk -f get_sd.awk <<< "$i") -DTITLE="${title[$i]}" m4/main.html.m4 > ${o%.*}.html
fi fi
done done
} }
function sass { function sass {
if ! test -d out; then if ! test -d out; then
err "Cannot render, directory 'out' does not exist, run ./render.sh dir" err "Cannot render, directory 'out' does not exist, run ./render.sh dir"
return 1 return 1
fi fi
local i o sass local i o sass
sass=(`./pfiles.rb sass`) sass=(`./pfiles.rb sass`)
inf "Rendering sass files..." inf "Rendering sass files..."
if [ ${#sass[@]} -eq 0 ]; then if [ ${#sass[@]} -eq 0 ]; then
inf "No .sass files detected, skipping" inf "No .sass files detected, skipping"
return 0 return 0
else else
for i in ${sass[@]}; do for i in ${sass[@]}; do
o="${i/in/out}" o="${i/in/out}"
o="${o/.s[ac]/.c}" o="${o/.s[ac]/.c}"
echo "$i => $o" echo "$i => $o"
sassc -t expanded -a $i $o sassc -t expanded -a $i $o
done done
fi fi
} }
function other { function other {
if ! test -d out; then if ! test -d out; then
err "Cannot render, directory 'out' does not exist, run ./render.sh dir" err "Cannot render, directory 'out' does not exist, run ./render.sh dir"
return 1 return 1
fi fi
inf "Copying other files..." inf "Copying other files..."
cp -rv 'in'/* out/ cp -rv 'in'/* out/
} }
function all { function all {
dirs dirs
docs docs
sass sass
other other
} }
function info { function info {
local i local i
echo "* \$ignore" echo "* \$ignore"
if [ ${#ignore[@]} -eq 0 ]; then if [ ${#ignore[@]} -eq 0 ]; then
echo null echo null
else else
for i in ${ignore[@]}; do for i in ${ignore[@]}; do
echo "- $i" echo "- $i"
done done
fi fi
echo "* \$titles" echo "* \$titles"
for i in ${!title[@]}; do for i in ${!title[@]}; do
echo " - $i :: ${title[$i]}" echo " - $i :: ${title[$i]}"
done done
} }
#E: Definition #E: Definition
#B: Logic #B: Logic
#B: Logic/LoadDefs #B: Logic/LoadDefs
#B: Logic/LoadDefs/title #B: Logic/LoadDefs/title
while read -r ii; do while read -r ii; do
csv -a i "$ii" csv -a i "$ii"
title[in/${i[0]}]=${i[1]} title[in/${i[0]}]=${i[1]}
done < title.csv done < title.csv
#E: Logic/LoadDefs/title #E: Logic/LoadDefs/title
unset ii unset ii
#B: Logic/LoadDefs/ignore #B: Logic/LoadDefs/ignore
if test -f ignore.txt; then if test -f ignore.txt; then
while read -r i; do while read -r i; do
ignore+=(in/$i) ignore+=(in/$i)
done < ignore.txt done < ignore.txt
fi fi
#E: Logic/LoadDefs/ignore #E: Logic/LoadDefs/ignore
#E: Logic/LoadDefs #E: Logic/LoadDefs
if test -z "$*"; then if test -z "$*"; then
all all
exit $? exit $?
fi fi
case $1 in case $1 in
dir) dirs;; dir) dirs;;