minor changes to src/todo.gmi, and src/index.gmi. refactored scripts/html.awk

This commit is contained in:
Abdullah Islam 2023-05-10 19:22:30 +06:00
parent e51ca03d19
commit 65173a6736
6 changed files with 13 additions and 180 deletions

View File

@ -1,15 +1,15 @@
BEGIN {
getline
printf "Navigation:\n\
if (FILENAME != "-")
printf "Navigation:\n\
=> %s home\n\
=> %s notes\n\
=> %s useful\n\
=> %s sitemap\n", \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/index.gmi"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/notes/index.gmi"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/useful/index.gmi"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/sitemap.gmi")
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/index.gmi"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/notes/index.gmi"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/useful/index.gmi"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/sitemap.gmi")
}
{ print }

View File

@ -10,6 +10,7 @@ BEGIN {
headingText = substr($0, RSTART + RLENGTH)
articleBody = articleBody sprintf("<h1>%s</h1>\n", headingText)
title = headingText
next
}
/^##[^#]/ {
@ -22,12 +23,14 @@ BEGIN {
toFilename(headingText))
subHeadings[length(subHeadings)] = headingText
next
}
/^###[^#]/ {
match($0, "^###([ ]*)")
headingText = substr($0, RSTART + RLENGTH)
articleBody = articleBody sprintf("<h3>%s</h3>\n", headingText)
next
}
/^=>/ {

View File

@ -1,2 +0,0 @@
# Tutorials
=> ./website-generation.gmi One way to build a website, I guess

View File

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

View File

@ -1,10 +1,11 @@
# techn0path's website
On this personal website of mine, I talk about stuff.
=> todo.gmi Todo
=> todo.gmi Todo list for this website
## Highlights
The content on this site I am most proud of. :)
=> notes/awk-make-sh.gmi Use awk + make + sh for website generation
=> notes/on-personal-websites.gmi On personal websites
=> useful/addons.gmi Useful addons

View File

@ -1,3 +1,3 @@
# Todo
* Add a feed to this site.
* Also add a search-engine targeted sitemap document
* Add a search-engine targeted sitemap document
* Make this website more efficient