added gemini sitemap functionality

This commit is contained in:
Abdullah Islam 2023-05-01 09:51:16 +06:00
parent 384e6bf008
commit fd60aca75d
3 changed files with 62 additions and 8 deletions

View File

@ -1,7 +1,8 @@
SHELL = /bin/sh
SOURCES = $(shell find src/ -type f)
SITEMAP_INDEX_FILES = $(filter %/index.gmi , $(SOURCES))
all: subdirs $(SOURCES:src/%.gmi=html/%.html) $(SOURCES:src/%.gmi=gmi/%.gmi) subdirs
all: subdirs $(SOURCES:src/%.gmi=html/%.html) $(SOURCES:src/%.gmi=gmi/%.gmi) gmi/sitemap.gmi # html/sitemap.html
clean:
rm -rf html/* gmi/*
@ -13,4 +14,10 @@ html/%.html: src/%.gmi tmpl/html.awk
mawk -f tmpl/html.awk -- $< > $@
gmi/%.gmi: src/%.gmi tmpl/gemini.awk
mawk -f tmpl/gemini.awk $< > $@
mawk -f tmpl/gemini.awk -- $< > $@
# html/sitemap.html: $(SITEMAP_INDEX_FILES) tmpl/sitemap_html.awk
# mawk -f tmpl/sitemap_html.awk $(SITEMAP_INDEX_FILES) > $@
gmi/sitemap.gmi: $(SITEMAP_INDEX_FILES) tmpl/sitemap_gmi.awk
mawk -f tmpl/sitemap_gmi.awk $(SITEMAP_INDEX_FILES) > $@

View File

@ -5,10 +5,8 @@ function getDirname(path, pathComponents, npathComponents, dirname) {
dirname = ""
if (npathComponents < 1) return "."
for (i = 1; i < npathComponents; i++)
else for (i = 1; i < npathComponents; i++)
dirname = dirname pathComponents[i] "/"
return dirname
}
@ -21,6 +19,7 @@ BEGIN {
FS = " "
title = "techn0path - no title"
body = ""
subheadings[0] = ""
nsubheadings = 0
}
@ -37,7 +36,6 @@ BEGIN {
body = body "<h2>" $0 "</h2>\n"
subheadings[nsubheadings] = $0
nsubheadings ++
next
}
@ -74,6 +72,12 @@ BEGIN {
body = body "<pre>"
getline
while ($0 != "```") {
gsub("<", "\&lt;")
gsub(">", "\&gt;")
gsub("&", "\&amp;")
gsub("\'", "\&apos;")
gsub("\"", "\&quot;")
body = body $0 "\n"
getline
}
@ -99,7 +103,7 @@ END {
navbar = sprintf("<a href='%s'>home</a> | \
<a href='%s'>notes</a> | \
<a href='%s'>useful</a> | \
<a href='%s'>howto</a>", relpath(dirname, ENVIRON["PWD"] "/src/index.html"), relpath(dirname, ENVIRON["PWD"] "/src/notes/index.html"), relpath(dirname, ENVIRON["PWD"] "/src/useful/index.html"), relpath(dirname, ENVIRON["PWD"] "/src/howto/index.html"))
<a href='%s'>howto</a> \n", relpath(dirname, ENVIRON["PWD"] "/src/index.html"), relpath(dirname, ENVIRON["PWD"] "/src/notes/index.html"), relpath(dirname, ENVIRON["PWD"] "/src/useful/index.html"), relpath(dirname, ENVIRON["PWD"] "/src/howto/index.html"))
toc = ""
if (nsubheadings > 0) {
@ -134,7 +138,7 @@ body { margin: 15px; }\n\
<nav id='navbar'>\n\
%s\n\
</nav>\n\
</header>\n\
</header><hr>\n\
<article id='content'>\n\
%s\n\
%s\n\

43
tmpl/sitemap_gmi.awk Normal file
View File

@ -0,0 +1,43 @@
BEGIN {
printf "# Sitemap\n\
This document is automatically generated. See:\n\
=> howto/website-generation.gmi\n"
}
function getDirname(path, pathComponents, npathComponents, dirname) {
pathComponents[1] = ""
sub("/$", "", path)
npathComponents = split(path, pathComponents, "/")
dirname = ""
if (npathComponents < 1) return "."
else for (i = 1; i < npathComponents; i++)
dirname = dirname pathComponents[i] "/"
return dirname
}
/^#[^#]/ {
sub("^#([ ]*)", "")
printf "## %s\n", $0
}
/^=>/ {
if (match($1, "^=>([^ ]*)")) {
link = $1
sub("^=>", "", link)
$1 = ""
description = $0
} else if (NF < 2) next
else {
link = $2
$1 = ""
$2 = ""
description = $0
}
sub("^([ ]*)", "", description)
sprintf("realpath %s/%s", getDirname(FILENAME), link) | getline absolutePath
sprintf("realpath --relative-to=\"%s\" \"%s\"", ENVIRON["PWD"], absolutePath) | getline link
printf "=> %s %s\n", link, description
}