site-neo/render.sh

133 lines
2.6 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-12-06 15:30:50 +00:00
#V:3.6-r2
2023-02-10 19:02:43 +00:00
#B: Load
2023-02-08 17:17:45 +00:00
enable -f /usr/lib/bash/csv csv
declare -A title
2023-02-10 19:02:43 +00:00
#E: Load
#B: Definition
2023-12-06 15:30:50 +00:00
#B: Definition/Ampelstatus
2023-02-17 13:13:52 +00: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: $*"; }
2023-12-06 15:30:50 +00:00
#E: Defintion/Ampelstatus
function dirs {
2023-02-11 22:26:39 +00:00
if test -d out; then
wrn "Directory 'out' already exists."
fi
2023-12-06 15:30:50 +00:00
local i o dir odir
2023-02-11 22:26:39 +00:00
dir=(`./pfiles.rb dir`)
2023-12-06 15:30:50 +00:00
inf "\x1B[1m[dirs]\x1B[0m Creating directory structure..."
2023-02-11 22:26:39 +00:00
echo ${dir[@]}
for i in ${dir[@]}; do
2023-12-06 15:30:50 +00:00
odir+="${i/in/out} "
2023-02-11 22:26:39 +00:00
done
2023-12-06 15:30:50 +00:00
mkdir -pv $odir
}
function docs {
2023-02-18 21:12:37 +00:00
load_title
2023-02-11 22:26:39 +00: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`)
2023-12-06 15:30:50 +00:00
inf "\x1B[1m[docs]\x1B[0m Rendering document files..."
2023-02-11 22:26:39 +00:00
for i in ${doc[@]}; do
o="${i/in/out}"
2023-02-18 23:45:41 +00:00
o="${o%.*}.html"
echo "'$i' -> '$o'"
2023-02-11 22:26:39 +00:00
if test -z "${title[$i]}"; then
2023-02-18 23:45:41 +00:00
m4 -D_INFILE="$i" -DCSSI=$(awk -f awk/getsd.awk <<< "$i") m4/main.html.m4 > $o
2023-02-11 22:26:39 +00:00
else
2023-02-18 23:45:41 +00:00
m4 -D_INFILE="$i" -DCSSI=$(awk -f awk/getsd.awk <<< "$i") -DTITLE="${title[$i]}" m4/main.html.m4 > $o
2023-02-11 22:26:39 +00:00
fi
done
}
function sassfn {
2023-02-11 22:26:39 +00:00
if ! test -d out; then
err "Cannot render, directory 'out' does not exist, run ./render.sh dir"
exit 1
2023-02-11 22:26:39 +00:00
fi
2023-12-06 15:30:50 +00:00
inf "\x1B[1m[sassfn]\x1B[0m Rendering sass files..."
sass --no-source-map in/css:out/css
}
function other {
2023-12-06 15:30:50 +00:00
inf "\x1B[1m[other]\x1B[0m Hardlinking other files..."
local i other=`./pfiles.rb rest`
for i in $other; do
2023-12-06 15:30:50 +00:00
local o=${i/in/out}
if test -f $o; then
inf "Skipping $i, file/hardlink exists..."
continue
fi
2023-12-06 15:30:50 +00:00
ln -v $i $o
done
}
function all {
2023-02-18 21:12:37 +00:00
load_title
2023-02-11 22:26:39 +00:00
dirs
docs
sass
other
}
2023-02-10 19:02:43 +00:00
function info {
2023-02-18 21:12:37 +00:00
load_title
2023-02-11 22:26:39 +00: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 19:02:43 +00:00
}
2023-02-18 21:12:37 +00: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 19:02:43 +00:00
#E: Definition
#B: Logic
#B: Logic/LoadDefs
#B: Logic/LoadDefs/ignore
if test -f ignore.txt; then
2023-02-11 22:26:39 +00:00
while read -r i; do
ignore+=(in/$i)
2023-02-17 18:17:33 +00:00
done < dat/ignore.txt
2023-02-10 19:02:43 +00:00
fi
#E: Logic/LoadDefs/ignore
#E: Logic/LoadDefs
if test -z "$*"; then
2023-02-11 22:26:39 +00:00
all
exit $?
fi
case $1 in
2023-02-17 13:13:52 +00:00
dir) dirs;;
2023-12-06 15:30:50 +00:00
dirs) dirs;;
2023-02-17 13:13:52 +00:00
doc) docs;;
2023-02-18 21:12:37 +00:00
docs) docs;;
s[ac]ss) sassfn;;
other) dirs; other;;
2023-02-17 13:13:52 +00:00
rest) other;;
info) info;;
2023-12-06 15:30:50 +00:00
sitemap) ./sitemap.sh;;
2023-02-17 13:13:52 +00:00
vall) info; all;;
all) all;;
2023-12-06 15:30:50 +00:00
clean) rm -rf out;;
*)
inf "Removing out..."
err "Unknown value, $1."
exit 1
;;
esac
2023-02-10 19:02:43 +00:00
#E: Logic
exit $?