site-neo/render.sh

161 lines
3.2 KiB
Bash
Raw Normal View History

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-11 11:22:16 -05:00
# v3.3-p1
2023-02-10 14:02:43 -05:00
#B: Load
2023-02-08 12:17:45 -05:00
enable -f /usr/lib/bash/csv csv
declare -A title
2023-02-10 14:02:43 -05:00
#E: Load
#B: Definition
function in_arr {
for i in "${@:2}"; do
[[ "$i" = "$1" ]] && return 0
done
return 1
}
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
2023-02-10 14:02:43 -05:00
err "tape: Passed directory, $1"
return 1
2023-02-06 23:00:03 -05:00
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-11 09:08:06 -05:00
*.s[ac]ss) err "Told to render $1, shouldn't happen"; return 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
}
function dirs {
2023-02-10 14:02:43 -05:00
if test -d out; then
wrn "Directory 'out' already exists."
return 0
fi
local i o dir
2023-02-11 09:08:06 -05:00
dir=(`./pfiles.rb dir`)
2023-02-10 14:02:43 -05:00
inf "Creating directory structure..."
echo ${dir[@]}
for i in ${dir[@]}; do
o="${i/in/out}"
mkdir -pv $o
done
}
function docs {
2023-02-10 14:02:43 -05:00
if ! test -d out; then
err "Cannot render, directory 'out' does not exist, run ./render.sh dir"
return 1
2023-02-08 12:17:45 -05:00
fi
2023-02-10 14:02:43 -05:00
local i o doc
2023-02-11 09:08:06 -05:00
doc=(`./pfiles.rb doc`)
2023-02-10 14:02:43 -05:00
inf "Rendering document files..."
for i in ${doc[@]}; do
o="${i/in/out}"
echo "$i => $o"
if test -z "${title[$i]}"; then
2023-02-11 11:22:16 -05:00
tape $i | m4 -DCSS_INC=$(awk -f get_sd.awk "$i") m4/main.html.m4 > ${o%.*}.html
2023-02-10 14:02:43 -05:00
else
2023-02-11 11:22:16 -05:00
tape $i | m4 -DCSS_INC=$(awk -f get_sd.awk "$i") -DTITLE="${title[$i]}" m4/main.html.m4 > ${o%.*}.html
2023-02-10 14:02:43 -05:00
fi
done
}
function sass {
2023-02-10 14:02:43 -05:00
if ! test -d out; then
err "Cannot render, directory 'out' does not exist, run ./render.sh dir"
return 1
fi
local i o sass scss
2023-02-11 09:08:06 -05:00
sass=(`./pfiles.rb sass`)
scss=(`./pfiles.rb scss`)
2023-02-10 14:02:43 -05:00
inf "Rendering sass files..."
if [ ${#sass[@]} -eq 0 ]; then
inf "No .sass files detected, skipping"
unset sass
else
for i in ${sass[@]}; do
o="${i/in/out}"
o="${o/.sa/.c}"
echo "$i => $o"
sassc -a $i $o
done
fi
if [ ${#scss[@]} -eq 0 ]; then
inf "No .scss files detected, skipping."
unset scss
else
for i in ${scss[@]}; do
o="${i/in/out}"
o="${o/\.s/.}"
echo "$i => $o"
sassc $i $o
done
fi
}
function other {
2023-02-10 14:02:43 -05:00
if ! test -d out; then
err "Cannot render, directory 'out' does not exist, run ./render.sh dir"
return 1
fi
inf "Copying other files..."
cp -rv 'in'/* out/
}
function all {
2023-02-10 14:02:43 -05:00
dirs
docs
sass
other
}
2023-02-10 14:02:43 -05:00
function info {
local i
echo "* \$ignore"
if [ ${#ignore[@]} -eq 0 ]; then
echo null
else
for i in ${ignore[@]}; do
echo "- $i"
done
fi
echo "* \$titles"
for i in ${!title[@]}; do
echo " - $i :: ${title[$i]}"
done
}
#E: Definition
#B: Logic
#B: Logic/LoadDefs
#B: Logic/LoadDefs/title
while read -r ii; do
csv -a i "$ii"
title[in/${i[0]}]=${i[1]}
done < title.csv
#E: Logic/LoadDefs/title
unset ii
#B: Logic/LoadDefs/ignore
if test -f ignore.txt; then
while read -r i; do
ignore+=(in/$i)
done < ignore.txt
fi
#E: Logic/LoadDefs/ignore
#E: Logic/LoadDefs
if test -z "$*"; then
all
2023-02-10 14:02:43 -05:00
exit $?
fi
case $1 in
2023-02-10 14:02:43 -05:00
dir) dirs;;
doc) docs;;
s[ac]ss) sass;;
other) other;;
rest) other;;
info) info;;
vall) info; all;;
all) all;;
*) all;;
esac
2023-02-10 14:02:43 -05:00
#E: Logic
exit $?