website/scripts/sitemap_html.awk

61 lines
1.1 KiB
Awk
Executable File

BEGIN {
body = "<h1>Sitemap</h1>"
pathComponents[1] = ""
}
{
linkAddress = FILENAME
sub("^" sourcePath, "", linkAddress)
if (link !~ "^[a-zA-Z0-9_]*:")
sub("\.gmi$", ".html", linkAddress)
split(linkAddress, pathComponents, "/")
oldFolderName = folderName
folderName = pathComponents[1]
if (oldFolderName != folderName) {
body = body sprintf("<h2>%s</h2>\n", folderName)
}
}
/^#[^#]/ {
match($0, "^#[ ]*")
title = substr($0, RSTART + RLENGTH)
}
{
body = body sprintf("<a href='%s'>%s</a><br>\n", linkAddress, title)
nextfile
}
END {
dirname = getDirname(linkAddress)
stylesheetPath = getRelativePath(dirname, sourcePath "/style.css")
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\
<link rel='stylesheet' href='%s'/>\n\
</head>\n\
<body>\n\
<header>\n\
%s\n\
</header>\n\
<article id='content'>\n\
%s\n\
</article>\n\
</body>\n\
</html>", \
stylesheetPath, \
genHTMLNavbar(FILENAME, sourcePath), \
body
}