dot

packages and services management
Log | Files | Refs | README

commit e315d96cecde390ab6b76e773ae9a62fa5ecbda7
parent e525c874445c5ce935f8c529034ab74fbb3dc52c
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 27 Nov 2017 01:59:23 +0100

first working version

Diffstat:
Mbin/gph-html | 42++++++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/bin/gph-html b/bin/gph-html @@ -1,6 +1,12 @@ #!/bin/sh # convert all *.gph in current directory to html +HEAD='<!doctype html> +<link rel="stylesheet" href="/style.css" type="text/css"/> +<link rel="icon" href="/favicon.png" type="image/png"/> +<meta charset="utf-8"> +' + awk=' function escape(str) @@ -12,15 +18,17 @@ function escape(str) return str; } -function url(tail) +function url(gph, tail) { split(tail, fields, "|"); path = fields[2]; host = fields[3]; port = fields[4]; - if (host == "server") + if (host == "server" || host == "") host = ""; - if (port == "port") + else if (gph) + host = "http://" host; + if (port == "port" || port == "") port = ""; else port = ":" port; @@ -30,39 +38,42 @@ function url(tail) function link(type, tail) { sub("\\]$", "", tail); - addr = url(tail); + addr = url(type == "file" || type == "dir/", tail); desc = tail; sub("\\|.*", "", desc); - return sprintf("<a href=\"%s\">%-4s</a>+ %s", addr, type, escape(desc)); + return sprintf("<a href=\"%s\">[%s]</a> %s", addr, type, escape(desc)); } -BEGIN { +FNR == 1 { + sub("/[^/]*$", "", FILENAME); + sub(".*/", "", FILENAME); print("<pre>"); + printf("<h1>%s</h1>\n", FILENAME); } sub("^t", "") { - print(" | " escape($0)); + print(" " escape($0)); next; } sub("^\\[i\\|", "") { sub("\\|.*", "", $0); - print(" | " escape($0)); + print(" " escape($0)); next; } sub("^\\[0\\|", "") { - print(link("File", $0)); + print(link("file", $0)); next; } sub("^\\[1\\|", "") { - print(link("Dir", $0)); + print(link("dir/", $0)); next; } sub("^\\[8\\|", "") { - print(link("Tnet", $0)); + print(link("tnet", $0)); next; } @@ -74,14 +85,14 @@ sub("^\\[h\\|", "") { sub("^\\[g\\|", "") || sub("^\\[I", "") { sub("\\]$", "", $0); desc = $0; - addr = url($0); + addr = url(1, $0); sub("\\|.*", "", desc); printf("<img alt=\"%s\" src=\"%s\"/>", escape(desc), addr); next; } { - print(" | " escape($0)); + print(" " escape($0)); next } @@ -89,4 +100,7 @@ END { print("</pre>"); }' -find "$1" -name '*.gph' -exec sh -c "awk '$awk' "'"$0" > "${0%.gph}.html"' {} ';' +find "$1" -name '*.gph' -exec sh -c ' + printf "%s\\n" '"'$HEAD'"' > "${0%.gph}.html" + awk '"'$awk'"' "$(cd "${0%/*}" && pwd)/${0##*/}" >> "${0%.gph}.html" +' {} ';'