Compare commits

..

5 Commits

Author SHA1 Message Date
vilmibm 64b434986b link handling 2022-05-28 01:23:50 +01:00
vilmibm 5b6c1d3beb gemini 2022-05-28 01:06:06 +01:00
vilmibm 74a9e407dd gopher 2022-05-28 01:00:51 +01:00
vilmibm 4fc74f5222 reduce go program in scope to just do the link processing 2022-05-28 00:30:51 +01:00
vilmibm 1fb18f9f9f make runnable locally 2022-05-23 09:34:25 -05:00
3 changed files with 115 additions and 28 deletions

83
main.go 100644
View File

@ -0,0 +1,83 @@
package main
import (
_ "embed"
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"regexp"
"strings"
)
func _main(o opts) error {
t, err := ioutil.ReadAll(o.In)
if err != nil {
return fmt.Errorf("could not read from stdin: %w", err)
}
r := regexp.MustCompile(`\(LINK ([^ ]+?) (.+?)\)`)
mms := r.FindAllSubmatch(t, -1)
if mms == nil {
fmt.Fprintf(o.Out, string(t))
return nil
}
output := string(t)
footer := ""
for ix, ms := range mms {
rawLink := string(ms[0])
link := string(ms[1])
title := string(ms[2])
switch o.Mode {
case "html":
output = strings.ReplaceAll(output, rawLink,
fmt.Sprintf("<a href=\"%s\">%s</a>", link, title))
case "gopher":
output = strings.ReplaceAll(output, rawLink, fmt.Sprintf("%s[%d]", title, ix))
linkType := "i"
if strings.HasPrefix(link, "http") {
linkType = "h"
}
footer += fmt.Sprintf("%s[%d]: %s %s\n", linkType, ix, title, link)
case "gemini":
output = strings.ReplaceAll(output, rawLink, fmt.Sprintf("%s[%d]", title, ix))
footer += fmt.Sprintf("=> %s [%d]: %s\n", link, ix, title)
}
}
if footer != "" {
output = output + "\n\n" + footer
}
fmt.Fprintf(o.Out, output)
return nil
}
type opts struct {
In io.Reader
Out io.Writer
Mode string
}
func main() {
var modeFlag = flag.String("mode", "", "one of html, gopher, gemini.")
flag.Parse()
if *modeFlag == "" || (*modeFlag != "html" && *modeFlag != "gopher" && *modeFlag != "gemini") {
fmt.Fprintln(os.Stderr, "--mode must be specified and one of: html, gopher, gemini")
os.Exit(1)
}
o := opts{
In: os.Stdin,
Out: os.Stdout,
Mode: *modeFlag,
}
if err := _main(o); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(2)
}
}

50
make.sh
View File

