summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2021-02-24 23:12:20 -0700
committerDavid Luevano Alvarado <david@luevano.xyz>2021-02-24 23:12:20 -0700
commit48429992410a0e3664df8d42b088d990db784d90 (patch)
tree3a5c66b0817486a7831247e7362db49023cbb5bc
parentd1ffcbc2c8d3e454f839c2094a913b8b952a8605 (diff)
Add ssg and rssg for static webpage management, other fixes
-rw-r--r--.config/picom.conf4
-rw-r--r--.config/zsh/.zshrc2
-rwxr-xr-x.local/bin/rssg189
-rwxr-xr-x.local/bin/ssg265
4 files changed, 457 insertions, 3 deletions
diff --git a/.config/picom.conf b/.config/picom.conf
index f9d81b8..a34b556 100644
--- a/.config/picom.conf
+++ b/.config/picom.conf
@@ -56,7 +56,7 @@ blur-background-exclude = [
];
##---Fading---##
-fading = false;
+fading = true;
fade-delta = 4;
fade-in-step = 0.03;
fade-out-step = 0.03;
@@ -83,7 +83,7 @@ wintypes:
{
tooltip =
{
- fade = false;
+ fade = true;
shadow = false;
opacity = 0.85;
focus = true;
diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc
index 4f0f050..c2bcb55 100644
--- a/.config/zsh/.zshrc
+++ b/.config/zsh/.zshrc
@@ -2,7 +2,7 @@
# PS1 colors and style.
autoload -U colors && colors
-PS1="%{$fg_bold[red]%}[%{$fg_bold[yellow]%}%n%{$fg_bold[green]%}@%{$fg_bold[blue]%}%M %{$fg_bold[magenta]%}%(5~|%-2~/.../%2~|%~)%{$fg_bold[red]%}]%{$fg_bold[cyan]%}%#%{$reset_color%} "
+PS1="%(!.%{$fg_bold[red]%}[%n@%M %(5~|%-2~/.../%2~|%~)]%#%{$reset_color%} .%{$fg_bold[red]%}[%{$fg_bold[yellow]%}%n%{$fg_bold[green]%}@%{$fg_bold[blue]%}%M %{$fg_bold[magenta]%}%(5~|%-2~/.../%2~|%~)%{$fg_bold[red]%}]%{$fg_bold[cyan]%}%#%{$reset_color%} )"
# Set LS_COLORS via dircolors.
[[ -f $HOME/.config/dircolors ]] && eval "$(dircolors $HOME/.config/dircolors)"
diff --git a/.local/bin/rssg b/.local/bin/rssg
new file mode 100755
index 0000000..52031e7
--- /dev/null
+++ b/.local/bin/rssg
@@ -0,0 +1,189 @@
+#!/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"
+}
+
+
+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/.local/bin/ssg b/.local/bin/ssg
new file mode 100755
index 0000000..5339958
--- /dev/null
+++ b/.local/bin/ssg
@@ -0,0 +1,265 @@
+#!/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"
+ f_file="$src/_footer.html"
+ test -f "$f_file" && FOOTER=$(cat "$f_file") && export FOOTER
+ test -f "$h_file" && HEADER=$(cat "$h_file") && export HEADER
+
+ 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 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
+ 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 "$@"