2020-10-23 23:08:10 +00:00
#!/bin/bash
# Auther: Skiqqy
HOST = "https://github.com/"
2021-04-22 21:59:42 +00:00
quote = true # True injects a qoute in hex
2021-04-22 20:50:01 +00:00
2021-04-22 21:59:42 +00:00
# Find a (WIP) qoute and transform to hex, replaceing newlines with \n
2021-04-22 20:50:01 +00:00
quote ( )
{
if " $quote "
then
res = $( printf 'C is quirky, flawed, and an enormous success.\n Dennis M. Ritchie' |
hexdump -e '8/1 " %02X" "\n"' )
printf '%s' " ${ res // $'\n' / \\ n } "
fi
}
2020-10-23 23:08:10 +00:00
conv ( ) {
# Take a file and convert it to html by making substitutes.
# ^/name -> https://github.com/name
# */name.domain -> https://name.domain
2020-10-25 17:03:21 +00:00
# !/name.domain -> http://name.domain
2021-04-04 21:10:20 +00:00
# a/name.domain/title/ -> <a href="name.domain">title</a>
2020-10-23 23:08:10 +00:00
sed -E " s|(\\^/)([^ \)]*)|^\/<a href= $HOST /\2>\2</a>|g " |
sed -E "s|(\\*/)([^ \)]*)|*\/<a href=https:\/\/\2/>\2</a>|g" |
2020-10-25 17:04:41 +00:00
sed -E "s|(\\!/)([^ \)]*)|!\/<a href=http:\/\/\2/>\2</a>|g" |
2021-04-04 21:10:20 +00:00
sed -E 's|a/(.+)/(.+)/|<a href="\1">\2</a>|g' |
2021-04-04 21:47:10 +00:00
sed -E 's|^SBLOCK\. (.+)|<div class=box><div class=boxheader>\1</div><br>|g' |
sed -E 's|^EBLOCK\.|</div>|g' |
2021-03-25 07:12:02 +00:00
sed -E 's|\\\\|<br>|g' |
2020-10-23 23:08:10 +00:00
sed -E '/%%BODY%%/r /dev/stdin' raw/template.html |
2020-11-10 08:24:09 +00:00
sed -E '/%%BODY%%/d' |
2021-04-22 20:50:01 +00:00
sed -E " s|%%QUOTE%%| $( quote) |g " |
2021-04-22 21:59:42 +00:00
sed -E " s|%%DEV%%| $dev |g " |
2020-11-10 08:24:09 +00:00
sed 's/%%HEADER%%/' " $header " '/g'
2020-10-23 23:08:10 +00:00
}
2020-11-10 08:24:09 +00:00
main ( ) {
2021-04-22 21:59:42 +00:00
while getopts "dq" opt
2020-11-10 08:24:09 +00:00
do
case $opt in
d)
2021-04-22 21:59:42 +00:00
dev = " <h4 class=dev>Please note, this is the development page, things may be broken\.<\/h4><h4 class=dev>Last built on $( date) \.<\/h4><details><summary>Details<\/summary>This version of my website is hosted inside a <a href=https:\/\/github.com\/skiqqy\/skiqqy-docker>docker container<\/a> and pulls from origin\/dev every 1 minute, hence it is possible for the site to be unstable, this is only for demo purposes\.<\/details> "
; ;
q)
quote = false
2020-11-10 08:24:09 +00:00
; ;
*)
exit 2
; ;
esac
done
mkdir -p site
for file in raw/*.txt
do
case $file in
*index.txt)
path = index.html
header = "<h1>Skiqqy<\/h1>~ Pronounced skippy"
; ;
*)
2021-04-22 20:50:01 +00:00
header = " <h1> $( echo " $file " | cut -d "/" -f 2 | cut -d "." -f 1) <\/h1> "
2020-11-10 08:24:09 +00:00
path = ${ file /raw/site }
path = ${ path /txt/html }
; ;
esac
2021-04-22 21:59:42 +00:00
#[[ -n $dev ]] && header="$header$dev"
2020-11-10 08:24:09 +00:00
echo " Building $file "
2021-04-22 20:50:01 +00:00
conv < " $file " > " $path "
2020-11-10 08:24:09 +00:00
done
}
main " $@ "