commit ace9a2912d4802753c979b3d04f4d826dd15f46d
parent 58e28b99f2f8416cbd0c6dd8f5720e9cb4bba621
Author: Charlie Stanton <charlie@shtanton.com>
Date: Sun, 3 Jan 2021 14:18:18 +0000
Switches from tup and python to make and dash
Diffstat:
13 files changed, 80 insertions(+), 88 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,34 @@
+WEB_POSTS = html/all_the_protocols.html html/build_process.html html/ex.html
+GOPHER_POSTS = gopher/all_the_protocols.md gopher/build_process.md gopher/ex.md
+
+WEB = $(WEB_POSTS) html/post.css html/colours.css html/index.html
+GOPHER = $(GOPHER_POSTS) gopher/index
+
+.PHONY: all clean publish
+
+all: $(WEB) $(GOPHER)
+
+html/%.css: html_src/%.css
+ cp $^ $@
+
+html_src/nav.html: html_src/nav_html.sh posts-config
+ $^ > $@
+
+html/%.html: html_src/post_html.sh posts/%.md posts-config html_src/post_template.html html_src/nav.html
+ $^ $* > $@
+
+html/index.html: html_src/index_html.sh html_src/index_template.html html_src/nav.html
+ $^ > $@
+
+gopher/%.md: posts/%.md
+ cp $^ $@
+
+gopher/index: gopher_src/index.sh posts-config
+ $^ > $@
+
+clean:
+ rm html_src/nav.html
+
+publish: all
+ rsync -vr --delete gopher charlie@shtanton.com:shtanton-gopher
+ rsync -vr --delete html charlie@shtanton.com:shtanton-web
diff --git a/Tupfile b/Tupfile
@@ -1,6 +0,0 @@
-: foreach html_src/*.css |> cp %f %o |> html/%B.css
-: |> ./html_src/nav_html.py > %o |> html_src/nav.html
-: foreach posts/*.md | html_src/nav.html |> ./html_src/post_html.py %B > %o |> html/%B.html
-: foreach posts/*.md |> cp %f %o |> gopher/%b
-: | html_src/nav.html |> ./html_src/index_html.py > %o |> html/index.html
-: |> ./gopher_src/index.py > %o |> gopher/index
diff --git a/config.json b/config.json
@@ -1,19 +0,0 @@
-{
- "posts": [
- {
- "title": "All the protocols",
- "file": "all_the_protocols",
- "date": "2020-11-17 18:20:28"
- },
- {
- "title": "How this site is built",
- "file": "build_process",
- "date": "2020-08-21 08:51:10"
- },
- {
- "title": "Reviving ex in 2020",
- "file": "ex",
- "date": "2020-08-05 15:27:08"
- }
- ]
-}
diff --git a/gopher_src/index.py b/gopher_src/index.py
@@ -1,12 +0,0 @@
-#!/usr/bin/python3.8
-import json, sys
-
-template_start = "iCharlie Stanton's Phlog\tnone\tshtanton.com\t70\r\n"
-template_end = ".\r\n"
-
-with open("config.json", encoding="utf-8") as config_file:
- config = json.load(config_file)
- sys.stdout.write(template_start)
- for post in config["posts"]:
- sys.stdout.write("0{title} - {date}\t{file}.md\tshtanton.com\t70\r\n".format(**post))
- sys.stdout.write(template_end)
diff --git a/gopher_src/index.sh b/gopher_src/index.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/dash
+/usr/bin/echo -en "iCharlie Stanton's Phlog\tnone\tshtanton.com\t70\r\n"
+awk -F :: '{print "0"$2" - "$3"\t"$1".md\tshtanton.com\t70\r"}' $1
+/usr/bin/echo -en ".\r\n"
diff --git a/html_src/index_html.py b/html_src/index_html.py
@@ -1,9 +0,0 @@
-#!/usr/bin/python3.8
-import sys, shutil
-
-with open("html_src/nav.html", encoding="utf-8") as nav_file, open("html_src/index_template.html", encoding="utf-8") as template_file:
- for line in template_file:
- if line == "{nav}\n":
- shutil.copyfileobj(nav_file, sys.stdout)
- else:
- sys.stdout.write(line)
diff --git a/html_src/index_html.sh b/html_src/index_html.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/dash
+while read line
+do
+ case $line in
+ "{nav}")
+ cat $2
+ ;;
+ *)
+ echo $line
+ ;;
+ esac
+done < $1
diff --git a/html_src/nav_html.py b/html_src/nav_html.py
@@ -1,11 +0,0 @@
-#!/usr/bin/python3.8
-import json, sys
-
-with open("config.json", encoding="utf-8") as config_file:
- config = json.load(config_file)
- sys.stdout.write("<ul>")
- for post in config["posts"]:
- sys.stdout.write("""<li>
- <a href="/{file}.html">{title}</a> - <em>{date}</em>
- </li>""".format(**post))
- sys.stdout.write("</ul>")
diff --git a/html_src/nav_html.sh b/html_src/nav_html.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/dash
+echo "<ul>"
+awk -F :: '{print "<li><a href=\"/"$1".html\">"$2"</a> - <em>"$3"</em></li>"}' $1
+echo "</ul>"
diff --git a/html_src/post_html.py b/html_src/post_html.py
@@ -1,27 +0,0 @@
-#!/usr/bin/python3.8
-import argparse, json, sys, os, subprocess, shutil
-
-parser = argparse.ArgumentParser(description="Generate html for post from markdown")
-parser.add_argument("post", help="Post markdown file name")
-args = parser.parse_args()
-
-with open(os.path.join("posts", args.post+".md"), encoding="utf-8") as post_file, open("config.json", encoding="utf-8") as config_file, open("html_src/post_template.html", encoding="utf-8") as template_file, open("html_src/nav.html", encoding="utf-8") as nav_file:
- config = json.load(config_file)
- post_metadata = next((p for p in config["posts"] if p["file"] == args.post), None)
- if not post_metadata:
- print("Post not found")
- sys.exit(1)
- for line in template_file:
- if line == "{content}\n":
- sys.stdout.flush()
- subprocess.call(["markdown"], stdin=post_file, stdout=sys.stdout)
- sys.stdout.flush()
- elif line == "{header}\n":
- sys.stdout.write("""
- <h2>{title}</h2>
- <em>{date}</em>
- """.format(title=post_metadata["title"], date=post_metadata["date"]))
- elif line == "{nav}\n":
- shutil.copyfileobj(nav_file, sys.stdout)
- else:
- sys.stdout.write(line)
diff --git a/html_src/post_html.sh b/html_src/post_html.sh
@@ -0,0 +1,23 @@
+#!/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}")
+ markdown $FILE
+ ;;
+ "{nav}")
+ cat $4
+ ;;
+ *)
+ echo $line
+ ;;
+ esac
+done < $3
diff --git a/posts-config b/posts-config
@@ -0,0 +1,3 @@
+all_the_protocols::All the protocols::2020-11-17 18:20:28
+build_process::How this site is built::2020-08-21 08:51:10
+ex::Reviving ex in 2020::2020-08-05 15:27:08
diff --git a/publish.sh b/publish.sh
@@ -1,4 +0,0 @@
-#!/usr/bin/sh
-tup
-rsync -vr --delete gopher charlie@shtanton.com:shtanton-gopher
-rsync -vr --delete html charlie@shtanton.com:shtanton-web