From c6b831531c64d751bd48eecf6b7d1ee97793d65e Mon Sep 17 00:00:00 2001 From: eudoxia Date: Sun, 22 Nov 2020 02:27:26 -0500 Subject: initial --- .gitignore | 2 + distress.network | 1 + md-footer | 8 +++ md-header | 36 ++++++++++++ md.sh | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ nav.sh | 37 ++++++++++++ plain.sh | 42 +++++++++++++ reload.sh | 9 +++ shadow | 1 + simple-header | 24 ++++++++ sitemap.sh | 40 +++++++++++++ svgtex.sh | 38 ++++++++++++ 12 files changed, 414 insertions(+) create mode 100644 .gitignore create mode 120000 distress.network create mode 100644 md-footer create mode 100644 md-header create mode 100755 md.sh create mode 100755 nav.sh create mode 100755 plain.sh create mode 100755 reload.sh create mode 120000 shadow create mode 100644 simple-header create mode 100755 sitemap.sh create mode 100755 svgtex.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..49a948d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +distress.network/ +shadow/ diff --git a/distress.network b/distress.network new file mode 120000 index 0000000..631fa20 --- /dev/null +++ b/distress.network @@ -0,0 +1 @@ +/var/www/distress.network/ \ No newline at end of file diff --git a/md-footer b/md-footer new file mode 100644 index 0000000..b8a2a43 --- /dev/null +++ b/md-footer @@ -0,0 +1,8 @@ + + + + + diff --git a/md-header b/md-header new file mode 100644 index 0000000..9f02377 --- /dev/null +++ b/md-header @@ -0,0 +1,36 @@ + + + + + + + + + + + + + +# + + + + +
+
#
+
+
+
––––DistressNetwork°
+ +
+
+
+ +
+
#
+
+ + diff --git a/md.sh b/md.sh new file mode 100755 index 0000000..d5f27d5 --- /dev/null +++ b/md.sh @@ -0,0 +1,176 @@ +#!/bin/sh +set -e + +# usage: +# ./md.sh +# ./md.sh +# +# target dir: input `src.md`, output `index.html` +# dependencies: lowdown, fzf, python (for now) + + +# i/o variables + +IN="$1/src.md" +OUT="$1/index.html" + +if [ "$2" ] ; then + IN="$1" ; + OUT="$2" ; +fi + +# confirm source exists before continuing + +[ -f $IN ] || { echo "---- [FATAL] $IN not found ----" ; exit 1 ; } + + +### initial write + +cat md-header > $OUT +lowdown -Thtml $IN >> $OUT +cat md-footer >> $OUT +echo '[ok] initial assembly' + + +### useful functions + +sedesc() { + sed -e 's;&;\\\&;g' -e 's/;/\\\;/g' +} + +unesc() { + sed -e 's;\\\&;\&;g' -e 's/\\\;/;/g' +} + +encode() ( # TODO: python't + python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "$1" +) + +decode() { + /bin/printf '%b' "$(echo "$1" | sed 's;%;\\x;g')" +} + + +### header variables extracted from metadata section + +TITLE=$(grep -e '^title: ' -m 1 $IN | cut -f 2- -d ' ' | sedesc) +sed "s/#/<title>${TITLE}/1" -i'' $OUT +printf '[ok] title: %s\n' "$(echo $TITLE | unesc)" + +BOMBER=$(grep -e '^bomber: ' -m 1 $IN | cut -f 2- -d ' ' | sedesc) +sed "s/<div class=\"bomber\">#/<div class=\"bomber\">${BOMBER}/1" -i'' $OUT +printf '[ok] bomber: %s\n' "$(echo $BOMBER | unesc)" + +MDATE=$(stat -c '%y' $IN | sed -e 's/\.[0-9]* //' -e 's/\(..\)\(..\)$/\1:\2/') # format: "yyyy-mm-dd hh:mm:ss±zz:zz" (ISO 8601) +DATE=$(echo $MDATE | cut -f 1 -d ' ' | sed -e 's/-//g' -e 's/^..//') # format: "yymmdd" (for humans) +sed "s;<div class=\"ident\"><time>#;<div class=\"ident\"><time datetime=\"${MDATE}\">${DATE};1" -i'' $OUT +sed "/^<\/head>/i <meta http-equiv=\"last-modified\" content=\"${MDATE}\" />" -i'' $OUT +printf '[ok] date: %s (%s)\n' "$DATE" "$MDATE" + +LEADING=$(grep -e '^leading: ' -m 1 $IN | cut -f 2- -d ' ' | sedesc) +sed "s;<div class=\"leading\">#;<div class=\"leading\">${LEADING};1" -i'' $OUT +printf '[ok] leading: "%s"\n' "$(echo $LEADING | unesc)" + +METADESC="\«\;${BOMBER}\»\; \&mdash\; ${LEADING}" +sed "s;<meta name=\"description\" content=\"#;<meta name=\"description\" content=\"${METADESC};1" -i'' $OUT +printf '[ok] meta description\n' + + +### image handling + +grep -n '<p><img' $OUT | \ +while IFS='' read -r data ; do + LINE=$(echo $data | cut -f 1 -d :) ; # extract line number + FILE=$(echo $data | cut -f 2 -d \") ; # extract file path + CAPT=$(echo $data | cut -f 4 -d \") ; # extract image caption + + if [ "$CAPT" = "#tex" ] ; then # for tex figures: remove caption and containers + sed "${LINE}s;.*;<figure><img src=\"${FILE}\" alt=\"\"></figure>;" -i'' $OUT ; + printf '[ok] tex figure at line %s\n' "$LINE" ; + else # use new image format + sed "${LINE}s;.*;<figure><a href=\"${FILE}\"><img src=\"${FILE}\" alt=\"\"></a><figcaption><p>${CAPT}</p></figcaption></figure>;" -i'' $OUT ; + printf '[ok] image at line %s\n' "$LINE" ; + fi +done + + +### table of contents generation + +tocgen() ( + +tmp=$(mktemp -p /tmp) # using a tempfile, more convenient for storage and operations + +TOCLIST=$(grep -e '^#' $IN | sed -e 's; ;- ;' -e 's;^#;;' -e 's;#; ;g') # headers from source as md list + +echo "$TOCLIST" | while IFS='' read -r data ; do # encode headers as urls + HEADER=$(echo "$data" | sed 's/^[[:space:]-]*//' | encode "$(cat /dev/stdin)") ; + echo "$data" | sed "s/^\([[:space:]-]*\)\(.*\)$/\1${HEADER}/" >> $tmp ; +done + +buffer=$(cat $tmp) ; echo "$buffer" | lowdown -Thtml > $tmp # convert to html, write to tempfile (reset) + +sed -e '1i <nav class="toc">' -e '/^$/d' -i'' $tmp # prepend starting tag, remove empty lines + +cat $tmp | while IFS='' read -r data ; do + + # get header (both encoded and raw), write as link + ID=$(echo $data | sed "s;^<li>\([^</>]*\)\(</li>\)*$;\1;") ; + HEADER=$(decode "$ID" | sedesc) ; + sed -e "s;^<li>\(${ID}\);<li><a href=\"#\1\">${HEADER};" -e "s;\([[:alnum:]]\)</li>$;\1</a></li>;" -i'' $tmp ; + + # find old id in output, replace with new id + IDLINE=$(grep -ne "^<h[[:digit:]] id=" $OUT | fzf -f "$(echo $HEADER | unesc)" | head -n 1 | cut -f 1 -d :) ; + if [ "$IDLINE" ] ; then + sed -e "${IDLINE}s;id=\".*\">.*</h;id=\"${ID}\">${HEADER}</h;" -i'' $OUT ; + printf ' assembled header "%s"\n' "$(echo $HEADER | unesc)" ; + # else + # printf '[warning] could not match header id: "%s"\n' "$HEADER" ; + # echo "---- [FATAL] could not find header id (possible escapement issue) ----" ; + # rm $tmp ; + # exit 1 ; + fi ; +done + +# close link tags on open lines, append closing tag + +sed "s;[[:alnum:]]$;&</a>;" -i'' $tmp +echo '</nav>' >> $tmp + +# get toc line number in output, insert data from tempfile + +TOCLINE=$(grep -n 'end of header' $OUT | cut -f 1 -d :) +sed "${TOCLINE}r $tmp" -i'' $OUT + +rm $tmp # cleanup + +echo '[ok] table of contents' + +) + + +### metadata option handling + +opts=$(grep -e '^opts: ' -m 1 $IN | cut -f 2- -d ' ') + +while [ "$opts" ]; do +case "$opts" in + (*[Cc]*) + tocgen + opts=$(echo $opts | sed 's/[Cc]//g') + ;; + + (*[Hh]*) + sed "/^<header>/,/^<\/header>/d" -i'' $OUT + sed "/bg.js/d" -i'' $OUT + echo "[ok] headerless" + opts=$(echo $opts | sed 's/[Hh]//g') + ;; + + (*) + echo "[warning] metadata: unrecognized option(s)" + ;; +esac +done + + +echo "---- build complete: ${OUT} ----" diff --git a/nav.sh b/nav.sh new file mode 100755 index 0000000..6cf5d08 --- /dev/null +++ b/nav.sh @@ -0,0 +1,37 @@ +#!/bin/sh +set -e + +# usage: nav.sh <source dir> <output file> + + +echo '<pre>' > $2 # starting <pre> tag +echo '<!--title: Sitemap-->' >> $2 # util for smd.sh + +# initial tree generation + +tree -dfn --noreport -I 'css|error|favicon|fonts|js|media' $1 >> $2 + +# remove leading path prefix + +sed 's;/var/www/distress\.network;;g' -i'' $2 + +# link generation loop for each line + +grep -n '─ ' $2 | \ +while IFS='' read -r data ; do + LINE=$(echo $data | cut -f 1 -d :) ; # extract line number + FULL=$(echo $data | cut -f 2- -d /) ; # extract output path + NAME=$(echo $FULL | grep -o '[^/]*$') ; # extract page name (last field of path) + + # at the line number, replace path with link to page + + sed "${LINE}s;─ .*;──<a href=\"/${FULL}\">${NAME}</a>;" -i'' $2 ; +done + +# replace starting blank line with root link + +sed '3s;.*;<a href="/">·</a>;' -i'' $2 + +echo '</pre>' >> $2 # closing <pre> tag + +cat $2 diff --git a/plain.sh b/plain.sh new file mode 100755 index 0000000..23eb200 --- /dev/null +++ b/plain.sh @@ -0,0 +1,42 @@ +#!/bin/sh +set -e + +# usage: ./plain.sh <input txt> <output html> + + +# i/o variables + +IN="$1" +OUT="$2" + +[ -f $IN ] || { echo "---- [FATAL] $IN not found ----" ; exit 1 ; } + + +# initial write + +cat plain-header > $2 +cat $1 >> $2 +printf "</pre>\n</body>\n</html>" >> $2 +echo '[ok] initial assembly' + +# hack to fix double <pre> when generating from nav.sh + +sed -e "/^<pre>$/ {n;/^<pre>$/d}" -e "/^<\/pre>$/ {n;/^<\/pre>$/d}" -i'' $2 + + +# metadata + +sedesc() { + sed -e 's;\&;\\\&;' -e 's/;/\\\;/' -e 's;-->;;' +} + +TITLE=$(grep -e '^<!--title: ' -m 1 $1 | cut -f 2- -d ' ' | sedesc) +sed -e "/^<!--title:/d" -e "s;<title>#;<title>${TITLE};1" -i'' $2 +printf '[ok] title: %s\n' "$TITLE" + +MDATE=$(stat -c '%y' $1 | sed -e 's/\.[0-9]* //' -e 's/\(..\)\(..\)$/\1:\2/') # ISO 8601 format: "yyyy-mm-dd hh:mm:ss±zz:zz" +sed "/^<\/head>/i <meta http-equiv=\"last-modified\" content=\"${MDATE}\" />" -i'' $2 +printf '[ok] date: %s\n' "$MDATE" + + +echo "---- build complete: $2 ----" diff --git a/reload.sh b/reload.sh new file mode 100755 index 0000000..6bb6b67 --- /dev/null +++ b/reload.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +sh ./nav.sh distress.network distress.network/nav.html > /dev/null +echo "[ok] nav embed" +sh ./plain.sh distress.network/nav.html distress.network/meta/sitemap/index.html > /dev/null +echo "[ok] nav page" +sh ./sitemap.sh distress.network distress.network/sitemap.xml > /dev/null +echo "[ok] sitemap.xml" diff --git a/shadow b/shadow new file mode 120000 index 0000000..97e6b5f --- /dev/null +++ b/shadow @@ -0,0 +1 @@ +/var/www/shadow.distress.network/ \ No newline at end of file diff --git a/simple-header b/simple-header new file mode 100644 index 0000000..65cdda0 --- /dev/null +++ b/simple-header @@ -0,0 +1,24 @@ +<!doctype html> +<html> +<head> +<meta charset="UTF-8"> +<link rel="stylesheet" href="/fonts/fonts.css"> +<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png"> +<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png"> +<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png"> +<link rel="manifest" href="/favicon/site.webmanifest"> +<style> +:root {font-size: 15px;} +body {background-color: #111; margin: 2rem;} +pre {color: #ddd; font-family: jetbrains-mono-regular, Consolas, Menlo, monospace; font-style: normal; font-size: 1rem; line-height: 1.5em; white-space: pre-wrap;} +pre a {color: #ddd;} +pre a:link {text-decoration: none; color: #ddd;} +pre a:visited {text-decoration: none; color: #ddd;} +pre a:hover {text-decoration: none; color: #111; background-color: #ddd;} +pre a:active {text-decoration: none; color: #ddd;} +</style> +<title># + + + +
diff --git a/sitemap.sh b/sitemap.sh
new file mode 100755
index 0000000..faf535d
--- /dev/null
+++ b/sitemap.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+set -e
+
+# usage: ./sitemap.sh  
+
+urlencode() (
+	# urlencode 
+
+	old_lc_collate=$LC_COLLATE
+	LC_COLLATE=C
+
+	length="${#1}"
+	i=1
+	while [ $i -le $length ] ; do
+		c=$(expr substr "$1" $i 1) ;
+		case $c in
+			([a-zA-Z0-9./~_-])	printf "$c" ;;
+			(*)			printf '%%%02X' "'$c" ;;
+		esac ;
+		true $((i=i+1)) ;
+	done
+
+	LC_COLLATE=$old_lc_collate
+)
+
+echo '
+' > $2
+
+echo "$(find -L $1 -type d | sort | sed -e 's;^\./;;' -e '\;/\(css\|error\|favicon\|fonts\|js\|media\);d' -e 's;$;/;')" | \
+while IFS='' read -r data ; do
+	DATE=$(grep "last-modified" ${data}/index.html | cut -f 4 -d \" | sed 's/ /T/' ) ;
+	urlencode "$data" | sed -e 's;^;https://;' -e "s;$;${DATE};" ;
+	printf "\n" ;
+done >> $2
+
+echo '' >> $2
+
+cat $2
diff --git a/svgtex.sh b/svgtex.sh
new file mode 100755
index 0000000..1ce2b03
--- /dev/null
+++ b/svgtex.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+set -e
+
+# usage: 	echo "" | svgtex.sh 
+
+
+tmp=$(mktemp -p /tmp)
+eqn=$(cat /dev/stdin)
+
+echo "---- begin assembly: ----"
+printf "%s\n" "$eqn"
+
+echo "\\\documentclass[10pt,fleqn]{standalone}
+\\\usepackage{standalone,amsmath,amssymb,xcolor}
+\\\begin{document}
+\\\color[HTML]{DDDDDD}" >> $tmp
+
+printf "\\\[ %s \\\]\n" "$eqn" >> $tmp
+
+echo "\\\end{document}" >> $tmp
+
+# now this is where the fun begins
+
+latex -interaction=batchmode $tmp
+
+[ -f tmp.dvi ] || { echo "---- [FATAL] tex output failed ----" ; exit 1 ; }	# make sure output exists before continuing
+
+echo "[ok] tex finished typesetting"
+
+dvisvgm tmp.dvi -f ttf -T S2
+
+echo "[ok] conversion to svg"
+
+mv tmp.svg $1 	# final move to desired path
+
+rm tmp.aux tmp.log tmp.dvi $tmp 	# cleanup
+
+echo "---- build complete: $1 ----"
-- 
cgit v1.2.3