|
|
|
@ -1,169 +0,0 @@
|
|
|
|
|
# One way to build a website, I guess
|
|
|
|
|
Let's talk how this website is generated. Basically it's a mashup of pp as a pre-processor, make as a build system, and common utilities you can find on most UNIX systems.
|
|
|
|
|
|
|
|
|
|
The base structure of my system is as follows. There are 4 directories: src/, tmpl/, html/, and gmi/. src/ contains the naked files that make up this website - what I refer to as "source files" - without the navigation bars or any fancy shenanigans. tmpl/ contains template files for pp, html/ contains the generated HTML, and gmi/ contains the generated gemtext.
|
|
|
|
|
|
|
|
|
|
Earlier, I mentioned how I use make. The good thing is that since I have configured my Makefile to not automatically execute the 'clean' rule as a part of 'all', only the source files that were changed get processed.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
SHELL = '/bin/sh'
|
|
|
|
|
SOURCES = $(shell find src -type f)
|
|
|
|
|
|
|
|
|
|
all: subdirs $(SOURCES:src/%.gmi=html/%.html) $(SOURCES:src/%.gmi=gmi/%.gmi) gmi/sitemap.gmi html/sitemap.html
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
|
rm -rf html/* gmi/*
|
|
|
|
|
|
|
|
|
|
subdirs:
|
|
|
|
|
find src/ -type d -printf '%P\0' | xargs -0 -I{} mkdir -p gmi/{} html/{}
|
|
|
|
|
|
|
|
|
|
gmi/%.gmi: src/%.gmi tmpl/gmi.uppgmi
|
|
|
|
|
pp tmpl/gmi.uppgmi $< > $@
|
|
|
|
|
|
|
|
|
|
html/%.html: src/%.gmi tmpl/html.upphtml
|
|
|
|
|
pp tmpl/html.upphtml $< > $@
|
|
|
|
|
|
|
|
|
|
gmi/sitemap.gmi: $(shell find src -mindepth 2 -maxdepth 2 -path '*/index.gmi') tmpl/sitemap.uppgmi
|
|
|
|
|
pp tmpl/sitemap.uppgmi src/ > $@
|
|
|
|
|
|
|
|
|
|
html/sitemap.html: $(shell find src -mindepth 2 -maxdepth 2 -path '*/index.gmi') tmpl/sitemap.upphtml
|
|
|
|
|
pp tmpl/sitemap.upphtml src/ > $@
|
|
|
|
|
|
|
|
|
|
.PHONY: clean subdirs
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Now let's talk about the processing. pp - the pre-processor - works by taking a template file and some other command-line arguments, processing them, and generating output which you can use for whatever you want.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
pp [options] [template-file] [args...]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
HTML generation:
|
|
|
|
|
```
|
|
|
|
|
<title>
|
|
|
|
|
#!
|
|
|
|
|
awk '/^#[^#]/ { sub("^#([ ]*)", ""); printf "%s", $0; exit } { print "techn0path" }' $1
|
|
|
|
|
#!
|
|
|
|
|
</title>
|
|
|
|
|
|
|
|
|
|
<meta name='referrer' content='no-referrer' />
|
|
|
|
|
<meta name='author' content='techn0path' />
|
|
|
|
|
<meta name='viewport' content='width=device-width,initial-scale=1.0' />
|
|
|
|
|
|
|
|
|
|
<header>
|
|
|
|
|
<nav>
|
|
|
|
|
<div id='navbar'>
|
|
|
|
|
#!
|
|
|
|
|
printf '<a href="%s">codeAI</a> |
|
|
|
|
|
<a href="%s">notes</a> |
|
|
|
|
|
<a href="%s">howto</a> |
|
|
|
|
|
<a href="%s">useful</a>' \
|
|
|
|
|
`realpath --relative-to="$(dirname $1)" "$PWD/src/index.html"` \
|
|
|
|
|
`realpath --relative-to="$(dirname $1)" "$PWD/src/notes/index.html"` \
|
|
|
|
|
`realpath --relative-to="$(dirname $1)" "$PWD/src/howto/index.html"` \
|
|
|
|
|
`realpath --relative-to="$(dirname $1)" "$PWD/src/useful/index.html"`
|
|
|
|
|
#!
|
|
|
|
|
</div>
|
|
|
|
|
</nav>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<main>
|
|
|
|
|
<div id='content'>
|
|
|
|
|
#!
|
|
|
|
|
printf "<p>Last modified on %s.</p>" `date -u -r "$1" +%Y/%m/%d`
|
|
|
|
|
|
|
|
|
|
awk -F " " '/^=>/ {
|
|
|
|
|
if (NF < 2) next;
|
|
|
|
|
|
|
|
|
|
sub("^([ ]*)", "", $2);
|
|
|
|
|
sub("([ ]*)$", "", $2);
|
|
|
|
|
|
|
|
|
|
if (match($2, "^\\.(\\.?)\\/") || ! match($2, "^(.*):\\/\\/"))
|
|
|
|
|
sub("\\.gmi$", ".html", $2)
|
|
|
|
|
} { print $0 }' $1 | gemini2html
|
|
|
|
|
#!
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Sitemap generation
|
|
|
|
|
```
|
|
|
|
|
# Sitemap
|
|
|
|
|
This document is automatically generated. See also:
|
|
|
|
|
=> howto/website-generation.gmi One way to generate a website, I guess
|
|
|
|
|
|
|
|
|
|
#!
|
|
|
|
|
export DIRECTORY="$1"
|
|
|
|
|
|
|
|
|
|
awk '
|
|
|
|
|
/^#[^#]/ { sub("^#([ ]*)", ""); printf "## %s\n", $0 }
|
|
|
|
|
/^=>/ {
|
|
|
|
|
if (NF < 2) next
|
|
|
|
|
link = $2
|
|
|
|
|
|
|
|
|
|
$1 = ""
|
|
|
|
|
$2 = ""
|
|
|
|
|
|
|
|
|
|
description = $0
|
|
|
|
|
sub("^([ ]*)", "", description)
|
|
|
|
|
|
|
|
|
|
sprintf("dirname %s", FILENAME) | getline dirname
|
|
|
|
|
sprintf("realpath %s/%s", dirname, link) | getline tmp
|
|
|
|
|
sprintf("realpath --relative-to=%s %s", ENVIRON["DIRECTORY"], tmp) | getline tmp2
|
|
|
|
|
link = tmp2
|
|
|
|
|
|
|
|
|
|
printf "=> %s %s\n", link, description
|
|
|
|
|
}' `find $DIRECTORY -mindepth 2 -maxdepth 2 -path "*/index.gmi"`
|
|
|
|
|
#!
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
HTML version:
|
|
|
|
|
```
|
|
|
|
|
# Note how the navigation bar generation is different.
|
|
|
|
|
#!
|
|
|
|
|
export DIRECTORY="$1"
|
|
|
|
|
|
|
|
|
|
printf '<a href="%s">codeAI</a> |
|
|
|
|
|
<a href="%s">notes</a> |
|
|
|
|
|
<a href="%s">howto</a> |
|
|
|
|
|
<a href="%s">useful</a> |
|
|
|
|
|
<a href="%s">sitemap</a>' \
|
|
|
|
|
`realpath --relative-to="$DIRECTORY" "$PWD/src/index.html"` \
|
|
|
|
|
`realpath --relative-to="$DIRECTORY" "$PWD/src/notes/index.html"` \
|
|
|
|
|
`realpath --relative-to="$DIRECTORY" "$PWD/src/howto/index.html"` \
|
|
|
|
|
`realpath --relative-to="$DIRECTORY" "$PWD/src/useful/index.html"` \
|
|
|
|
|
`realpath --relative-to="$DIRECTORY" "$PWD/src/sitemap.html"`
|
|
|
|
|
#!
|
|
|
|
|
|
|
|
|
|
<div id='content'>
|
|
|
|
|
#!
|
|
|
|
|
awk '
|
|
|
|
|
/^#[^#]/ { sub("^#([ ]*)", ""); printf "<h2>%s</h2>", $0 }
|
|
|
|
|
/^=>/ {
|
|
|
|
|
if (NF < 2) next
|
|
|
|
|
link = $2
|
|
|
|
|
|
|
|
|
|
$1 = ""
|
|
|
|
|
$2 = ""
|
|
|
|
|
|
|
|
|
|
description = $0
|
|
|
|
|
sub("^([ ]*)", "", description)
|
|
|
|
|
|
|
|
|
|
sprintf("dirname %s", FILENAME) | getline dirname
|
|
|
|
|
sprintf("realpath %s/%s", dirname, link) | getline tmp
|
|
|
|
|
sprintf("realpath --relative-to=%s %s", ENVIRON["DIRECTORY"], tmp) | getline tmp2
|
|
|
|
|
link = tmp2
|
|
|
|
|
|
|
|
|
|
if (match(link, "^\\.(\\.?)\\/") || ! match(link, "^(.*):\\/\\/"))
|
|
|
|
|
sub("\\.gmi$", ".html", link)
|
|
|
|
|
|
|
|
|
|
printf "<a href=\"%s\">%s</a><br>", link, description
|
|
|
|
|
}' `find $DIRECTORY -mindepth 2 -maxdepth 2 -path "*/index.gmi"`
|
|
|
|
|
#!
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Related
|
|
|
|
|
=> ../notes/on-personal-websites.gmi On personal websites
|
|
|
|
|
=> https://www.karl.berlin/static-site.html Karl Bartel - 'make' as a static site generator
|
|
|
|
|
=> https://shadowm00n.neocities.org/tech/how_this_site_is_built ShadowM00N - How this site is built
|