~kris/dots

srice

ref: 9f828eb14bdd54d2c4fd8a3b2c90253021df3152 srice/.local/bin/blog-archive-url -rwxr-xr-x 780 bytes
9f828eb1 — Kris Yotam mksh: backslash-escape commands in history hook to bypass module aliases (wc=tokei, tr=transmission-remote, cat=bat) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env sh
set -eu

if [ "$#" -ne 1 ]; then
  printf 'usage: blog-archive-url URL\n' >&2
  exit 2
fi

url=$1
domain=$(printf '%s' "$url" | awk -F[/:] '{print $4}')
hash=$(printf '%s' "$url" | sha1sum | awk '{print $1}')
root=${BLOG_ARCHIVE_DIR:-archives/www}
dir="$root/$domain"
mkdir -p "$dir"

if command -v single-file >/dev/null 2>&1; then
  out="$dir/$hash.html"
  single-file "$url" "$out"
elif command -v monolith >/dev/null 2>&1; then
  out="$dir/$hash.html"
  monolith "$url" -o "$out"
elif command -v wget >/dev/null 2>&1; then
  out="$dir/$hash"
  mkdir -p "$out"
  wget --page-requisites --convert-links --adjust-extension --no-host-directories --directory-prefix="$out" "$url"
else
  out="$dir/$hash.html"
  curl -Lfs "$url" -o "$out"
fi

printf '%s\n' "$out"