diff --git a/.gitignore b/.gitignore index 0f0679b..4a7f37d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ generated-template-parts public_html public_gemini +public +gem-cert tmp assets/css/main.min.css xxx-* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..da9f321 --- /dev/null +++ b/Makefile @@ -0,0 +1,98 @@ +export ALLTAGS := $(shell bin/listTags) +ALLBLOGS := $(shell bin/listBlogs all) +STANDALONE := $(subst .md,,$(subst content/,,$(wildcard content/*.md))) +.SECONDEXPANSION: + +.PHONY: blogs tags standalone push-blog push-assets all clean + +#################### +# TEMPLATE PARTS # +#################### + + +tmp/templates/taglist.html: + mkdir -p tmp/templates/ + bin/htmlTagList $(ALLTAGS) > $@ + + +############ +# INTROS # +############ + +tmp/intros/%.html: content/blog/*-%.md + mkdir -p tmp/intros/ + bin/htmlIntro $< > $@ + +tmp/intros/%.rss: content/blog/*-%.md + mkdir -p tmp/intros/ + bin/rssIntro $< > $@ + +tmp/intros/%.gmi: content/blog/*-%.md + mkdir -p tmp/intros/ + bin/gmiIntro $< > $@ + +############## +# ARCHIVES # +############## + +public/feed.rss: $(foreach blog, $(ALLBLOGS), tmp/intros/$(blog).rss ) + mkdir -p public + bin/generateRSS $^ > $@ + +public/index.html: $(foreach blog, $(ALLBLOGS), tmp/intros/$(blog).html ) + mkdir -p public + bin/htmlIndex index $^ > $@ + +public/index.gmi: $(foreach blog, $(ALLBLOGS), tmp/intros/$(blog).gmi ) + mkdir -p public + bin/gmiIndex index $^ > $@ + +public/tag/%/index.html: $$(foreach blog, $$(shell bin/listBlogs % ), tmp/intros/$$(blog).html ) tmp/templates/taglist.html + mkdir -p $(@D) + bin/htmlIndex tag $* $^ > $@ + + + +########### +# Pages # +########### + +public/blog/%/index.html: content/blog/*-%.md tmp/templates/taglist.html + mkdir -p $(@D) + pandoc --template=templates/blog.html -f markdown -t html5 -M comments $< > $@ + +public/%/index.html: content/%.md tmp/templates/taglist.html + mkdir -p $(@D) + pandoc --template=templates/blog.html -f markdown -t html5 -M comments $< > $@ + +public/blog/%/index.gmi: content/blog/*-%.md + mkdir -p $(@D) + echo -n "# " > $@ + grep 'title: ' $< | cut -d ' ' -f 2- >> $@ + echo "" >> $@ + md2gemini -f -l paragraph $< >> $@ + +public/card: + content/card.curl > $@ + +########### +# PHONY # +########### + +tags: $(foreach tag, $(ALLTAGS), public/tag/$(shell echo $(tag) | tr 'A-Z' 'a-z')/index.html ) + +blogs: $(foreach blog, $(ALLBLOGS), public/blog/$(shell echo $(blog) | tr 'A-Z' 'a-z')/index.html ) $(foreach blog, $(ALLBLOGS), public/blog/$(shell echo $(blog) | tr 'A-Z' 'a-z')/index.gmi ) + +standalone: $(foreach page, $(STANDALONE), public/$(page)/index.html ) + +all: tags blogs standalone public/index.html public/feed.rss public/card + +push-blog: + rsync -azvhP ./public/ generalPurpose:docker/jonathanh/public + +push-assets: + rsync -azvhP ./assets/ generalPurpose:docker/jonathanh/public/assets + +clean: + rm -rf public/* + rm -rf tmp/ diff --git a/bin/generateRSS b/bin/generateRSS new file mode 100755 index 0000000..ec1b384 --- /dev/null +++ b/bin/generateRSS @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +lastUpdate="$(date --utc "+%a, %d %b %Y %H:%M:%S") UT" +echo " + + + <![CDATA[Jonathan Hodgson]]> + + https://jonathanh.co.uk + $lastUpdate" + +for i in "$@"; do + cat "$i" +done +echo "" diff --git a/bin/gmiIndex b/bin/gmiIndex new file mode 100755 index 0000000..fe3d04c --- /dev/null +++ b/bin/gmiIndex @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +case "$1" in + tag) + title="Archive: $(echo "$ALLTAGS" | tr ' _' '\n ' | grep -i "$(echo "$2" | tr '_' ' ')")" + template="$(echo "" | pandoc --template=templates/blog.html \ + -f markdown -t html5 -M archive -M title:"$title" 2> /dev/null )" + shift + ;; + index) + echo "# Jonathan Hodgson" + echo "" + echo "## Blogs" + echo "" + + ;; +esac + +shift + + + +for i in "$@"; do + case "$i" in + tmp/intros/*) + cat "$i" + echo "" + ;; + esac +done + + +echo "## Other Links" +echo "=> /help-me-out/ Help Me Out" +echo "=> /other-stuff-you-might-like/ Other Stuff You Might Like" diff --git a/bin/gmiIntro b/bin/gmiIntro new file mode 100755 index 0000000..c6df094 --- /dev/null +++ b/bin/gmiIntro @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +file="$1" + +getBlogSlug(){ + echo "$1" | sed 's/^content\//\//' | sed 's/.md$/\//' | sed -E 's/[0-9]+-//' +} + +info="$(sed -n '/---/,/---/p' "$file" | sed '/^$/,$d' | sed -n '1,/---/p' | sed '/^---$/d')" + +slug=$(getBlogSlug "$file") +date="$(echo "$info" | yq -r .date)" +title="$(echo "$info" | yq -r .title)" +description="$(echo "$info" | yq -r .description)" + +echo "=> $slug $title" +echo -e "\t$date" +echo "$description" + diff --git a/bin/htmlIndex b/bin/htmlIndex new file mode 100755 index 0000000..296a6dc --- /dev/null +++ b/bin/htmlIndex @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +case "$1" in + tag) + title="Archive: $(echo "$ALLTAGS" | tr ' _' '\n ' | grep -i "$(echo "$2" | tr '_' ' ')")" + template="$(echo "" | pandoc --template=templates/blog.html \ + -f markdown -t html5 -M archive -M title:"$title" 2> /dev/null )" + shift + ;; + index) + template="$(echo "" | pandoc --template=templates/blog.html \ + -f markdown -t html5 -M frontpage 2> /dev/null )" + ;; +esac + +shift + + +echo "$template" | sed -n '1,/#CONTENT#/p' | head -n -1 + +for i in "$@"; do + case "$i" in + tmp/intros/*) cat "$i" ;; + esac +done + +echo "$template" | sed -n '/#CONTENT#/,$p' | sed '1d' diff --git a/bin/htmlIntro b/bin/htmlIntro new file mode 100755 index 0000000..17748fa --- /dev/null +++ b/bin/htmlIntro @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +file="$1" + +getBlogSlug(){ + echo "$1" | sed 's/^content\//\//' | sed 's/.md$/\//' | sed -E 's/[0-9]+-//' +} + +info="$(sed -n '/---/,/---/p' "$file" | sed '/^$/,$d' | sed -n '1,/---/p' | sed '/^---$/d')" + +slug=$(getBlogSlug "$file") +date="$(echo "$info" | yq -r .date)" +title="$(echo "$info" | yq -r .title)" +description="$(echo "$info" | yq -r .description)" + +echo "
+

$title

+
+
+ $date +
+
+

$description

+

Read More

+
" diff --git a/bin/htmlTagList b/bin/htmlTagList new file mode 100755 index 0000000..c2a8fa2 --- /dev/null +++ b/bin/htmlTagList @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +echo "" diff --git a/bin/listBlogs b/bin/listBlogs new file mode 100755 index 0000000..3c2e2e6 --- /dev/null +++ b/bin/listBlogs @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +tag="$(echo "$1" | tr ' ' '_' | tr 'A-Z' 'a-z')" + +if [ "$tag" == "all" ]; then + find content/blog/ -type f -name '*.md' -not -name 'xxx-*' | sort -r -u | + cut -d '-' -f 2- | cut -d '.' -f 1 +else + find content/blog/ -type f -name '*.md' -not -name 'xxx-*' | sort -r -u | + while read file; do + tags="$(sed -n '/---/,/---/p' "$file" | + sed -n '1,/---/p' | sed '/^---$/d' | + sed '/^$/,$d' | + yq -r 'if ( .tags | type ) == "array" then .tags else [ .tags ] end | join("\n")' | + tr 'A-Z' 'a-z' | tr ' ' '_' + )" + if echo "$tags" | grep -q "$tag"; then + echo "$file" | cut -d '-' -f 2- | cut -d '.' -f 1 + fi + done + +fi + diff --git a/bin/listTags b/bin/listTags new file mode 100755 index 0000000..4ba1ab6 --- /dev/null +++ b/bin/listTags @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +find content/blog/ -type f -name '*.md' -not -name 'xxx-*' | while read file; do + sed -n '/---/,/---/p' "$file" | sed -n '1,/---/p' | sed '/^---$/d' | sed '/^$/,$d' | yq -r 'if ( .tags | type ) == "array" then .tags else [ .tags ] end | join("\n")' | while read tag; do + echo "$tag" | tr ' ' '_' + done +done | sort -u diff --git a/bin/rssIntro b/bin/rssIntro new file mode 100755 index 0000000..87d7ff8 --- /dev/null +++ b/bin/rssIntro @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +file="$1" + +getBlogSlug(){ + echo "$1" | sed 's/^content\//\//' | sed 's/.md$/\//' | sed -E 's/[0-9]+-//' +} + +info="$(sed -n '/---/,/---/p' "$file" | sed '/^$/,$d' | sed -n '1,/---/p' | sed '/^---$/d')" + +slug=$(getBlogSlug "$file") +date="$(echo "$info" | yq -r .date)" +rfc822="$(date --utc -d "$date" "+%a, %d %b %Y %H:%M:%S") UT" +title="$(echo "$info" | yq -r .title)" +description="$(echo "$info" | yq -r .description)" + +echo " + + <![CDATA[$title]]> + https://jonathanh.co.uk$slug + https://jonathanh.co.uk$slug + $rfc822 + +" diff --git a/build.sh b/build.sh deleted file mode 100755 index f353979..0000000 --- a/build.sh +++ /dev/null @@ -1,231 +0,0 @@ -#!/usr/bin/env bash - -getBlogSlug(){ - echo "$1" | sed 's/^content\//\//' | sed 's/.md$/.html/' | sed -E 's/[0-9]+-//' -} - -blog(){ - echo "Generating Blog pages" - [ ! -f "tmp/templates/tagList.html" ] && echo "No taglist file" | tee "tmp/templates/tagList.html" > /dev/stderr - local newer="" - [ -f tmp/lastBlogUpdate ] && newer="-newer tmp/lastBlogUpdate" - find content/ -type f -name '*.md' $newer | while read file; do - newFileName=$(getBlogSlug "$file") - mkdir -p "public_html/${newFileName%/*}" - mkdir -p "public_gemini/${newFileName%/*}" - pandoc --template=templates/blog.html -f markdown -t html5 -M comments "$file" > "public_html/$newFileName" - local info="$(sed -n '/---/,/---/p' "$file" | sed '/^$/,$d' | sed -n '1,/---/p' | sed '/^---$/d')" - local title="$(echo "$info" | yq -r .title)" - echo "# $title" | cat - "$file" | sed '/^---/,/^---/d' | md2gemini --link at-end > "public_gemini/${newFileName%.*}.gmi" - done - touch tmp/lastBlogUpdate -} - -makeIntro(){ - local file="$1" - local output="tmp/intros/$file" - local rssoutput="tmp/rss/$file" - # We delete tmp each time the build script runs, so if the file exists, we have already generated one this time - [ -f "$output" ] && return 1 - mkdir -p "${output%/*}" - mkdir -p "${rssoutput%/*}" - local info="$(sed -n '/---/,/---/p' "$file" | sed '/^$/,$d' | sed -n '1,/---/p' | sed '/^---$/d')" - local slug=$(getBlogSlug "$file") - local date="$(echo "$info" | yq -r .date)" - local rfc822="$(date --utc -d "$date" "+%a, %d %b %Y %H:%M:%S") UT" - local tags="$(echo "$info" | yq -r 'if ( .tags | type ) == "array" then .tags else [ .tags ] end | join("\n")' | awk '{print "
  • " $0 "
  • "}' )" - local title="$(echo "$info" | yq -r .title)" - local description="$(echo "$info" | yq -r .description)" - echo "
    -

    $title

    -
    -
    - $date -
    -
    -

    $description

    -

    Read More

    -
    " > "$output" - echo "=> ${slug%.*}.gmi $title - $date -$description - " > "${output%.*}.gmi" - echo " - - <![CDATA[$title]]> - https://jonathanh.co.uk/$slug - https://jonathanh.co.uk/$slug - $rfc822 - - " > "$rssoutput" -} - -getIntro(){ - local file="$1" - local output="tmp/intros/$file" - - if [ "$2" = "rss" ]; then - local output="tmp/rss/$file" - fi - - if [ "$2" = "gmi" ]; then - local output="tmp/intros/${file%.*}.gmi" - fi - #makeIntro "$file" - cat "$output" -} - -index(){ - echo "Generating Home Page" - [ ! -f "tmp/templates/tagList.html" ] && echo "No taglist file" | tee "tmp/templates/tagList.html" > /dev/stderr - local template="$(echo "" | pandoc --template=templates/blog.html -f markdown -t html5 -M frontpage 2> /dev/null )" - - # First loop makes all the intros needed and stores them in tmp/intros - find content/blog/ -type f -name '*.md' | grep -v 'xxx' | sort -r | head -n 20 | while read file; do - makeIntro "$file" - done - - - # Once they are created, we will put them in, in order - ( - echo "$template" | sed -n '1,/#CONTENT#/p' | head -n -1 - find content/blog/ -type f -name '*.md' | grep -v 'xxx' | sort -r | head -n 20 | while read file; do - grep -Eq '^draft: true' "$file" || getIntro "$file" - done - echo "$template" | sed -n '/#CONTENT#/,$p' | sed '1d' - ) > public_html/index.html - - # Once they are created, we will put them in, in order - ( - echo "# Jonathan Hodgson" - echo "" - echo "## Blogs" - echo "" - find content/blog/ -type f -name '*.md' | grep -v 'xxx' | sort -r | head -n 20 | while read file; do - grep -Eq '^draft: true' "$file" || getIntro "$file" gmi - done - echo "" - echo "## Other Links" - echo "=> /help-me-out.gmi Help Me Out" - echo "=> /other-stuff-you-might-like.gmi Other Stuff You Might Like" - - ) > public_gemini/index.gmi -} - -tagIndex(){ - local tag="$1" - local title="$(basename "$tag")" - - [ ! -f "tmp/templates/tagList.html" ] && echo "No taglist file" | tee "tmp/templates/tagList.html" > /dev/stderr - local template="$(echo "" | pandoc --template=templates/blog.html -f markdown -t html5 -M archive -M title:"$title Archive" 2> /dev/null )" - - cat "$1" | grep -v 'xxx' | sort -r | while read file; do - makeIntro "$file" & - done - wait - - echo "$template" | sed -n '1,/#CONTENT#/p' | head -n -1 - cat "$1" | sort -r | while read file; do - getIntro "$file" - done - echo "$template" | sed -n '/#CONTENT#/,$p' | sed '1d' -} - - -html_tag_list(){ - if [ -d "tmp/tag" ]; then - echo "" - else - echo "Need to generate the taglist" > /dev/stderr - fi -} - -tags(){ - - echo "Generating Tags" - - # Loops through each blog and puts it in tag lists, although only blogs that have changed - local newer="" - [ -f tmp/lastTagUpdate ] && newer="-newer tmp/lastTagUpdate" - find content/blog/ -type f -name '*.md' -not -name 'xxx-*' $newer | while read file; do - sed -n '/---/,/---/p' "$file" | sed -n '1,/---/p' | sed '/^---$/d' | sed '/^$/,$d' | yq -r 'if ( .tags | type ) == "array" then .tags else [ .tags ] end | join("\n")' | while read tag; do - tag=$(echo "$tag" | tr ' ' '_') - # Adds the file to the tags list if it's not already in there - grep -q "$file" tmp/tag/"$tag" 2> /dev/null || echo "$file" >> tmp/tag/"$tag" - done - done - - echo "Generating Taglist HTML" - html_tag_list > tmp/templates/tagList.html - - # We should now have a folder with a text file for each tag containing each blog - echo "Generating Tag Index Pages" - - find tmp/tag/ -type f $newer | while read tag; do - filename="$(echo $tag | sed 's/^tmp//' | tr '[A-Z]' '[a-z]').html" - tagIndex "$tag" > "public_html/$filename" - done - - touch tmp/lastTagUpdate -} - -card(){ - echo "Generating Card" - content/card.curl > public_html/card -} - -rss(){ - echo "Generating RSS Feed" - lastUpdate="$(date --utc "+%a, %d %b %Y %H:%M:%S") UT" - - # First loop makes all the intros needed and stores them in tmp/intros - find content/blog/ -type f -name '*.md' | grep -v 'xxx' | sort -r | head -n 20 | while read file; do - makeIntro "$file" & - done - wait - - ( - echo " - - - <![CDATA[Jonathan Hodgson]]> - - https://jonathanh.co.uk - $lastUpdate" - find content/blog/ -type f -name '*.md' | grep -v 'xxx' | sort -r | head -n 20 | while read file; do - grep -Eq '^draft: true' "$file" || getIntro "$file" rss - done - echo ""; - ) > public_html/feed.rss -} - - -clean(){ - rm -rf tmp > /dev/null 2> /dev/null - # Don't remove the public_html folder or docker won't re-attach it - rm -rf public_html/* - rm -rf public_gemini/* -} - - -# Make sure the folders we will need exist -mkdir -p public_html/{blog,tag} -mkdir -p public_gemini/{blog,tag} -mkdir -p tmp/{tag,templates,intros} - - -case "$1" in - clean) clean ;; - index) index ;; - blog) blog ;; - tags) tags ;; - card) card ;; - rss) rss ;; - all) tags && blog && index && rss && card ;; -esac diff --git a/templates/blog.html b/templates/blog.html index 79ee352..0c41b92 100644 --- a/templates/blog.html +++ b/templates/blog.html @@ -65,13 +65,13 @@ $body$ $endif$