fusch.online

git / lists / casts

git.fusch.online/planner

Generate static pages from a list of links
git clone git://git.fusch.online/planner
Log / Files / Readme / Issues

commit 162ed54b63ca1fecb51052625fd434fdf0ea6ad8
Author: hbkk <tschugg@posteo.de>
Date:   Sat, 30 Mar 2019 23:51:47 +0100

init

Diffstat:
Alinks.sh | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atodo.txt | 3+++
2 files changed, 144 insertions(+), 0 deletions(-)

diff --git a/links.sh b/links.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash + +tmp=$(mktemp) +offline=false + + +# main +[[ $1 == -n ]] && { + offline=true + shift +} + +mkdir -p ./site + +cat <<EOF > ./site/index.html +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>links</title> + <style> + body { + width: 60em; + margin: 0 auto; + font-size: 7pt; + color: purple; + } + + h2 { + font-size: small; + } + + .entry { + line-height: 1em; + padding: 0.4em; + margin-bottom: 1em; + border-bottom-style: dotted; + border-width: 1px; + border-color: black; + } + + a { + text-decoration: none; + } + + a.read { + color: purple; + } + + a.read:hover { + text-decoration: underline; + } + + a.unread { + color: blue; + } + + a.unread:hover { + text-decoration: underline; + } + + a.link { + color: black; + } + + a.link:hover { + text-decoration: underline; + } + + .tag { + color: grey; + text-decoration: none; + } + + .tag:hover { + color: purple; + } + </style> + </head> + <body> + <h1>links</h1> +EOF + +while read -r line; do + link=$(cut -d, -f1 <<< "$line") + tags=$(cut -s -d, -f2 <<< "$line") + title=$(cut -s -d, -f3- <<< "$line") + class="read" + + if [[ -z $title ]]; then + title=$(grep "^${link}," ./db.txt | cut -d, -f3-) + + [[ -z $title && $offline == false ]] && { + printf "getting title for %s...\n" "$link" >&2 + + title=$(curl -L -s "$link" \ + | grep "<title>" \ + | head -1 \ + | sed -e 's/^.*<title>//' -e 's/<\/title>.*$//') + + printf "\t%s\n" "$title" >&2 + } + + [[ -z $title ]] && { + title="$(sed -e 's/http.:\/\///' -e 's/\/.*$//' <<< "$link")" + title="⛷ $title" + printf "\t%s\n" "$title" >&2 + } + + printf "%s,%s,%s\n" "$link" "$tags" "$title" >> "$tmp" + else + printf "%s\n" "$line" >> "$tmp" + fi + + grep "^${link}," ./db.txt | cut -d, -f2 | grep -q "read" && { + title="⛟ $title" + class="unread" + } + + cat << EOF >> ./site/index.html + <div class="entry"> + <h2><a class="$class" href="$link">$title</a></h2> + <a class="link" href="$link">$link</a> +EOF + + for tag in $tags; do + [[ $tag == read ]] && continue + + printf " <a class=\"tag\" href=\"%s\">%s</a>\n" \ + "./$tag.html" "$tag" >> ./site/index.html + done + + printf " </div>\n" >> ./site/index.html +done < "${1:-./links.txt}" + +cat << EOF >> ./site/index.html + </body> +</html> +EOF + +mv "$tmp" ./db.txt diff --git a/todo.txt b/todo.txt @@ -0,0 +1,3 @@ +- [ ] add public/private bookmarks +- [ ] add sites for tags +- [x] newest first