sebastiano.tronto.net

Source files and build scripts for my personal website
git clone https://git.tronto.net/sebastiano.tronto.net
Download | Log | Files | Refs | README

gen.sh (1169B)


      1 #!/bin/sh
      2 
      3 invert() {
      4 	# To invert an alg, replace R2 with RR, B' with B3 and then BBB
      5 	# and similar. Then reverse the string and triple every letter.
      6 	# It's a ugly hack, but it works.
      7 	alg="$(echo "$1" | tr -d ' ' | tr \' 3)"
      8 	echo "$alg" | sed -E 's/(.)(3)/\1\1\1/g' | \
      9 		sed -E 's/(.)(2)/\1\1/g' | sed 's/./&&&/g' | rev
     10 }
     11 
     12 gen() {
     13 	[ -e "trigger_$1.png" ] || cubeviz trigger "$1" > /dev/null 2>&1
     14 }
     15 
     16 printitem() {
     17 	alg="$1"
     18 	if [ -n "$alg" ]; then
     19 		inv="$(invert "$alg")"
     20 		echo "Working on alg $alg with inverse $inv" 1>&2
     21 		gen "$inv"
     22 		printf '<td style="font-size:16pt; text-align:center" '
     23 		printf 'width="20%%">%s</td>\n' "$alg"
     24 		printf '<td><a href="trigger_%s.png">\n' "$inv"
     25 		printf '<img src="trigger_%s.png" ' "$inv"
     26 		printf 'style="height:100px"></a></td>\n'
     27 	else
     28 		printf '<td width="20%%"><td width="30%%">\n'
     29 	fi
     30 }
     31 
     32 maketable() {
     33 	alg1="$(echo "$1" | sed 's/;.*$//' | tr -d '!')"
     34 	alg2="$(echo "$1" | sed 's/.*;//')"
     35 	printf '<table><tr>\n'
     36 	printitem "$alg1"
     37 	printitem "$alg2"
     38 	printf '</tr></table>\n'
     39 }
     40 
     41 while read -r line; do
     42 	algs="$(echo "$line" | grep '^!')"
     43 	if [ -z "$algs" ]; then
     44 		echo "$line"
     45 	else
     46 		maketable "$line"
     47 	fi
     48 done