added tmpl/common_functions.awk, as a shared library for all the awk templates. but unfortunately i can't include it for some reason

This commit is contained in:
Abdullah Islam 2023-05-01 10:09:53 +06:00
parent fd60aca75d
commit d08244c07b
4 changed files with 23 additions and 8 deletions

View File

@ -1,8 +1,8 @@
SHELL = /bin/sh
SOURCES = $(shell find src/ -type f)
SITEMAP_INDEX_FILES = $(filter %/index.gmi , $(SOURCES))
SITEMAP_INDEX_FILES = $(filter %/index.gmi, $(SOURCES))
all: subdirs $(SOURCES:src/%.gmi=html/%.html) $(SOURCES:src/%.gmi=gmi/%.gmi) gmi/sitemap.gmi # html/sitemap.html
all: subdirs $(SOURCES:src/%.gmi=html/%.html) $(SOURCES:src/%.gmi=gmi/%.gmi) gmi/sitemap.gmi
clean:
rm -rf html/* gmi/*
@ -16,8 +16,5 @@ html/%.html: src/%.gmi tmpl/html.awk
gmi/%.gmi: src/%.gmi 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) > $@

16
tmpl/common_functions.awk Normal file
View File

@ -0,0 +1,16 @@
function getDirname(path, pathComponents, npathComponents, dirname) {
pathComponents[1] = ""
sub("/$", "", path)
npathComponents = split(path, pathComponents, "/")
dirname = ""
if (npathComponents < 2) return "."
else for (i = 1; i < npathComponents; i++)
dirname = dirname pathComponents[i] "/"
return dirname
}
function relpath(base, path, resolvedPath) {
sprintf("realpath --relative-to=\"%s\" \"%s\"", base, path) | getline resolvedPath
return resolvedPath
}

View File

@ -25,10 +25,12 @@ BEGINFILE {
=> %s home\n\
=> %s notes\n\
=> %s useful\n\
=> %s howto\n", \
=> %s howto\n\
=> %s sitemap\n", \
relpath(dirname, ENVIRON["PWD"] "/src/index.gmi"), \
relpath(dirname, ENVIRON["PWD"] "/src/notes/index.gmi"), \
relpath(dirname, ENVIRON["PWD"] "/src/useful/index.gmi"), \
relpath(dirname, ENVIRON["PWD"] "/src/howto/index.gmi")
relpath(dirname, ENVIRON["PWD"] "/src/howto/index.gmi"), \
relpath(dirname, ENVIRON["PWD"] "/src/sitemap.gmi")
}
{ print }

View File

@ -4,7 +4,7 @@ function getDirname(path, pathComponents, npathComponents, dirname) {
npathComponents = split(path, pathComponents, "/")
dirname = ""
if (npathComponents < 1) return "."
if (npathComponents < 2) return "."
else for (i = 1; i < npathComponents; i++)
dirname = dirname pathComponents[i] "/"
return dirname