@ -1,26 +1,31 @@
#!/bin/bash
set -e
# global
pd=/usr/bin/pandoc
g=/bin/grep
tr=/usr/bin/tr
sed=/bin/sed
sort=/usr/bin/sort
postDir=/home/vilmibm/blog/posts
mkdir -p "${HOME}/public_gopher/blog" > /dev/null
mkdir -p "${HOME}/public_gemini/blog" > /dev/null
mkdir -p "${HOME}/public_html/blog" > /dev/null
htmlDir=/home/vilmibm/public_html/blog
htmlIndexTmpl=/home/vilmibm/blog/index.tmpl.html
htmlIndex=/home/vilmibm/public_html/blog/index.html
srcDir=$HOME/blog
postDir=$srcDir/posts
gopherPath=/home/vilmibm/public_gopher/blog
htmlIndexTmpl=$srcDir/index.tmpl.html
htmlDir=$HOME/public_html/blog
htmlIndex=$HOME/public_html/blog/index.html
gopherPath=$HOME/public_gopher/blog
gopherIndex="${gopherPath}/gophermap"
geminiPath=/home/vilmibm/public_gemini/blog
geminiPath=$HOME/public_gemini/blog
geminiIndex="${geminiPath}/index.gmi"
cd $postDir > /dev/null
# attempt compilation
if [ ! -e "linkpost" ]
then
go build -o linkpost main.go
fi
lp="$(pwd)/linkpost"
# backup HTML index
if [ -e "${htmlIndex}" ]
@ -31,7 +36,7 @@ fi
cp $htmlIndexTmpl $htmlIndex
# Remove old gopher posts
rm ${gopherPath}/*
rm -f ${gopherPath}/*
# Initialize blog gophermap
echo "!the phlog of vilmibm as it were" > $gopherIndex
@ -41,11 +46,13 @@ echo >> $gopherIndex
echo "the gemblog of vilmibm as it were" > $geminiIndex
echo >> $geminiIndex
for p in $(ls *.md | $sort -r)
cd $postDir > /dev/null
for p in $(ls *.md | sort -r)
do
pubdate=$($g "pubdate:" $p | $sed 's/pubdate: //')
title=$($g "title:" $p | $sed 's/title: //')
slug=$($g "slug:" $p | $sed 's/slug: //' | $tr -d \[:blank:\])
pubdate=$(grep "pubdate:" $p | sed 's/pubdate: //')
title=$(grep "title:" $p | sed 's/title: //')
slug=$(grep "slug:" $p | sed 's/slug: //' | tr -d \[:blank:\])
if [ -z "$pubdate" ] || [ -z "$title" ] || [ -z "$slug" ]
then
echo "warning: missing at least one of: pubdate, slug, title in ${p}"
@ -54,16 +61,17 @@ do
echo "<h2 class=\"title\">${title}</h2>" >> $htmlIndex
echo "<a class=\"pubdate\" name=\"${slug}\" href=\"https://tilde.town/~vilmibm/blog#${slug}\">${pubdate}</a>" >> $htmlIndex
echo "<div class=\"post\">" >> $htmlIndex
$g -v "pubdate:" $p | $g -v "title:" | $g -v "slug:" |$pd -fmarkdown -thtml >> $htmlIndex
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" | $lp --mode "html" | pandoc -fmarkdown -thtml >> $htmlIndex
echo "</div>" >> $htmlIndex
# Gopher
echo "0${title} ${slug}.txt" >> $gopherIndex
gopherPostPath="${gopherPath}/${slug}.txt"
echo "# ${title}" > $gopherPostPath
echo >> $gopherPostPath
echo "_published ${pubdate}_" >> $gopherPostPath
$g -v "pubdate:" $p | $g -v "title:" | $g -v "slug:" >> $gopherPostPath
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" | $lp --mode "gopher" >> $gopherPostPath
# Gemini
echo "=> gemini://tilde.town/~vilmibm/blog/${slug}.gmi ${title}" >> $geminiIndex
@ -71,7 +79,7 @@ do
echo "# ${title}" > $geminiPostPath
echo >> $geminiPostPath
echo "_published ${pubdate}_" >> $geminiPostPath
$g -v "pubdate:" $p | $g -v "title:" | $g -v "slug:" >> $geminiPostPath
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" | $lp --mode "gemini" >> $geminiPostPath
fi
done

View File

@ -6,19 +6,15 @@ I made a blog. I haven't had one in years. When I did it was mostly for dream lo
Another reason I'm making one of these again is self-actualization. Historically I've thought very poorly of myself and agonized over anyone actually caring what I posted. Now, I'm just excited to share whatever I'm excited about or mentally chewing on, not out of self-aggrandizement, but because the stuff I find interesting is interesting because I find it interesting. It's a very cozy tautology. I'm not interested in building a following or crafting a brand: just sharing what inspires me in an honest way while still keeping some of myself to myself.
Finally, I like to mark time with the discovery of artifacts. I'm always hunting for inspiring things--books, sites, objects, people--and feel an urge to catalogue them so I can be re-inspired in the future. I post on social media about these things sometimes, but social media is uniquely unsuited to reflection and later perusal. I liked Tumblr for this to an extent but never got comfy posting there; too many numbers and buttons and noise there for me to feel like I could collect my thoughts or feel like I was posting for myself instead of a hypothetical audience that might "like" something. I also don't like being beholden to corporate platforms.
Finally, I like to mark time with the discovery of artifacts. I'm always hunting for inspiring things--books, sites, objects, people--and feel an urge to catalogue them so I can be re-inspired in the future. I post on social media about these things sometimes, but social media is uniquely unsuited to reflection and later perusal. I liked Tumblr for this to an extent but never got comfy posting there; too many numbers and buttons and noise there for me to feel like I could collect my thoughts or feel like I was posting for myself instead of a hypothetical audience that might "like" something. I also don't like being beholden to (LINK https://twitter.com/nate_smith corporate platforms).
Some initial posting fodder:
* Going through a decade's worth of unsorted bookmarks and posting interesting finds
* Reviews or pre-reviews of 1990s primary "cyber media" that I collect like old academic books on hypertext culture and trashy web magazines
* Reporting on 1990s primary "cyber media" that I collect like academic books on hypertext and trashy web magazines
* Project ideas that I'll never get to
* Project ideas that I have gotten to
* My "religious" interests in Discordianism and Hermeticism
* Fiction/poetry/essays
Technically speaking, this is all powered by some markdown files with custom metadata embedded in it and a <100 line bash script(0).
TODO: decide on link formatting/processing. Considering a (LINK _url with protocol_ _title_) macro that either replaces with anchor tag for html or creates a footnote link in gopher or gemini style.
=> https://git.tilde.town/vilmibm/blog/src/branch/trunk/make.sh 0: this blog's bash script
Technically speaking, this is all powered by some markdown files with custom metadata embedded in it, a <100 line bash script, and a Go program for handling a little linking macro. I wanted to be able to author links in a consistent way but have sensible renderings in HTML, Gemini, and Gopher. All of this, including posts, can be found in (LINK https://git.tilde.town/vilmibm/blog this repository). I considered a static site generator...but I prefer scripting my own thing wrt blogging. It keeps me humble and I find that I don't use most of the features of off the shelf things.