dot

packages and services management
Log | Files | Refs | README

commit 6ffaf15f7d0eff3fedc694852f37f90add81acc1
parent 366c7c0904b245a04a17ed19662b279948af04bf
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 26 Nov 2017 21:57:34 +0100

gopher to html for managing all my pages through gopher

Diffstat:
Abin/git-gph | 24++++++++++++++++++++++++
Mbin/git-html | 12++++++------
Abin/gph-html | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 110 insertions(+), 6 deletions(-)

diff --git a/bin/git-gph b/bin/git-gph @@ -0,0 +1,24 @@ +#!/bin/sh +# add index.gph and commit/%H inside of a git bare repository + +export LC_COLLATE=C + +NAME=$(cd "$1" && pwd | sed 's|.*/||') + +{ + printf '\n [ %s ]\n\n' "$NAME" + git -C "$1" ls-tree -r --name-only master | sort | sed 's|^| |' + printf '\n\n' + git -C "$1" log --graph --date=short --decorate --tags --stat \ + --branches --remotes | + sed -r -e '/[0-9a-f]{40}/ s/\|/\\&/g' \ + -e 's/.*([0-9a-f]{40}).*/[0|&|\/commit\/\1|server|port]/' +} > "$1/index.gph" + +mkdir -p "$1/commit" +for commit in $(git -C "$1" log --format='%H') +do + [ -f "$1/commit/$commit" ] && continue + printf '%s\n' "$commit" + git -C "$1" show -U3 "$commit" | sed > "$1/commit/$commit" +done diff --git a/bin/git-html b/bin/git-html @@ -6,10 +6,10 @@ export LC_COLLATE=C NAME=$(cd "$1" && pwd | sed 's|.*/||') HEADER="<!doctype html> <title>$NAME</title> -<meta charset="utf-8"/> +<meta charset=\"utf-8\"/> <style> pre { width: 80ch; margin: 4em auto 4em auto; } </style> <pre> -<h1><a href="..">..</a>/$NAME</h1> +<h1><a href=\"..\">..</a>/$NAME</h1> <b>GIT_SMART_HTTP=0 git clone http://git.josuah.net/$NAME</b> " @@ -21,7 +21,7 @@ HEADER="<!doctype html> --branches --remotes | sed -r -e 's|&|\&amp;|g' \ -e 's|<|\&lt;|g' \ - -e 's|([0-9a-f]{8})[0-9a-f]{32}|<a href="commit/&.html">\1</a>|' + -e 's|[0-9a-f]{40}|<a href="commit/&.html">&</a>|' printf '</pre>\n' } > "$1/index.html" @@ -37,8 +37,8 @@ do -e ' s|^[A-Z][a-z]*:|<b>&</b>|' \ -e '/^commit/ s|.*|<b>&</b>|' \ -e '/^diff/ s|.*|<b>&</b>|' \ - -e '/^+/ s|.*|<span style="color: #0f0;">&</span>|' \ - -e '/^-/ s|.*|<span style="color: #f00;">&</span>|' \ - -e '/^@/ s|.*|<span style="color: #00f;">&</span>|' + -e '/^+/ s|.*|<span style="color: #0e0;">&</span>|' \ + -e '/^-/ s|.*|<span style="color: #e00;">&</span>|' \ + -e '/^@/ s|.*|<span style="color: #00e;">&</span>|' printf '</pre>\n' >> "$1/commit/$commit.html" done diff --git a/bin/gph-html b/bin/gph-html @@ -0,0 +1,80 @@ +#!/bin/sh +# convert all *.gph in current directory to html + +find "$1" -name '*.gph' -exec sh -c 'awk '"'"' + +function escape(str) +{ + gsub("&", "\\&amp;", str); + gsub("<", "\\&lt;", str); + gsub(">", "\\&gt;", str); + gsub("\"", "\\&quote;", str); + return str; +} + +function link(type, tail) +{ + path = tail; + desc = tail; + sub("[^|]*\\|", "", path); + sub("URL:", "", path); + sub("\\|.*", "", path); + sub("\\|.*", "", desc); + return sprintf("<a href=\"%s\">%-7s</a> %s", path, type, escape(desc)); +} + +BEGIN { + print("<pre>"); +} + +sub("^t", "") { + print("\t" escape($0)); + next; +} + +sub("^\\[i\\|", "") { + sub("\\|.*", "", $0); + print("\t" escape($0)); + next; +} + +sub("^\\[0\\|", "") { + print(link("file", $0)); + next; +} + +sub("^\\[1\\|", "") { + print(link("dir", $0)); + next; +} + +sub("^\\[8\\|", "") { + print(link("telnet", $0)); + next; +} + +sub("^\\[h\\|", "") { + print(link("link", $0)); + next; +} + +sub("^\\[g\\|", "") || sub("^\\[I", "") { + desc = $0; + path = $0; + sub("[^|]*\\|", "", path); + sub("\\|.*", "", desc); + sub("\\|.*", "", path); + print("<img alt=\"" escape(desc) "\" src=\"" path "\"/>"); + next; +} + +{ + print("\t" escape($0)); + next +} + +END { + print("</pre>"); +} + +'"'"' "$0" > "${0%.gph}.html" ' {} ';'