dotfiles

personal configurations for my systems and programs
git clone git@git.eonndev.com/dotfiles.git
Log | Files | Refs

commit 6d532e4d7139aaf65bbebd35a2de858f087a28fb
parent 453a88d0df6df58a22ff0ea57f7cbd79c9d0c030
Author: iressa <ian@eonndev.com>
Date:   Wed, 16 Dec 2020 02:01:33 -0500

adding mutt, ssg setup

Diffstat:
A.neomutt/mailcap | 1+
A.neomutt/muttrc | 9+++++++++
Aweb/bin/indexgen | 13+++++++++++++
Aweb/bin/publish | 14++++++++++++++
Aweb/bin/rssg | 190+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aweb/bin/ssg5 | 278+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aweb/bin/sssg | 7+++++++
7 files changed, 512 insertions(+), 0 deletions(-)

diff --git a/.neomutt/mailcap b/.neomutt/mailcap @@ -0,0 +1 @@ +text/html; elinks -dump ; copiousoutput; diff --git a/.neomutt/muttrc b/.neomutt/muttrc @@ -0,0 +1,9 @@ +source ~/.neomutt/accounts +set mailcap_path=~/.neomutt/mailcap + +set sidebar_visible=yes +bind index,pager \Ck sidebar-prev +bind index,pager \Cj sidebar-next +bind index,pager \Co sidebar-open + +color sidebar_new green black diff --git a/web/bin/indexgen b/web/bin/indexgen @@ -0,0 +1,13 @@ +#!/bin/bash +cd dst +FILES="$(find post/ -type f -name "*.html" | sort)" +TITLES="$(cat $FILES | grep h1 | sed 's|</*h1>||g')" +DATES="$(cat $FILES | grep h2 | sed 's|</*h2>||g')" + +FILESHTML="$(printf %b "$FILES" | sed 's|^|<a href="/|g;s/$/" /g')" +DATESPREPEND="$(printf %b "$DATES" | sed 's/^/<li>/g;s/$/ /g')" +DATESHTML="$(printf %b "$DATES" | sed 's/^/title="/g;s/$/"/g')" +TITLESHTML="$(printf %b "$TITLES" | sed 's/^/>/g;s|$|</a></li>|g')" + +paste -d "" <(echo "$DATESPREPEND") <(echo "$FILESHTML") <(echo "$DATESHTML") <(echo "$TITLESHTML") | tac +printf %b "<a href=\"https://eonndev.com/rss.xml\">rss</a>" diff --git a/web/bin/publish b/web/bin/publish @@ -0,0 +1,14 @@ +#!/bin/sh + +die(){ +echo "$1"; exit 1 +} + +cd ~/web +echo "generating website..." +bin/ssg5 src dst 'eonndev' 'https://eonndev.com' || die "ssg5 exited with an error" +echo "generating RSS..." +bin/indexgen > dst/rssindex.html +bin/rssg dst/rssindex.html 'eonndev blog' > dst/rss.xml || die "rssg exited with an error" +echo "copying files..." +rsync -rvPz --delete dst/ ssg@eonndev.com:/var/www/html/ || die "rsync exited with an error" diff --git a/web/bin/rssg b/web/bin/rssg @@ -0,0 +1,190 @@ +#!/bin/sh +# +# https://www.romanzolotarev.com/bin/rssg +# Copyright 2018 Roman Zolotarev <hi@romanzolotarev.com> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +set -e + + +main () { + test -n "$1" || usage + test -n "$2" || usage + test -f "$1" || no_file "$1" + + + index_file=$(readlink -f "$1") + test -z "${index_file##*html}" && html=$(cat "$index_file") + test -z "${index_file##*md}" && html=$(md_to_html "$index_file") + test -n "$html" || usage + + base="${index_file%/*}" + base_url="$(echo "$html" | get_url | sed 's#\(.*\)/[^/]*#\1#')" + + url=$( echo "$html" | get_url) + + title="$2" + + description=$( echo "$html" | get_description | + remove_tags | + remove_nbsp ) + + items=$( echo "$html" | get_items) + + rss=$( echo "$items" | + render_items "$base" "$base_url" | + render_feed "$url" "$title" "$description") + + >&2 echo "[rssg] ${index_file##$(pwd)/} $(echo "$rss" | grep -c '<item>') items" + echo "$rss" +} + + +usage() { + echo "usage: ${0##*/} index.{html,md} title > rss.xml" >&2 + exit 1 +} + + +no_file() { + echo "${0##*/}: $1: No such file" >&2 + exit 2 +} + + +md_to_html() { + test -x "$(which lowdown)" || exit 3 + lowdown \ + -D html-skiphtml \ + -D smarty \ + -d metadata \ + -d autolink "$1" +} + + +get_title() { + awk 'tolower($0)~/^<h1/{gsub(/<[^>]*>/,"",$0);print;exit}' +} + + +get_url() { + grep -i '<a .*rss.xml"' | head -1 | + sed 's#.*href="\(.*\)".*#\1#' +} + + +get_items() { + grep -i 'href=".*" title="' | + sed 's#.*href="\(.*\)" title="\(.*\)">\(.*\)</a>.*#\1 \2 \3#' +} + + +get_description() { + start='sub("^.*<"s"*"t"("s"[^>]*)?>","")' + stop='sub("</"s"*"t""s"*>.*","")&&x=1' + awk -v 's=[[:space:]]' -v 't=[Pp]' "$start,$stop;x{exit}" +} + +remove_tags() { + sed 's#<[^>]*>##g;s#</[^>]*>##g' +} + + +remove_nbsp() { + sed 's#\&nbsp;# #g' +} + + +rel_to_abs_urls() { + site_url="$1" + base_url="$2" + + abs='s#(src|href)="/([^"]*)"#\1="'"$site_url"/'\2"#g' + rel='s#(src|href)="([^:/"]*)"#\1="'"$base_url"/'\2"#g' + sed -E "$abs;$rel" +} + + +date_rfc_822() { + #date -j '+%a, %d %b %Y %H:%M:%S %z' \ + #"$(echo "$1"| tr -cd '[:digit:]')0000" + echo "$1" +} + + +render_items() { + while read -r i + do render_item "$1" "$2" "$i" + done +} + + +render_item() { + base="$1" + base_url="$2" + item="$3" + + site_url="$(echo "$base_url"| sed 's#\(.*//.*\)/.*#\1#')" + + date=$(echo "$item"|awk '{print$2}') + url=$(echo "$item"|awk '{print$1}') + + f="$base/$url" + test -f "$f" && html=$(cat "$f") + test -f "${f%\.html}.md" && html=$(md_to_html "${f%\.html}.md") + + description=$( + echo "$html" | + rel_to_abs_urls "$site_url" "$base_url" | + remove_nbsp + ) + title=$(echo "$description" | get_title) + guid="$base_url/$(echo "$url" | sed 's#^/##')" + + echo ' +<item> +<guid>'"$guid"'</guid> +<link>'"$guid"'</link> +<pubDate>'"$(date_rfc_822 "$date")"'</pubDate> +<title>'"$title"'</title> +<description><![CDATA[ + +'"$description"' + +]]></description> +</item>' +} + + +render_feed() { + url="$1" + title=$(echo "$2" | remove_nbsp) + description="$3" + + base_url="$(echo "$url" | cut -d '/' -f1-3)" + + echo '<?xml version="1.0" encoding="UTF-8"?> +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> +<channel> +<atom:link href="'"$url"'" rel="self" type="application/rss+xml" /> +<title>'"$title"'</title> +<description>'"$description"'</description> +<link>'"$base_url"'/</link> +<lastBuildDate>'"$(date_rfc_822 date)"'</lastBuildDate> +'"$(cat)"' +</channel></rss>' +} + + +main "$@" diff --git a/web/bin/ssg5 b/web/bin/ssg5 @@ -0,0 +1,278 @@ +#!/bin/sh -e +# +# https://rgz.ee/bin/ssg5 +# Copyright 2018-2019 Roman Zolotarev <hi@romanzolotarev.com> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +main() { + test -n "$1" || usage + test -n "$2" || usage + test -n "$3" || usage + test -n "$4" || usage + test -d "$1" || no_dir "$1" + test -d "$2" || no_dir "$2" + + src=$(readlink_f "$1") + dst=$(readlink_f "$2") + + IGNORE=$( + if ! test -f "$src/.ssgignore" + then + printf ' ! -path "*/.*"' + return + fi + while read -r x + do + test -n "$x" || continue + printf ' ! -path "*/%s*"' "$x" + done < "$src/.ssgignore" + ) + + # files + + title="$3" + + h_file="$src/_header.html" + h_index_file="$src/_header-index.html" + f_file="$src/_footer.html" + test -f "$f_file" && FOOTER=$(cat "$f_file") && export FOOTER + test -f "$h_file" && DEFHEADER=$(cat "$h_file") && export DEFHEADER + test -f "$h_index_file" && INDEXHEADER=$(cat "$h_index_file") && export INDEXHEADER + + list_dirs "$src" | + (cd "$src" && cpio -pdu "$dst") + + fs=$( + if test -f "$dst/.files" + then list_affected_files "$src" "$dst/.files" + else list_files "$1" + fi + ) + + if test -n "$fs" + then + echo "$fs" | tee "$dst/.files" + + if echo "$fs" | grep -q '\.md$' + then + if test -x "$(which lowdown 2> /dev/null)" + then + echo "$fs" | grep '\.md$' | + render_md_files_lowdown "$src" "$dst" "$title" + else + if test -x "$(which Markdown.pl 2> /dev/null)" + then + echo "$fs" | grep '\.md$' | + render_md_files_Markdown_pl "$src" "$dst" "$title" + else + echo "couldn't find lowdown nor Markdown.pl" + exit 3 + fi + fi + fi + + echo "$fs" | grep '\.html$' | + render_html_files "$src" "$dst" "$title" + + echo "$fs" | grep -Ev '\.md$|\.html$' | + (cd "$src" && cpio -pu "$dst") + fi + + printf '[ssg] ' >&2 + print_status 'file, ' 'files, ' "$fs" >&2 + + + # sitemap + + base_url="$4" + date=$(date +%Y-%m-%d) + urls=$(list_pages "$src") + + test -n "$urls" && + render_sitemap "$urls" "$base_url" "$date" > "$dst/sitemap.xml" + + print_status 'url' 'urls' "$urls" >&2 + echo >&2 +} + + +readlink_f() { + file="$1" + cd "$(dirname "$file")" + file=$(basename "$file") + while test -L "$file" + do + file=$(readlink "$file") + cd "$(dirname "$file")" + file=$(basename "$file") + done + dir=$(pwd -P) + echo "$dir/$file" +} + + +print_status() { + test -z "$3" && printf 'no %s' "$2" && return + + echo "$3" | awk -v singular="$1" -v plural="$2" ' + END { + if (NR==1) printf NR " " singular + if (NR>1) printf NR " " plural + }' +} + + +usage() { + echo "usage: ${0##*/} src dst title base_url" >&2 + exit 1 +} + + +no_dir() { + echo "${0##*/}: $1: No such directory" >&2 + exit 2 +} + +list_dirs() { + cd "$1" && eval "find . -type d ! -name '.' ! -path '*/_*' $IGNORE" +} + + +list_files() { + cd "$1" && eval "find . -type f ! -name '.' ! -path '*/_*' $IGNORE" +} + + +list_dependant_files () { + e="\\( -name '*.html' -o -name '*.md' -o -name '*.css' -o -name '*.js' \\)" + cd "$1" && eval "find . -type f ! -name '.' ! -path '*/_*' $IGNORE $e" +} + +list_newer_files() { + cd "$1" && eval "find . -type f ! -name '.' $IGNORE -newer $2" +} + + +has_partials() { + grep -qE '^./_.*\.html$|^./_.*\.js$|^./_.*\.css$' +} + + +list_affected_files() { + fs=$(list_newer_files "$1" "$2") + + if echo "$fs" | has_partials + then list_dependant_files "$1" + else echo "$fs" + fi +} + + +render_html_files() { + while read -r f + do + if $(echo "$1/$f" | grep "index.html" > /dev/null); then + HEADER="$INDEXHEADER" && export HEADER + else + HEADER="$DEFHEADER" && export HEADER + fi + render_html_file "$3" < "$1/$f" > "$2/$f" + done +} + + +render_md_files_lowdown() { + while read -r f + do + lowdown \ + -D html-skiphtml \ + -d metadata \ + -d autolink < "$1/$f" | + render_html_file "$3" \ + > "$2/${f%\.md}.html" + done +} + + +render_md_files_Markdown_pl() { + while read -r f + do + if $(echo "$1/$f" | grep "index.md" > /dev/null); then + HEADER="$INDEXHEADER" && export HEADER + else + HEADER="$DEFHEADER" && export HEADER + fi + Markdown.pl < "$1/$f" | + render_html_file "$3" \ + > "$2/${f%\.md}.html" + done +} + + +render_html_file() { + # h/t Devin Teske + awk -v title="$1" ' + { body = body "\n" $0 } + END { + body = substr(body, 2) + if (body ~ /<[Hh][Tt][Mm][Ll]/) { + print body + exit + } + if (match(body, /<[[:space:]]*[Hh]1(>|[[:space:]][^>]*>)/)) { + t = substr(body, RSTART + RLENGTH) + sub("<[[:space:]]*/[[:space:]]*[Hh]1.*", "", t) + gsub(/^[[:space:]]*|[[:space:]]$/, "", t) + if (t) title = t " &mdash; " title + } + n = split(ENVIRON["HEADER"], header, /\n/) + for (i = 1; i <= n; i++) { + if (match(tolower(header[i]), "<title></title>")) { + head = substr(header[i], 1, RSTART - 1) + tail = substr(header[i], RSTART + RLENGTH) + print head "<title>" title "</title>" tail + } else print header[i] + } + print body + print ENVIRON["FOOTER"] + }' +} + + +list_pages() { + e="\\( -name '*.html' -o -name '*.md' \\)" + cd "$1" && eval "find . -type f ! -path '*/.*' ! -path '*/_*' $IGNORE $e" | + sed 's#^./##;s#.md$#.html#;s#/index.html$#/#' +} + + +render_sitemap() { + urls="$1" + base_url="$2" + date="$3" + + echo '<?xml version="1.0" encoding="UTF-8"?>' + echo '<urlset' + echo 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' + echo 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' + echo 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"' + echo 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' + echo "$urls" | + sed -E 's#^(.*)$#<url><loc>'"$base_url"'/\1</loc><lastmod>'\ +"$date"'</lastmod><priority>1.0</priority></url>#' + echo '</urlset>' +} + +main "$@" diff --git a/web/bin/sssg b/web/bin/sssg @@ -0,0 +1,7 @@ +#!/bin/sh +while : +do + find . -type f ! -path '*/.*' | + entr -d "$HOME/bin/ssg5" . "$1" "$(date)" '//www' +done +$