#!/usr/bin/awk -f # originally from gemini://hubbz.de/en/floss/2021-02-13-convert-gemini-text-to-html.gmi # licenced under the MIT license # the string in the BEGIN statement is modified to link to my stylesheet, to # add a page title, and to add navigation links. the link parsing function has # been modified to automatically rewrite images to be inline and to # automatically fix non-relative links (i.e. links to /example will be # rewritten to /gemini/example). the END statement has been modified to add a # footer telling the reader what gemini is and suggesting to browse with a real # browser. BEGIN { print "\n\ \n\ \n\ \n\ \n\ \n\ nytpu's gemini capsule\n\ \n\ \n\ ↩ exit my gemini capsule
↑ go up one directory (to parent)


\n" in_pre = 0; in_list = 0; } !in_pre && /^```/ { in_pre = 1; if (in_list) { in_list = 0; print(""); } print "
";
	next
}
in_pre && /^```/    { in_pre = 0; print "
"; next } in_pre { print san($0); next } /^###/ { output("

", substr($0, 4), "

"); next } /^##/ { output("

", substr($0, 3), "

"); next } /^#/ { output("

", substr($0, 2), "

"); next } /^>/ { output("
", substr($0, 2), "
"); next } /^\*/ { output("
  • ", substr($0, 2), "
  • "); next } /^=>/ { $0 = substr($0, 3); link = $1; $1 = ""; output_link(link, $0); next; } // { output("

    ", $0, "

    "); next } END { if (in_list) print "" if (in_pre) print "" print "

    \n\ This site is significiantly improved by visiting through Gemini.
    \n\ What is Gemini?
    \n\ You need a Gemini client. \ Here's a list, \ but I personally recommend Lagrange\n" print "\n" } function trim(s) { sub("^[ \t]*", "", s); return s; } function san(s) { gsub("&", "\\&", s) gsub("<", "\\<", s) gsub(">", "\\>", s) return s; } function output(ot, content, ct) { content = trim(content); if (!in_list && ot == "
  • ") { in_list = 1; print ""; } if (ot == "

    " && content == "") return; printf("%s%s%s\n", ot, san(content), ct); } function output_link(link, content) { if (in_list) { in_list = 0; print ""; } # If it's a local gemini file, link to the html: if((link !~ /^[a-zA-Z]*:\/\//) && (link ~ /\.gmi$/)){ sub(/\.gmi$/, ".html", link) } # if it's an absolute link (i.e. "/folder/file.gmi") be sure to prepend the proper web directory if(link ~ /^\//){ link = "/gemini" link } if(link ~ /\.(png|jpg|webp)$/){ printf("

    %s

    \n", link, link, trim(san(content))); }else{ if (content == "") content = link; printf("⮩ %s
    \n", link, trim(san(content))); } }