From b4f9be57d3afbe19970bb268ecb6723cd80e703e Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 9 Jun 2026 16:11:06 +0100 Subject: http: builds blogs from gemlogs --- http/bin/gmi2upphtml | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100755 http/bin/gmi2upphtml (limited to 'http/bin/gmi2upphtml') diff --git a/http/bin/gmi2upphtml b/http/bin/gmi2upphtml new file mode 100755 index 0000000..608f4e8 --- /dev/null +++ b/http/bin/gmi2upphtml @@ -0,0 +1,176 @@ +#!/bin/sh -e + +post_title="${1:-}" + +is_in_list=0 +is_in_link_block=0 +is_in_preformatted_block=0 +is_in_blockquote=0 + +if_in_list_then_close() +{ + if [ $is_in_list -ne 0 ] + then + echo "" + is_in_list=0 + fi +} + +if_in_link_block_then_close() +{ + if [ $is_in_link_block -ne 0 ] + then + echo "

" + is_in_link_block=0 + fi +} + +if_in_preformatted_block_then_close() +{ + if [ $is_in_preformatted_block -ne 0 ] + then + echo "" + is_in_preformatted_block=0 + fi +} + +if_in_blockquote_then_close() +{ + if [ $is_in_blockquote -ne 0 ] + then + echo "" + is_in_blockquote=0 + fi +} + +close_all_open_blocks() +{ + if_in_list_then_close + if_in_link_block_then_close + if_in_preformatted_block_then_close + if_in_blockquote_then_close +} + +escape_upphtml() +{ + echo "$1" | sed "s/\`/\\\\\`/g" | sed "s/\"/\\\\\"/g" | sed "s/\\\$/\\\\\$/g" +} + +close_all_open_blocks_except() +{ + except="$1" + if [ "$except" != "list" ] + then + if_in_list_then_close + fi + if [ "$except" != "link" ] + then + if_in_link_block_then_close + fi + if [ "$except" != "pre" ] + then + if_in_preformatted_block_then_close + fi + if [ "$except" != "blockquote" ] + then + if_in_blockquote_then_close + fi +} + +if [ -z "$post_title" ] +then + read first_line + if [ "$(echo "$first_line" | cut -c1-2)" != "# " ] + then + echo >&2 "Error: no [post_title] argument provided and no top-level heading at top of the document." + exit 1 + fi + post_title="${first_line### }" +fi + +echo "#! +export TITLE=\"${post_title} | joeac's blog\" +export DESCRIPTION=\"${post_title} | joeac's blog\" +pp \"\${SHARE}\"/components/meta.upphtml +#!" + +while read line +do + if [ "$(echo $line | sed "s/[[:space:]]//g")" = "" ] + then + continue + fi + + if [ "$(echo $line | cut -c1)" = "#" ] + then + title="$(escape_upphtml "${line#*# }")" + heading="${line%%$title}" + heading="${heading%% }" + heading_level="${#heading}" + if [ "$(echo "$line" | cut -c$(( $heading_level + 1 )) )" = " " ] + then + close_all_open_blocks + echo "${title}" + continue + fi + fi + + if [ "$(echo "$line" | cut -c1-2)" = "=>" ] + then + close_all_open_blocks_except link + href="$(escape_upphtml "$(echo "$line" | sed "s/^=>[[:space:]]*\([[:alnum:][:punct:]]\+\).*$/\1/")")" + title="$(escape_upphtml "$(echo "$line" | sed "s/^=>[[:space:]]*[[:alnum:][:punct:]]\+[[:space:]]\(.*\)$/\1/")")" + if [ $is_in_link_block -eq 0 ] + then + echo "

" + else + echo "
" + fi + is_in_link_block=1 + echo "=> ${title}" + continue + fi + + if [ "$( echo "$line" | cut -c1-2)" = "* " ] + then + close_all_open_blocks_except list + if [ $is_in_list -eq 0 ] + then + echo "