phlog

Source code for my blog/gemlog. It used to be on gopher, hence the name
git clone http://shtanton.xyz/git/repo/phlog
Log | Files | Refs

commit 6c39ca53c836105518ffc5c7c953b9079bce5777
parent eb6f56d036f050bcffe0e9dc92dbb4d023801a56
Author: Charlie Stanton <charlie@shtanton.xyz>
Date:   Fri, 14 Oct 2022 19:01:53 +0100

Switches to a new templating system using mustach and jq

Diffstat:
MMakefile | 35++++++++++++++++++++++-------------
Mgemini_src/index.gmi | 2+-
Agemini_src/posts/index.gmi.mustache | 3+++
Dgemini_src/posts/index.sh | 3---
Mhtml_src/index.html | 1+
Ahtml_src/nav.html.mustache | 3+++
Dhtml_src/nav_html.sh | 4----
Ahtml_src/posts/index.html.mustache | 12++++++++++++
Dhtml_src/posts/index.sh | 12------------
Dhtml_src/posts/index_template.html | 12------------
Dhtml_src/posts/post_html.sh | 23-----------------------
Dhtml_src/posts/post_template.html | 25-------------------------
Ahtml_src/posts/post_template.html.mustache | 25+++++++++++++++++++++++++
Dhtml_src/rss.sh | 12------------
Ahtml_src/rss.xml.mustache | 13+++++++++++++
Dhtml_src/rss_items.sh | 13-------------
Dhtml_src/rss_template.xml | 8--------
Aposts-config.json | 29+++++++++++++++++++++++++++++
18 files changed, 109 insertions(+), 126 deletions(-)

