added a sitemap generation template for HTML

This commit is contained in:
Abdullah Islam 2023-05-03 16:57:57 +06:00
parent c71d756bd1
commit dd5b79da41
3 changed files with 90 additions and 10 deletions

View File

@ -2,7 +2,7 @@ SHELL = /bin/sh
SOURCES = $(shell find src/ -type f)
SITEMAP_INDEX_FILES = $(wildcard src/*/index.gmi)
all: subdirs $(SOURCES:src/%.gmi=html/%.html) $(SOURCES:src/%.gmi=gmi/%.gmi) gmi/sitemap.gmi gmi/feed.atom
all: subdirs $(SOURCES:src/%.gmi=html/%.html) $(SOURCES:src/%.gmi=gmi/%.gmi) gmi/sitemap.gmi gmi/feed.atom html/sitemap.html
clean:
rm -rf html/* gmi/*
@ -10,14 +10,17 @@ clean:
subdirs:
find src -mindepth 1 -type d -printf '%P\0' | xargs -0 -I{} mkdir -p gmi/{} html/{}
html/%.html: src/%.gmi tmpl/html.awk tmpl/common_functions.awk
html/%.html: src/%.gmi tmpl/html.awk
mawk -f tmpl/common_functions.awk -f tmpl/html.awk -- $< > $@
gmi/%.gmi: src/%.gmi tmpl/gemini.awk tmpl/common_functions.awk
gmi/%.gmi: src/%.gmi tmpl/gemini.awk
mawk -f tmpl/common_functions.awk -f tmpl/gemini.awk -- $< > $@
gmi/sitemap.gmi: $(SITEMAP_INDEX_FILES) tmpl/sitemap_gmi.awk tmpl/common_functions.awk
gmi/sitemap.gmi: $(SITEMAP_INDEX_FILES) tmpl/sitemap_gmi.awk
mawk -f tmpl/common_functions.awk -f tmpl/sitemap_gmi.awk -- $(SITEMAP_INDEX_FILES) > $@
gmi/feed.atom: src/feed.ass tmpl/feed.awk tmpl/common_functions.awk
git log --pretty=format:"/hash %s%n/date %cI%n/title %s%n/body %b%n/end%n" | mawk -f tmpl/common_functions.awk -f tmpl/feed.awk -- - > $@
html/sitemap.html: $(SITEMAP_INDEX_FILES) tmpl/sitemap_html.awk
mawk -f tmpl/common_functions.awk -f tmpl/sitemap_html.awk -- $(SITEMAP_INDEX_FILES) > $@
gmi/feed.atom: src/feed.ass tmpl/feed.awk
mawk -f tmpl/common_functions.awk -f tmpl/feed.awk -- $< > $@

View File

@ -1,15 +1,21 @@
BEGIN {
filename = FILENAME
printf "# Sitemap\n\
This document is automatically generated. See:\n\
=> howto/website-generation.gmi\n"
}
/^#[^#]/ { sub("^#(\s*)", "## "); print }
FILENAME != filename {
filename = FILENAME
printf "\n"
}
/^#[^#]/ { sub("^#([ ]*)", "## "); print }
/^=>/ {
if ($1 ~ "^=>[^ ]") {
link = $1
sub("^=>", "", link)
if (match($1, "^=>[^ ]") > 0) {
link = substr($1, RSTART)
$1 = ""
}
else if (NF < 2) next

71
tmpl/sitemap_html.awk Normal file
View File

@ -0,0 +1,71 @@
BEGIN {
getline
filename = FILENAME
}
/^#[^#]/ {
sub("^#([ ]*)", "")
body = body "<h2>" $0 "</h2>\n"
}
/^=>/ {
if (match($1, "^=>[^ ]") > 0) {
link = substr($1, RSTART)
$1 = ""
}
else if (NF < 2) next
else {
link = $2
$1 = ""
$2 = ""
}
description = $0
sub("([ ]*)", "", description)
if (link !~ "^(\w*):") sub("\.gmi$", ".html", link)
link = relpath(ENVIRON["PWD"] "/src", abspath(getDirname(FILENAME) "/" link))
body = body "<a href='" link "'>" description "</a><br>\n"
}
END {
printf "<!DOCTYPE html>\n\
<html>\n\
<head>\n\
<title>Sitemap</title>\n\
\n\
<meta name='author' content='techn0path' />\n\
<meta name='referrer' content='no-referrer' />\n\
<meta name='viewpoint' content='width=device-width,initial-scale=1.0' />\n\
\n\
<style>\n\
body { margin: 15px; }\n\
#content { max-width: 70ch; }\n\
.permalink { margin-left: 10px; }\n\
</style>\n\
</head>\n\
<body>\n\
<header>\n\
<nav id='navbar'>\n"
printf "\
<a href='%s'>home</a> | \
<a href='%s'>notes</a> | \
<a href='%s'>useful</a> | \
<a href='%s'>howto</a> \n", \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/index.html"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/notes/index.html"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/useful/index.html"), \
relpath(getDirname(FILENAME), ENVIRON["PWD"] "/src/howto/index.html")
printf "</nav>\n\
</header><hr>\n\
<article id='content'>\n\
%s\n\
</article>\n\
</body>\n\
</html>", body
}