aboutsummaryrefslogtreecommitdiffstats
path: root/wr
diff options
context:
space:
mode:
Diffstat (limited to 'wr')
-rwxr-xr-xwr211
1 files changed, 211 insertions, 0 deletions
diff --git a/wr b/wr
new file mode 100755
index 0000000..1e4f07f
--- /dev/null
+++ b/wr
@@ -0,0 +1,211 @@
+#!/bin/sh
+# wr - Minimal webring utility
+# Licensed under the MIT License.
+
+# This script should not be sourced, make sure to change the string 'wr'
+# in the following line to match this file's name
+[ 'wr' = "$( basename ${0} )" ] || return 1
+
+# Edit DOMAIN and AUTHOR for your instance
+# Make sure that DOMAIN is ONLY the domain of your instance, and without trailing slash
+DOMAIN="webring.gumx.cc"
+AUTHOR="Ahmed (~gumxcc)"
+
+# Script metadata
+SCRIPT=$( basename "$0" )
+VMAJOR=0
+VMINOR=1
+VPATCH=0
+HOMEPAGE="https://webring.gumx.cc/"
+
+print_help () {
+ cat << HELP_TEXT
+${SCRIPT} v${VMAJOR}.${VMINOR}.${VPATCH}
+Minimal webring utility
+
+Usage:
+ ${SCRIPT} add SITE_URL SITE_TITLE [AUTHOR_NAME]
+ Add a new entry to the webring
+ ${SCRIPT} [build]
+ Build the webring
+ ${SCRIPT} -h | --help | help
+ Display this help message and exit
+ ${SCRIPT} -v | --version | version
+ Display the script version and exit
+
+Project homepage: <${HOMEPAGE}>
+HELP_TEXT
+}
+
+print_version () {
+ VERSION="${VMAJOR}.${VMINOR}.${VPATCH}"
+ printf '%s Version %s\n' "${SCRIPT}" "${VERSION}"
+}
+
+print_error () {
+ ERROR_MSG=${1:-Unknown error}
+ printf '%s: %s\n' "${SCRIPT}" "${ERROR_MSG}" >&2
+}
+
+build_webring() {
+ mkdir -p public
+ printf '' > public/index.html
+
+ cat << INDEX_PAGE_TOP > public/index.html
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta content="IE=edge" http-equiv="X-UA-Compatible">
+ <meta content="text/html; charset=UTF-8" http-equiv="content-type">
+ <meta content="width=device-width,initial-scale=1" name="viewport">
+ <title>webring</title>
+ <meta content="webring" name="title">
+ <meta content="${AUTHOR}" name="author">
+ <meta content="Minimal webring" name="description">
+ <meta content="website" property="og:type">
+ <meta content="${DOMAIN}" property="og:url">
+ <meta content="webring" property="og:site_name">
+ <meta content="webring" property="og:title">
+ <meta content="Minimal webring" property="og:description">
+ <meta content="summary" property="twitter:card">
+ <meta content="${DOMAIN}" property="twitter:url">
+ <meta content="webring" property="twitter:title">
+ <meta content="Minimal webring" property="twitter:description">
+ <link href="${DOMAIN}" rel="canonical">
+ <link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAACYktHRAAAqo0jMgAAAAd0SU1FB+YMGRUdK60VU+wAAAEzSURBVEjH7ZO9SgNBFIU/fyImEkgExRQquEiaQCwsDT6AnYWdnWCRx0jlA1ha+Q4WCvYWFimTgKzBRgUTRDSB6Fh4dzI7mJm1sNvT3DOHe787w7KQKtW/qIFCoTg3skPJbpIA7qT5yMhWJVMEvvGybt38FVu3B6atc01qj04sjy6/6wOUpbatPDpv+QCBBxAwlwzQtfKu7i+5AWtS+8AeISEhJ0BPdyzHB2YtwILUAVBgHYAVYKg7cu4bZKR+AVnxWeBz0kobMDCG8uLzsb3vbkD01hywZLx6DHhxA0Kpi4y/yAZQFK+4dwOaUivMsCO+QJWK+JZ+5AQd6H+hpZ3igTdxp3g0z5MxqLiMnRTbPgDsM9Ltz5S4Nsa9+39U44I+r1xRBYqc8cgHtxwzlQyQ6o/6BrGHacYUEyMVAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIyLTEyLTI1VDIxOjI5OjQzKzAwOjAwsFlEUAAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMi0xMi0yNVQyMToyOTo0MyswMDowMMEE/OwAAAAodEVYdGRhdGU6dGltZXN0YW1wADIwMjItMTItMjVUMjE6Mjk6NDMrMDA6MDCWEd0zAAAACHRFWHRsYWJlbADPieuXgVsAAAAASUVORK5CYII=" rel="icon">
+ <script type="application/ld+json">
+ {
+ "description":"Minimal webring",
+ "url":"${DOMAIN}",
+ "@type":"WebSite",
+ "headline":"webring",
+ "name":"webring",
+ "author":{
+ "@type":"Person",
+ "name":"${AUTHOR}"
+ },
+ "@context":"https://schema.org"
+ }
+ </script>
+ <style>
+ html { height:100%; background:white; }
+ body { background:white; color:black; font-family:monospace; font-size:16px; line-height:1.4; margin:0; padding:4rem 0; min-height:100%; overflow-wrap:break-word; }
+ main { max-width:640px; margin:0 auto; padding:0 2rem; }
+ h1 { text-align:center }
+ ul { display: flow-root; }
+ li, nav a { width: 40%; float: left; margin: 0 5%; }
+ nav a { text-decoration: none; display: block; text-align: center; }
+ body[theme="dark"] { filter:invert(1); }
+ @media (prefers-color-scheme: dark) { body[theme="auto"] { filter:invert(1); } }
+ @media (max-width:640px) { li { width: 90%; } }
+ </style>
+</head>
+
+<body theme="auto">
+ <main>
+ <h1>&omega; webring</h1>
+ <hr />
+ <ul>
+INDEX_PAGE_TOP
+
+ #TODO: refactor this
+ count=0
+ for entry in $( find ./entries -type f ); do
+ count=$(( count + 1 ))
+ . ${entry}
+ entry_name="$( basename ${entry} )"
+ [ ${count} -eq 1 ] && first_entry="${entry_name}" && prev_entry="${entry_name}"
+ mkdir -p "public/${entry_name}" \
+ "public/${entry_name}/next" \
+ "public/${entry_name}/previous"
+ printf "<html><meta http-equiv=\"Refresh\" content=\"0; url='%s'\" /></html>\n" "${url}" \
+ > "public/${entry_name}/index.html"
+ cp "public/${entry_name}/index.html" "public/${prev_entry}/next/index.html"
+ cp "public/${prev_entry}/index.html" "public/${entry_name}/previous/index.html"
+ prev_entry="${entry_name}"
+ [ -n "${author}" ] \
+ && printf ' <li><a href="%s">%s</a> by %s</li>\n' \
+ "${url}" "${title}" "${author}" >> public/index.html \
+ || printf ' <li><a href="%s">%s</a></li>\n' \
+ "${url}" "${title}" >> public/index.html
+ unset url title author
+ done
+ cp "public/${first_entry}/index.html" "public/${entry_name}/next/index.html"
+ cp "public/${entry_name}/index.html" "public/${first_entry}/previous/index.html"
+
+ cat << INDEX_PAGE_BOTTOM >> public/index.html
+ </ul>
+ <hr />
+ <p>This is an attempt to replicate <a href="https://wiki.xxiivv.com/site/devine_lu_linvega.html">Devine Lu Linvega</a>'s <a href="https://webring.xxiivv.com/">webring</a> in a very minimal way, and with a lower technical bar.</p>
+ <p>To add your site to the webring, follow the instructions <a href="https://git.sr.ht/~gumxcc/webring.gumx.cc#host-your-own">here</a>. For issues, source code, documentation, visit the <a href="https://sr.ht/~a2/webring/">project page on sourcehut</a></p>
+ <p>This project is licensed under <a href="https://git.sr.ht/~gumxcc/webring.gumx.cc/tree/main/item/LICENSE">MIT license</a></p>
+ <hr />
+ <nav>
+ <a href="/${DOMAIN}/previous">&prec; previous</a>
+ <a href="/${DOMAIN}/next">next &succ;</a>
+ </nav>
+ </main>
+</body>
+
+</html>
+INDEX_PAGE_BOTTOM
+}
+
+add_entry() {
+ entry="$( basename ${1} )"
+ entry_file="entries/${entry}"
+ mkdir -p $( dirname ${entry_file} )
+
+ printf 'url="%s"\ntitle="%s"' "${1}" "${2}" > "${entry_file}"
+ [ -n "${3}" ] && printf '\nauthor="%s"' "${3}" >> "${entry_file}"
+
+ cat << ENTRY_LINKS
+Add the following links in your website, preferrably in the footer:
+
+ <p>
+ <a href="https://${DOMAIN}/${entry}/previous">&larr; previous</a>
+ &emsp;
+ <a href="https://${DOMAIN}/">webring index</a>
+ &emsp;
+ <a href="https://${DOMAIN}/${entry}/next">next &rarr;</a>
+ </p>
+
+You can style them as you please of course
+ENTRY_LINKS
+}
+
+if [ -z "${1}" ] || [ "${1}" = "build" ]; then
+ printf 'Building the webring..'
+ build_webring
+ printf ' done\n'
+ exit 0
+fi
+
+ENTRY_URL=''
+ENTRY_TITLE=''
+ENTRY_AUTHOR=''
+
+case "${1}" in
+ -h|--help|help)
+ print_help
+ exit 0
+ ;;
+ -v|--version|version)
+ print_version
+ exit 0
+ ;;
+ add)
+ shift
+ add_entry "${1}" "${2}" "${3}"
+ exit 0
+ ;;
+ *)
+ print_error "${1}: Invalid argument"
+ print_help >&2
+ exit 22
+ ;;
+esac
+
+trap "print_error 'Interrupt signal detected, output may be incomplete'" INT