shite

rc static blog generator
git clone git://git.2f30.org/shite
Log | Files | Refs | README

commit a5eeb08dd55a536bb044d8e066f001764c4a725d
Author: dsp <dsp@2f30.org>
Date:   Tue,  5 Apr 2022 09:17:01 +0000

initial import

Diffstat:
AREADME | 47+++++++++++++++++++++++++++++++++++++++++++++++
Acontent/home | 3+++
Acontent/post-1 | 1+
Acontent/post-2 | 1+
Apostdb | 18++++++++++++++++++
Ashite | 263+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 333 insertions(+), 0 deletions(-)

diff --git a/README b/README @@ -0,0 +1,47 @@ +shite +An rc shtatic html/gemini blog generator. + +Usage: + ./shite {init, mk, clean} + +Tune the baseurl, blogtitle, css variables in +the shite script, and modify postdb and content/ +with the data you want to serve. + +This script reads a postdb file formatted as per ndb(6). It then +creates indexing files that associate the fields. +These files are used in automatically creating post navigation +pages by id and tag, as well as a navbar + +An example postdb file contains entries like + +type=post + id=1 + title="a test title" + date=2021-04-15 + tag=tag1 tag=tag2 + content="content/post-test" + +type=page + title="home" + content="content/home" + +It describes a site consisting of a home page, a blog +page that contains one entry, as well as navigation pages +based on post titles and tags. + +The files it would create in the current directory are +ids, tags, titles, id_content, id_title, tag_id, title_content + +content files should be plain text as they are just appended +between hardcoded headers and footers. + +Depending on the setting the HTML_BASE and/or GEMINI_BASE +variables in the mkshite script it generates under publish/ +the final static sites that you can upload to your web/gem +servers. + +All code is Public Domain. +DsP <dsp 47 2f30.org> + + diff --git a/content/home b/content/home @@ -0,0 +1,3 @@ + +Sample home +... diff --git a/content/post-1 b/content/post-1 @@ -0,0 +1 @@ +post 1 content diff --git a/content/post-2 b/content/post-2 @@ -0,0 +1 @@ +post 2 content diff --git a/postdb b/postdb @@ -0,0 +1,18 @@ +type=post + id=1 + title="test title 1" + date=2021-10-7 + tag=tag1 tag=tag2 + content="content/post-1" +type=post + id=2 + title="test title 2" + date=2021-10-8 + tag=tag3 tag=tag2 + content="content/post-2" +type=page + title="home" + content="content/home" + + + diff --git a/shite b/shite @@ -0,0 +1,263 @@ +#!/bin/rc +# +#the shite database file +sdb=postdb + +#if any of the base strings are not empty it will generate output +#of that type in the publish/ subdirectory +HTML_BASE=https://baseurl +GEMINI_BASE=gemini://baseurl + +#a title that will be used in the html/gmi headers +BLOG_TITLE=someblog + +#we start by setting URL with correct BASEs +homeURLhtml=$HTML_BASE/home.html +postsURLhtml=$HTML_BASE/posts.html +tagsURLhtml=$HTML_BASE/tags.html +homeURLgem=$GEMINI_BASE/home.gmi +postsURLgem=$GEMINI_BASE/posts.gmi +tagsURLgem=$GEMINI_BASE/tags.gmi +postURLbase=post/ + +#takes two parameters (date/tag and id/content) and then creates +#two files. one is named as the first parameter with a final s +#and the other has the association of that parameter with +#the second parameter type. +#There is a final parameter that if it is equal to "uniq" +#it only keeps distinct vals from the first column. +fn join { + #here we will split es on space normally (tags and ids are separated by one) + if (~ $3 uniq) es=`{ndb/query -a -f $sdb type post $1 | sort | uniq} + if not { + #here we are splitting on newline (literally as i discovered) + #since titles can contain spaces. + es=`' +'{ndb/query -a -f $sdb type post $1} + } + cat /dev/null > $1^s + cat /dev/null > $1^_^$2 + for (e in $es) { + echo $e >> $1^s + joined =`{ndb/query -a -f $sdb $1 $e $2} + echo $e $joined >> $1^_^$2 + } +} + +fn GemHeader { + echo '# '$BLOG_TITLE'->'$1 +} + +fn GemFooter { + echo '- - - - - - - - -' + if (! ~ HTML_BASE '') { + echo 'This content is also hosted over ' + echo '=> '$HTML_BASE' http' + } +} + +fn GemMenu { + echo '## navigate' + echo '=> '$homeURLgem' home' + echo '=> '$postsURLgem' posts' + echo '=> '$tagsURLgem' tags' +} + +fn HTMLHeader { + echo '<html>' + echo '<head> <link rel="stylesheet" type="text/css" href="'$HTML_BASE'/css/dsp.css"></head>' + echo '<title>'$BLOG_TITLE'->'$1'</title>' + echo '<body>' +} + +fn HTMLMenu { + echo '<div id="navbar">' + echo '<a href="'^$homeURLhtml^'">home</a> | <a href="'^$postsURLhtml^'">posts</a> | <a href="'^$tagsURLhtml^'">tags</a><br>' + echo '- - - - - - - - -<br>' + echo '</div>' +} + +fn HTMLFooter { + echo '- - - - - - - - -<br>' + if (! ~ GEMINI_BASE '') { + echo 'This content is also hosted over <a href="'$GEMINI_BASE'"> gemini </a><br>' + } + echo '</body>' + echo '</html>' +} + + +fn mkgenpages { + es=`' +'{ndb/query -a -f $sdb type page} + for (e in $es) { + title=`{echo $e | sed 's/.*title=//' | sed 's/ .*//g'} + content=`{echo $e | sed 's/.*content=//' | sed 's/ .*//g'} + if (! ~ $HTML_BASE '') { + out='publish/html/'$title'.html' + HTMLHeader $"title > $out + HTMLMenu >> $out + echo '<pre>' >> $out + cat $content >> $out + echo '</pre>' >> $out + HTMLFooter >> $out + } + if (! ~ $GEMINI_BASE '') { + out='publish/gmi/'$title'.gmi' + GemHeader $"title > $out + GemMenu >> $out + cat $content >> $out + GemFooter >> $out + } + } +} + +fn mktaglist { + if (! ~ $HTML_BASE '') { + out=publish/html/tags.html + HTMLHeader tags > $out + HTMLMenu >> $out + echo '<h1> Tag Listing </h1>' >> $out + tagid=`' + '{cat tag_id} + for (t in $tagid) { + tag=`{echo $t | sed 's/ .*//'} + ids=`{echo $t | sed 's/^[a-zA-Z0-9]+ //'} + echo '<h2> '^$tag^' </h2>' >> $out + echo '<ul>' >> $out + for (id in $ids) { + title=`{grep '^'$id id_title|sed 's/^[0-9] //'} + datestr=`{ndb/query -a -f $sdb id $id date} + echo '<li><a href="'$HTML_BASE^'/'^$postURLbase^$id'.html">['$id':'$datestr':'$"title']</a></li>' >> $out + echo >> $out + } + echo '</ul>' >> $out + } + HTMLFooter >> $out + } + if (! ~ $GEMINI_BASE '') { + out=publish/gmi/tags.gmi + GemHeader tags > $out + GemMenu >> $out + echo '# Tag Listing ' >> $out + tagid=`' + '{cat tag_id} + for (t in $tagid) { + tag=`{echo $t | sed 's/ .*//'} + ids=`{echo $t | sed 's/^[a-zA-Z0-9]+ //'} + echo '## '$tag >> $out + for (id in $ids) { + title=`{grep '^'$id id_title|sed 's/^[0-9] //'} + datestr=`{ndb/query -a -f $sdb id $id date} + echo '=>'$GEMINI_BASE^'/'^$postURLbase^$id'.gmi ['$id':'$datestr':'$"title']' >> $out + } + } + GemFooter >> $out + } + +} + +fn mkpostlist { + if (! ~ $HTML_BASE '') { + out=publish/html/posts.html + HTMLHeader posts > $out + HTMLMenu >> $out + echo '<h1> Post Listing </h1>' >> $out + echo '<div id="postlist">' >> $out + echo '<ol>' >> $out + idtitle=`' +'{cat id_title} + for (i in $idtitle) { + id=`{echo $i | sed 's/ .*//'} + title=`{echo $i | sed 's/^[0-9] //'} + datestr=`{ndb/query -a -f $sdb id $id date} + echo '<li><a href='^$HTML_BASE^'/'^$postURLbase^$id'.html>['$id':'$datestr'] '$"title'</a></li>' >> $out + } + echo '</ol>' >> $out + echo '</div>' >> $out + HTMLFooter >> $out + } + if (! ~ $GEMINI_BASE '') { + out=publish/gmi/posts.gmi + GemHeader posts > $out + GemMenu >> $out + echo '# Post Listing' >> $out + idtitle=`' +'{cat id_title} + for (i in $idtitle) { + id=`{echo $i | sed 's/ .*//'} + title=`{echo $i | sed 's/^[0-9] //'} + datestr=`{ndb/query -a -f $sdb id $id date} + echo '=>'^$GEMINI_BASE^'/'^$postURLbase^$id'.gmi ['$id':'$datestr'] '$"title >> $out + } + GemFooter >> $out + } +} + +#expects a post content formatted line like +#number path +fn mkpost { + id=$1 + title=$2 + content=$3 + if (! ~ $HTML_BASE '') { + out=publish/html/post/$id.html + HTMLHeader $"title > $out + HTMLMenu >> $out + echo '<h1>'^$"title^'</h1>' >> $out + echo '<div type=''post''>' >> $out + echo '<pre>' >> $out + cat $content >> $out + echo '</pre>' >> $out + echo '</div>' >> $out + HTMLFooter >> $out + } + if (! ~ $GEMINI_BASE '') { + out=publish/gmi/post/$id.gmi + GemHeader $"title > $out + GemMenu >> $out + echo '# '^$"title >> $out + cat $content >> $out + GemFooter >> $out + } +} + +#mkallposts extracts the title content and id and passes +#them to mkpost +fn mkallposts { + if (! test -d publish/html) + mkdir -p publish/html/post + postcontent=`' +'{cat id_content} + for (p in $postcontent) { + id=`{echo $p | sed 's/ .*//'} + title=`{grep '^'$id id_title | sed 's/^[0-9] //'} + content=`{echo $p | sed 's/^[0-9] //'} + mkpost $id $"title $content + } +} + +if (~ $1 'mk') { + #this will create tags and tag_id + join tag id uniq + #get all titles and contents + join title content + #get id and title + join id title + #id with content + join id content + mkallposts + mkpostlist + mktaglist + mkgenpages +} +if (~ $1 'init') { + touch postdb + mkdir -p content + mkdir -p publish/html/^$postURLbase + mkdir -p publish/gmi/^$postURLbase +} +if (~ $1 'clean') { + rm -r publish + rm ids titles id_content id_title tag_id tags title_content +}