Moved to Makefile based build system

Got rid of janky build.sh script. Now uses a bunch of janky scripts and
a make file - because that is bound to be easier to maintain.
master
Jonathan Hodgson 2 years ago
parent 39791363fa
commit 56f95cb9aa
  1. 2
      .gitignore
  2. 98
      Makefile
  3. 15
      bin/generateRSS
  4. 35
      bin/gmiIndex
  5. 19
      bin/gmiIntro
  6. 27
      bin/htmlIndex
  7. 25
      bin/htmlIntro
  8. 11
      bin/htmlTagList
  9. 23
      bin/listBlogs
  10. 7
      bin/listTags
  11. 24
      bin/rssIntro
  12. 231
      build.sh
  13. 6
      templates/blog.html

2
.gitignore vendored

@ -1,6 +1,8 @@
generated-template-parts
public_html
public_gemini
public
gem-cert
tmp
assets/css/main.min.css
xxx-*

@ -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/

@ -0,0 +1,15 @@
#!/usr/bin/env bash
lastUpdate="$(date --utc "+%a, %d %b %Y %H:%M:%S") UT"
echo "<?xml version='1.0' encoding='UTF-8' ?>
<rss xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:atom=\"http://www.w3.org/2005/Atom\" version=\"2.0\">
<channel>
<title><![CDATA[Jonathan Hodgson]]></title>
<description><![CDATA[Jonathan Hodgson's Blog]]></description>
<link>https://jonathanh.co.uk</link>
<lastBuildDate>$lastUpdate</lastBuildDate>"
for i in "$@"; do
cat "$i"
done
echo "</channel></rss>"

@ -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"

@ -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"

@ -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'

@ -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 "<article>
<h2><a href='$slug'>$title</a></h2>
<div class="article-details">
<div class="date">
$date
</div>
</div>
<p>$description</p>
<p><a href='$slug'>Read More</a></p>
</article>"

@ -0,0 +1,11 @@
#!/usr/bin/env bash
echo "<ul class='taglist'>"
for line in "$@"; do
link="/tag/$(echo "$line" | tr 'A-Z' 'a-z')/"
name="$(echo "$line" | tr '_' ' ')"
echo "<li><a href='$link'>$name</a></li>"
done
echo "</ul>"

@ -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

@ -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

@ -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 "<item>
<title>
<![CDATA[$title]]></title>
<link>https://jonathanh.co.uk$slug</link>
<guid isPermaLink=\"true\">https://jonathanh.co.uk$slug</guid>
<pubDate>$rfc822</pubDate>
<description><![CDATA[$description]]></description>
</item>"

@ -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 "<li>" $0 "</li>"}' )"
local title="$(echo "$info" | yq -r .title)"
local description="$(echo "$info" | yq -r .description)"
echo "<article>
<h2><a href='$slug'>$title</a></h2>
<div class="article-details">
<div class="date">
$date
</div>
</div>
<p>$description</p>
<p><a href='$slug'>Read More</a></p>
</article>" > "$output"
echo "=> ${slug%.*}.gmi $title
$date
$description
" > "${output%.*}.gmi"
echo "<item>
<title>
<![CDATA[$title]]></title>
<link>https://jonathanh.co.uk/$slug</link>
<guid isPermaLink=\"true\">https://jonathanh.co.uk/$slug</guid>
<pubDate>$rfc822</pubDate>
<description><![CDATA[$description]]></description>
</item>" > "$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 "<ul class='taglist'>"
wc -l tmp/tag/* | head -n -1 | sort -nr | while read line; do
local link=$(echo "$line" | awk '{print $2 ".html"}' | sed 's/^tmp//' | tr '[A-Z]' '[a-z]' | tr ' ' '-')
local name=$(echo "$line" | sed 's/tmp\/tag\///' | awk '{print $2 " (" $1 ")"}' | tr '_' ' ')
echo "<li><a href='$link'>$name</a></li>"
done
echo "</ul>"
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 "<?xml version='1.0' encoding='UTF-8' ?>
<rss xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:atom=\"http://www.w3.org/2005/Atom\" version=\"2.0\">
<channel>
<title><![CDATA[Jonathan Hodgson]]></title>
<description><![CDATA[Jonathan Hodgson's Blog]]></description>
<link>https://jonathanh.co.uk</link>
<lastBuildDate>$lastUpdate</lastBuildDate>"
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 "</channel></rss>";
) > 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

@ -65,13 +65,13 @@ $body$
$endif$
</a>
<nav>
${ ../tmp/templates/tagList.html() }
${ ../tmp/templates/taglist.html() }
</nav>
</aside>
</div>
<footer>
<a href="/help-me-out.html">Help Me Out</a>
<a href="/other-stuff-you-might-like.html">Other Stuff You Might Like</a>
<a href="/help-me-out/">Help Me Out</a>
<a href="/other-stuff-you-might-like/">Other Stuff You Might Like</a>
<a href="https://git.jonathanh.co.uk/jab2870/Website">Website Source</a>
</footer>
</body>

Loading…
Cancel
Save