site-neo/render.sh

135 lines
2.5 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.
# v3.5-p0
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
2023-02-17 08:13:52 -05:00
function inf { 1>&2 echo -e "\x1B[1;32mINF\x1B[0m: $*"; }
function wrn { 1>&2 echo -e "\x1B[1;93mWRN\x1B[0m: $*"; }
function err { 1>&2 echo -e "\x1B[1;31mERR\x1B[0m: $*"; }
function dirs {
2023-02-11 17:26:39 -05:00
if test -d out; then
wrn "Directory 'out' already exists."
return 0
fi
local i o dir
dir=(`./pfiles.rb dir`)
inf "Creating directory structure..."
echo ${dir[@]}
for i in ${dir[@]}; do
o="${i/in/out}"
mkdir -pv $o
done
}
function docs {
2023-02-18 16:12:37 -05:00
load_title
2023-02-11 17:26:39 -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 doc
doc=(`./pfiles.rb doc`)
inf "Rendering document files..."
for i in ${doc[@]}; do
o="${i/in/out}"
2023-02-18 18:45:41 -05:00
o="${o%.*}.html"
echo "'$i' -> '$o'"
2023-02-11 17:26:39 -05:00
if test -z "${title[$i]}"; then
2023-02-18 18:45:41 -05:00
m4 -D_INFILE="$i" -DCSSI=$(awk -f awk/getsd.awk <<< "$i") m4/main.html.m4 > $o
2023-02-11 17:26:39 -05:00
else
2023-02-18 18:45:41 -05:00
m4 -D_INFILE="$i" -DCSSI=$(awk -f awk/getsd.awk <<< "$i") -DTITLE="${title[$i]}" m4/main.html.m4 > $o
2023-02-11 17:26:39 -05:00
fi
done
}
function sass {
2023-02-11 17:26:39 -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
sass=(`./pfiles.rb sass`)
inf "Rendering sass files..."
if [ ${#sass[@]} -eq 0 ]; then
inf "No .sass files detected, skipping"
return 0
else
for i in ${sass[@]}; do
o="${i/in/out}"
o="${o/.s[ac]/.c}"
echo "'$i' -> '$o'"
2023-02-17 13:17:33 -05:00
sassc -t expanded -a $i | sed '/^$/d' > $o
2023-02-11 17:26:39 -05:00
done
fi
}
function other {
local other=`./pfiles.rb rest`
for i in $other; do
ln -v $i ${i/in/out}
done
}
2023-02-18 20:18:26 -05:00
function sitemap {
./gensimap.sh
}
function all {
2023-02-18 16:12:37 -05:00
load_title
2023-02-11 17:26:39 -05:00
dirs
docs
sass
other
}
2023-02-10 14:02:43 -05:00
function info {
2023-02-18 16:12:37 -05:00
load_title
2023-02-11 17:26:39 -05:00
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
2023-02-10 14:02:43 -05:00
}
2023-02-18 16:12:37 -05:00
function load_title {
local ii
while read -r ii; do
csv -a i "$ii"
title[in/${i[0]}]=${i[1]}
done < dat/title.csv
}
2023-02-10 14:02:43 -05:00
#E: Definition
#B: Logic
#B: Logic/LoadDefs
#B: Logic/LoadDefs/ignore
if test -f ignore.txt; then
2023-02-11 17:26:39 -05:00
while read -r i; do
ignore+=(in/$i)
2023-02-17 13:17:33 -05:00
done < dat/ignore.txt
2023-02-10 14:02:43 -05:00
fi
#E: Logic/LoadDefs/ignore
#E: Logic/LoadDefs
if test -z "$*"; then
2023-02-11 17:26:39 -05:00
all
exit $?
fi
case $1 in
2023-02-17 08:13:52 -05:00
dir) dirs;;
doc) docs;;
2023-02-18 16:12:37 -05:00
docs) docs;;
2023-02-17 08:13:52 -05:00
s[ac]ss) sass;;
other) dirs; other;;
2023-02-17 08:13:52 -05:00
rest) other;;
info) info;;
2023-02-18 20:18:26 -05:00
sitemap) sitemap;;
2023-02-17 08:13:52 -05:00
vall) info; all;;
all) all;;
*) all;;
esac
2023-02-10 14:02:43 -05:00
#E: Logic
exit $?