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 93da23182c174b8b183ef9bc45e8b3b8bb4cc2f0
parent c00cd77085bbccd459b46b24e77a22b043ee102d
Author: tutti <tutti@fusch.online>
Date:   Mon, 30 Mar 2020 20:41:08 +0200

format to csv + small changes

Diffstat:
MREADME.md | 12+++++++-----
Mplanner | 84+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Mstyle.css | 16+---------------
Mtodo.txt | 6+++---
4 files changed, 63 insertions(+), 55 deletions(-)

diff --git a/README.md b/README.md @@ -2,6 +2,8 @@ Generate static pages from a list of links +Requires markdown. + ## example [planner.fusch.online](https://planner.fusch.online) @@ -10,17 +12,17 @@ Generate static pages from a list of links Edit `config`, then: - ./planner links.tsv + ./planner links.csv This will write all files to a directory named ./planner_html. -## links.tsv +## links.csv ### example - 190401 https://git.fusch.online/planner.git git code Static link aggregator + 190401,https://git.fusch.online/planner,git code,Static link aggregator ## templates -./header.html and ./footer.html will be included in all files if found. -"{{{ tag }}}" will be replaced with the currently selected tag. +`./header.html` and `./footer.html` will be included in all files if +found. `index.md` will be rendered in the root `index.html` if found. diff --git a/planner b/planner @@ -7,9 +7,14 @@ offline=false dateformat="--rfc-3339=seconds" builddate=$(date "$dateformat") sitetitle="planner" +db=./planner.db config=./config +xml_escape() { + sed -e 's/&/\&amp\;/g; s/</\&lt\;/g; s/>/\&gt\;/g;' <<< "$1" +} + print_html_head() { cat <<EOF <!DOCTYPE html> @@ -28,8 +33,7 @@ EOF } print_html_tail() { - sed -e "s/{{{ rss }}}/.\/atom.xml/" -e "s/{{{ tags }}}/.\/tags.html/" \ - ./footer.html | grep -v "{{{ .* }}}" + sed -e "s_{{{ rss }}}_$PLANNER_URL/atom.xml_" ./footer.html | grep -v "{{{ .* }}}" cat << EOF </div> @@ -51,7 +55,7 @@ print_html_link_tail() { } print_html_link_tag() { - printf " <a class=\"tag\" href=\"%s\">%s</a>\n" "./$1.html" "$1" + printf " <a class=\"tag\" href=\"$PLANNER_URL/%s\">#%s</a>\n" "./$1" "$1" } print_atom_head() { @@ -74,7 +78,7 @@ EOF print_atom_link() { cat << EOF <entry> - <title type="text">$1</title> + <title type="text">$(xml_escape "$1")</title> <link href="$2"></link> <id>$2</id> <author> @@ -94,7 +98,7 @@ print_atom_tail() { # main mkdir -p $site -touch ./db.tsv +touch $db rm -f $site/*.html $site/atom.xml [[ -f $config ]] && source "$config" @@ -107,17 +111,27 @@ rm -f $site/*.html $site/atom.xml print_html_head "" > $site/index.html print_atom_head > $site/atom.xml +echo "<h1>${PLANNER_URL##https://}</h1>" >> $site/index.html + +[[ -f ./index.md ]] && { + echo "<div class=\"planner-desc\">" + markdown ./index.md + echo "</div>" +} >> $site/index.html + +true > $site/bookmarks.txt + while read -r line; do - link=$(cut -f2 <<< "$line") - tags=$(cut -s -f3 <<< "$line") - title=$(cut -s -f4- <<< "$line") + link=$(cut -d, -f2 <<< "$line") + tags=$(cut -s -d, -f3 <<< "$line") + title=$(cut -s -d, -f4- <<< "$line") class="linktitle read" - date=$(grep "$link" ./db.tsv | cut -f1) + date=$(grep "$link" $db | cut -d, -f1) [[ -z $date ]] && date=$builddate if [[ -z $title ]]; then - title=$(grep "$link" ./db.tsv | cut -f4-) + title=$(grep "$link" $db | cut -d, -f4-) [[ -z $title && $offline == false ]] && { printf "getting title for %s...\n" "$link" >&2 @@ -127,75 +141,81 @@ while read -r line; do | head -1 \ | sed -e 's/^.*<title>//' -e 's/<\/title>.*$//') - printf "\t%s\n" "$title" >&2 + printf ",%s\n" "$title" >&2 } [[ -z $title ]] && { title="$(sed -e 's/http.:\/\///' -e 's/\/.*$//' <<< "$link")" title="⛷ $title" - printf "\t%s\n" "$title" >&2 + printf ",%s\n" "$title" >&2 } fi - printf "%s\t%s\t%s\t%s\n" "$date" "$link" "$tags" "$title" >> "$tmp" + printf "%s,%s,%s,%s\n" "$date" "$link" "$tags" "$title" >> "$tmp" grep -q "read" <<< "$tags" && { title="⛟ $title" class="linktitle unread" } - grep -q "$link" ./db.tsv || { + grep -q "$link" $db || { echo "$title" class="new $class" } - true > $site/link.html + true > $site/link_build.html - print_html_link_head "$title" "$link" "$class" >> $site/link.html + print_html_link_head "$title" "$link" "$class" >> $site/link_build.html for tag in $tags; do [[ $tag == read ]] && continue - print_html_link_tag "$tag" >> $site/link.html + print_html_link_tag "$tag" >> $site/link_build.html print_html_link_tag "$tag" >> $site/tags_build.html done - print_html_link_tail >> $site/link.html + print_html_link_tail >> $site/link_build.html for tag in $tags; do - cat $site/link.html >> $site/"${tag}_build.html" + cat $site/link_build.html >> $site/"${tag}_build.html" done - cat $site/link.html >> $site/index.html + cat $site/link_build.html >> $site/index.html print_atom_link "$title" "$link" "$date" >> $site/atom.xml -done < "${1:-/dev/stdin}" -rm $site/link.html + echo "$link" >> $site/bookmarks.txt +done < "${1:-/dev/stdin}" -print_html_tail >> $site/index.html print_atom_tail >> $site/atom.xml -print_html_head "tags" > $site/tags.html - { printf " <div class=\"tags\">" sort -u -r $site/tags_build.html printf " </div>" -} >> $site/tags.html +} > $site/tags_build.html.tmp -print_html_tail >> $site/tags.html +mv $site/tags_build.html.tmp $site/tags_build.html +cat $site/tags_build.html >> $site/index.html -rm $site/tags_build.html +print_html_tail >> $site/index.html -mv "$tmp" ./db.tsv +mv "$tmp" $db for file in $site/*; do [[ $file != *_build.html ]] && continue tag=$(sed -e "s/$site\///" -e 's/_build.html//' <<< "$file") - print_html_head "$tag" > $site/"$tag.html" - cat "$file" >> $site/"$tag.html" - print_html_tail >> $site/"$tag.html" + mkdir -p $site/$tag + print_html_head "$tag" > $site/$tag/index.html + cat <<EOF >> $site/$tag/index.html + <h1> + <a href="$PLANNER_URL">${PLANNER_URL##https://}</a>#$tag + </h1> +EOF + cat "$file" >> $site/$tag/index.html + cat $site/tags_build.html >> $site/$tag/index.html + print_html_tail >> $site/$tag/index.html + cp ./style.css $site/$tag/ done rm $site/*_build.html diff --git a/style.css b/style.css @@ -1,11 +1,10 @@ body { - width: 50em; + max-width: 50em; margin: 0 auto; line-height: 1.4em; margin-top: 8em; margin-bottom: 4em; font-family: Tahoma, Verdana, Arial, sans-serif; - text-align: center; } h1 { @@ -29,23 +28,14 @@ h3 { } .header { - position: fixed; - left: 0; - top: 0; width: 100%; background-color: white; - text-align: center; } .footer { - position: fixed; - margin: 0 auto; - bottom: 0; line-height: 1.6em; - width: 50em; background-color: white; padding: 0.4em; - text-align: center; color: black; } @@ -90,10 +80,6 @@ a.link:hover { text-decoration: none; } -.tags { - text-align: center; -} - .tag:hover { color: purple; } diff --git a/todo.txt b/todo.txt @@ -1,3 +1,3 @@ -- [x] add public/private bookmarks -- [x] add sites for tags -- [x] newest first +x add public/private bookmarks +x add sites for tags +x newest first