diff --git a/Makefile b/Makefile @@ -9,31 +9,40 @@ GEMINI = $(GEMINI_POSTS) gemini/index.gmi gemini/posts/index.gmi all: html/rss.xml $(WEB) $(GEMINI) -html/rss.xml: posts-config html_src/rss_template.xml $(POSTS:%=posts/%.gmi) html_src/rss.sh html_src/rss_items.sh html_src/rss_template.xml - ./html_src/rss.sh posts-config < html_src/rss_template.xml > $@ +html/rss.xml: posts-config.json html_src/rss.xml.mustache + jq '.posts[] |= (.formattedDate = (.date | strptime("%Y-%m-%d") | strftime("%d %b %y 12:00:00 GMT")))' < posts-config.json | mustach - html_src/rss.xml.mustache > $@ html/%.css: html_src/%.css cp $^ $@ -html_src/nav.html: html_src/nav_html.sh posts-config - $^ > $@ +html_src/nav.html: posts-config.json html_src/nav.html.mustache + mustach posts-config.json html_src/nav.html.mustache > $@ -html/posts/%.html: html_src/posts/post_html.sh posts/%.gmi posts-config html_src/posts/post_template.html html_src/nav.html - $^ $* > $@ +html/posts/%.html: posts/%.gmi html_src/posts/post_template.html.mustache posts-config.json html_src/nav.html + jq\ + --arg content "$$(gmi2html < $<)"\ + --arg nav "$$(tee < html_src/nav.html)"\ + --arg slug '$(<:posts/%.gmi=%)'\ + '.posts[] | select(.slug==$$slug) | (.content |= $$content) | (.nav |= $$nav)'\ + < posts-config.json | mustach - html_src/posts/post_template.html.mustache > $@ -html/posts/index.html: html_src/posts/index.sh html_src/posts/index_template.html html_src/nav.html - $^ > $@ +html/posts/index.html: posts-config.json html_src/posts/index.html.mustache html_src/nav.html.mustache + mustach posts-config.json html_src/posts/index.html.mustache > $@ html/index.html: html_src/index.html cp $^ $@ -gemini/posts/%.gmi: posts/%.gmi - awk -F :: "/^$*::/{print \"# \"\$$2}" posts-config > $@ +gemini/posts/%.gmi: posts/%.gmi posts-config.json + jq\ + -r\ + --arg slug '$*'\ + '.posts[] | select(.slug==$$slug) | ("# " + .name)'\ + < posts-config.json > $@ echo "" >> $@ - tee < $^ >> $@ + tee < $< >> $@ -gemini/posts/index.gmi: gemini_src/posts/index.sh posts-config - $^ > $@ +gemini/posts/index.gmi: posts-config.json gemini_src/posts/index.gmi.mustache + mustach $< > $@ gemini/index.gmi: gemini_src/index.gmi cp $^ $@ diff --git a/gemini_src/index.gmi b/gemini_src/index.gmi @@ -2,4 +2,4 @@ I don't know what I'm doing but hopefully I don't give up on this space. -=> gemini://shtanton.xyz/posts Maybe I've written something on my gemlog recently +=> gemini://shtanton.xyz/posts/ Maybe I've written something on my gemlog recently diff --git a/gemini_src/posts/index.gmi.mustache b/gemini_src/posts/index.gmi.mustache @@ -0,0 +1,3 @@ +# Shtanton's Gemlog +{{#posts}} +=> gemini://shtanton.xyz/posts/{{slug}}.gmi {{date}} - {{name}}{{/posts}} diff --git a/gemini_src/posts/index.sh b/gemini_src/posts/index.sh @@ -1,3 +0,0 @@ -#!/usr/bin/dash -/usr/bin/echo "# Gemlog" -awk -F :: '{print "=> gemini://shtanton.xyz/posts/"$1".gmi "$3" - "$2}' $1 diff --git a/html_src/index.html b/html_src/index.html @@ -10,6 +10,7 @@ <ul> <li><a href="/posts">Blog posts</a></li> <li><a href="/git">Git repos</a></li> + <li><a href="/rss.xml">RSS Feed</a></li> </ul> </body> </html> diff --git a/html_src/nav.html.mustache b/html_src/nav.html.mustache @@ -0,0 +1,3 @@ +<ul>{{#posts}} + <li><a href="/posts/{{slug}}.html">{{name}}</a> - <em>{{date}}</em></li>{{/posts}} +</ul> diff --git a/html_src/nav_html.sh b/html_src/nav_html.sh @@ -1,4 +0,0 @@ -#!/usr/bin/dash -echo "<ul>" -awk -F :: '{print "<li><a href=\"/posts/"$1".html\">"$2"</a> - <em>"$3"</em></li>"}' $1 -echo "</ul>" diff --git a/html_src/posts/index.html.mustache b/html_src/posts/index.html.mustache @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> + <head> + <title>shtanton's blog</title> + <link rel="stylesheet" href="/colours.css"/> + </head> + <body> + <h2>shtanton's Blog</h2> + <h3>Cool people read it on gemini</h3> +{{> html_src/nav.html}} + </body> +</html> diff --git a/html_src/posts/index.sh b/html_src/posts/index.sh @@ -1,12 +0,0 @@ -#!/usr/bin/dash -while read line -do - case $line in - "{nav}") - cat $2 - ;; - *) - echo $line - ;; - esac -done < $1 diff --git a/html_src/posts/index_template.html b/html_src/posts/index_template.html @@ -1,12 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>shtanton's blog</title> - <link rel="stylesheet" href="/colours.css"/> - </head> - <body> - <h2>shtanton's Blog</h2> - <h3>Cool people read it on gemini</h3> -{nav} - </body> -</html> diff --git a/html_src/posts/post_html.sh b/html_src/posts/post_html.sh @@ -1,23 +0,0 @@ -#!/usr/bin/dash -RAW=$(ag --nonumbers "^$5::" $2) -FILE=$1 -TITLE=$(echo $RAW | awk -F :: '{print $2}') -DATE=$(echo $RAW | awk -F :: '{print $3}') - -while read line -do - case $line in - "{header}") - echo "<h2>$TITLE</h2> <em>$DATE</em>" - ;; - "{content}") - gmi2html < $FILE - ;; - "{nav}") - cat $4 - ;; - *) - echo $line - ;; - esac -done < $3 diff --git a/html_src/posts/post_template.html b/html_src/posts/post_template.html @@ -1,25 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>shtanton's blog</title> - <link rel="stylesheet" href="/post.css"/> - <link rel="stylesheet" href="/colours.css"/> - </head> - <body> - <div> - <header> -{header} - </header> - </div> - <div> - <nav> -{nav} - </nav> - </div> - <div> - <article> -{content} - </article> - </div> - </body> -</html> diff --git a/html_src/posts/post_template.html.mustache b/html_src/posts/post_template.html.mustache @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> + <head> + <title>shtanton's blog</title> + <link rel="stylesheet" href="/post.css"/> + <link rel="stylesheet" href="/colours.css"/> + </head> + <body> + <div> + <header> +<h2>{{name}}</h2> <em>{{date}}</em> + </header> + </div> + <div> + <nav> +{{{nav}}} + </nav> + </div> + <div> + <article> +{{{content}}} + </article> + </div> + </body> +</html> diff --git a/html_src/rss.sh b/html_src/rss.sh @@ -1,12 +0,0 @@ -#!/usr/bin/dash -while read line -do - case $line in - "{ITEMS}") - ./html_src/rss_items.sh < $1 - ;; - *) - echo $line - ;; - esac -done diff --git a/html_src/rss.xml.mustache b/html_src/rss.xml.mustache @@ -0,0 +1,13 @@ +<rss version="2.0"> + <channel> + <title>Shtanton's Blog</title> + <link>http://shtanton.xyz</link> + <description>Charlie's blog posts</description>{{#posts}} + <item> + <title>{{name}}</title> + <link>http://shtanton.xyz/posts/{{slug}}.html</link> + <pubDate>{{formattedDate}}</pubDate> + <guid>http://shtanton.xyz/posts/{{slug}}.html</guid> + </item>{{/posts}} + </channel> +</rss> diff --git a/html_src/rss_items.sh b/html_src/rss_items.sh @@ -1,13 +0,0 @@ -#!/usr/bin/dash -while read line -do - ID=$(echo $line | awk -F :: '{print $1}') - TITLE=$(echo $line | awk -F :: '{print $2}') - DATE=$(echo $line | awk -F :: '{print $3}') - echo "<item>" - echo "<title>$TITLE</title>" - echo "<link>http://shtanton.xyz/posts/${ID}.html</link>" - echo "<pubDate>$(date -d $DATE '+%d %b %y 12:00:00 GMT')</pubDate>" - echo "<guid>http://shtanton.xyz/posts/${ID}.html</guid>" - echo "</item>" -done diff --git a/html_src/rss_template.xml b/html_src/rss_template.xml @@ -1,8 +0,0 @@ -<rss version="2.0"> - <channel> - <title>Shtanton's Blog</title> - <link>http://shtanton.xyz</link> - <description>Charlie's blog posts</description> -{ITEMS} - </channel> -</rss> diff --git a/posts-config.json b/posts-config.json @@ -0,0 +1,29 @@ +{ + "posts": [ + { + "slug": "gripes_with_pipes", + "name": "Gripes With Pipes (My non-problems with the shell)", + "date": "2021-09-09" + }, + { + "slug": "domain_specific_languages", + "name": "Domain Specific Languages", + "date": "2021-08-25" + }, + { + "slug": "best_social_media", + "name": "The Best Social Media", + "date": "2021-04-30" + }, + { + "slug": "all_the_protocols", + "name": "All the protocols", + "date": "2020-11-17" + }, + { + "slug": "ex", + "name": "Reviving ex in 2020", + "date": "2020-08-05" + } + ] +}