consolidated navigation bar generation logic into scripts/navbar.awk. also recorded new output testing/output.html as correct.
This commit is contained in:
parent
aab35e2982
commit
59005b975c
14
Makefile
14
Makefile
|
@ -5,6 +5,8 @@ SITEMAP_INDEX_FILES = $(wildcard src/*/index.gmi)
|
|||
all: subdirs \
|
||||
$(SOURCES:src/%.gmi=html/%.html) \
|
||||
$(SOURCES:src/%.gmi=gmi/%.gmi) \
|
||||
$(SOURCES:src/%.png=html/%.png) \
|
||||
$(SOURCES:src/%.png=gmi/%.png) \
|
||||
$(SOURCES:src/%.webp=html/%.webp) \
|
||||
$(SOURCES:src/%.webp=gmi/%.webp) \
|
||||
gmi/sitemap.gmi \
|
||||
|
@ -12,9 +14,13 @@ all: subdirs \
|
|||
gmi/feed.atom \
|
||||
html/feed.atom \
|
||||
|
||||
upload:
|
||||
scp -r gmi/* techn0path@vern.cc:public_gemini
|
||||
scp -r html/* techn0path@vern.cc:public_html
|
||||
|
||||
test: testing/example.gmi testing/example.ass
|
||||
mawk -f ~/projects/awk_functions/lib.awk -f scripts/html.awk -- testing/example.gmi > testing/output.html
|
||||
mawk -f ~/projects/awk_functions/lib.awk -f scripts/gemini.awk -- testing/example.gmi > testing/output.gmi
|
||||
mawk -f scripts/navbar.awk -f ~/projects/awk_functions/lib.awk -f scripts/html.awk -- testing/example.gmi > testing/output.html
|
||||
mawk -f scripts/navbar.awk -f ~/projects/awk_functions/lib.awk -f scripts/gemini.awk -- testing/example.gmi > testing/output.gmi
|
||||
mawk -f ~/projects/awk_functions/lib.awk -f scripts/feed.awk -- testing/example.ass > testing/output.atom
|
||||
|
||||
subdirs:
|
||||
|
@ -33,10 +39,10 @@ gmi/%.webp: src/%.webp
|
|||
cp $< $@
|
||||
|
||||
html/%.html: src/%.gmi scripts/html.awk
|
||||
mawk -f ~/projects/awk_functions/lib.awk -f scripts/html.awk -- $< > $@
|
||||
mawk -f scripts/navbar.awk -f ~/projects/awk_functions/lib.awk -f scripts/html.awk -- $< > $@
|
||||
|
||||
gmi/%.gmi: src/%.gmi scripts/gemini.awk
|
||||
mawk -f ~/projects/awk_functions/lib.awk -f scripts/gemini.awk -- $< > $@
|
||||
mawk -f scripts/navbar.awk -f ~/projects/awk_functions/lib.awk -f scripts/gemini.awk -- $< > $@
|
||||
|
||||
gmi/sitemap.gmi: $(SITEMAP_INDEX_FILES) scripts/sitemap_gmi.awk
|
||||
mawk -f ~/projects/awk_functions/lib.awk -f scripts/sitemap_gmi.awk -- $(SITEMAP_INDEX_FILES) > $@
|
||||
|
|
|
@ -1,19 +1,6 @@
|
|||
BEGIN {
|
||||
getline firstLine
|
||||
if (FILENAME != "-")
|
||||
printf "Navigation:\n\
|
||||
=> %s home\n\
|
||||
=> %s notes\n\
|
||||
=> %s useful\n\
|
||||
=> %s sitemap\n\
|
||||
=> %s feed\n\n", \
|
||||
relpath(getDirname(FILENAME), "src/index.gmi"), \
|
||||
relpath(getDirname(FILENAME), "src/notes/index.gmi"), \
|
||||
relpath(getDirname(FILENAME), "src/useful/index.gmi"), \
|
||||
relpath(getDirname(FILENAME), "src/sitemap.gmi"), \
|
||||
relpath(getDirname(FILENAME), "src/feed.atom")
|
||||
{ body = body $0 "\n" }
|
||||
|
||||
printf "%s\n", firstLine
|
||||
END {
|
||||
printf "%s", genNavbarGMI(FILENAME, "src/", "gmi/")
|
||||
printf "%s", body
|
||||
}
|
||||
|
||||
{ print }
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
BEGIN {
|
||||
title = "techn0path - no title"
|
||||
articleBody = ""
|
||||
body = ""
|
||||
subHeadings[0] = ""
|
||||
FS = " "
|
||||
}
|
||||
|
||||
/^#[^#]/ {
|
||||
match($0, "^#[ ]*")
|
||||
headingText = substr($0, RSTART + RLENGTH)
|
||||
articleBody = articleBody sprintf("<h1>%s</h1>\n", headingText)
|
||||
headingText = substr($0, RSTART + RLENGTH)
|
||||
body = body sprintf("<h1>%s</h1>\n", headingText)
|
||||
title = headingText
|
||||
next
|
||||
}
|
||||
|
||||
/^##[^#]/ {
|
||||
match($0, "^##[ ]*")
|
||||
match($0, "^##[ ]*")
|
||||
headingText = substr($0, RSTART + RLENGTH)
|
||||
articleBody = articleBody sprintf("<h2 id='%s'>%s</h2>\n\
|
||||
body = body sprintf("<h2 id='%s'>%s</h2>\n\
|
||||
<a href='#%s'>Permalink</a><br/><br/>\n", \
|
||||
toFilename(headingText), \
|
||||
headingText, \
|
||||
|
@ -27,23 +26,20 @@ BEGIN {
|
|||
}
|
||||
|
||||
/^###[^#]/ {
|
||||
match($0, "^###[ ]*")
|
||||
match($0, "^###[ ]*")
|
||||
headingText = substr($0, RSTART + RLENGTH)
|
||||
articleBody = articleBody sprintf("<h3>%s</h3>\n", headingText)
|
||||
body = body sprintf("<h3>%s</h3>\n", headingText)
|
||||
next
|
||||
}
|
||||
|
||||
/^=>/ {
|
||||
match($0, "^=>[ ]*[^ ]*")
|
||||
match($0, "^=>[ ]*[^ ]*")
|
||||
link = substr($0, 3, RLENGTH - 2)
|
||||
description = substr($0, RSTART + RLENGTH)
|
||||
|
||||
sub("^[ ]*", "", link)
|
||||
sub("^[ ]*", "", description)
|
||||
|
||||
if (description == "")
|
||||
description = link
|
||||
|
||||
if (description == "") description = link
|
||||
if (link !~ "^[a-zA-Z0-9_]*:")
|
||||
sub("\.gmi$", ".html", link)
|
||||
|
||||
|
@ -53,12 +49,12 @@ BEGIN {
|
|||
gsub("'", "'", description)
|
||||
gsub("\"", """, description)
|
||||
|
||||
articleBody = articleBody sprintf("<a href='%s'>%s</a><br>\n", link, description)
|
||||
body = body sprintf("<a href='%s'>%s</a><br>\n", link, description)
|
||||
next
|
||||
}
|
||||
|
||||
/^```/ {
|
||||
articleBody = articleBody "<pre>\n"
|
||||
body = body "<pre>\n"
|
||||
getline
|
||||
while ($0 !~ "^```") {
|
||||
gsub("&", "\&")
|
||||
|
@ -67,15 +63,15 @@ BEGIN {
|
|||
gsub("'", "\'")
|
||||
gsub("\"", "\"")
|
||||
|
||||
articleBody = articleBody $0 "\n"
|
||||
body = body $0 "\n"
|
||||
if (getline != 1) break
|
||||
}
|
||||
articleBody = articleBody "</pre>\n"
|
||||
body = body "</pre>\n"
|
||||
next
|
||||
}
|
||||
|
||||
/^>/ {
|
||||
articleBody = articleBody "<blockquote>\n"
|
||||
body = body "<blockquote>\n"
|
||||
while (match($0, "^>[ ]*")) {
|
||||
text = substr($0, RSTART + RLENGTH)
|
||||
gsub("&", "\\&", text)
|
||||
|
@ -84,15 +80,15 @@ BEGIN {
|
|||
gsub("'", "\\'", text)
|
||||
gsub("\"", "\\"", text)
|
||||
|
||||
articleBody = articleBody text "<br>\n"
|
||||
body = body text "<br>\n"
|
||||
if (getline != 1) break
|
||||
}
|
||||
articleBody = articleBody "</blockquote>\n"
|
||||
body = body "</blockquote>\n"
|
||||
next
|
||||
}
|
||||
|
||||
/^\*/ {
|
||||
articleBody = articleBody "<ul>\n"
|
||||
body = body "<ul>\n"
|
||||
while (match($0, "^\\*[ ]*")) {
|
||||
gsub("&", "\&")
|
||||
gsub("<", "\<")
|
||||
|
@ -100,10 +96,10 @@ BEGIN {
|
|||
gsub("'", "\'")
|
||||
gsub("\"", "\"")
|
||||
|
||||
articleBody = articleBody sprintf("<li>%s</li>\n", substr($0, RSTART + RLENGTH))
|
||||
body = body sprintf("<li>%s</li>\n", substr($0, RSTART + RLENGTH))
|
||||
if (getline != 1) break
|
||||
}
|
||||
articleBody = articleBody "</ul>\n"
|
||||
body = body "</ul>\n"
|
||||
next
|
||||
}
|
||||
|
||||
|
@ -113,7 +109,7 @@ BEGIN {
|
|||
gsub(">", "\>")
|
||||
gsub("'", "\'")
|
||||
gsub("\"", "\"")
|
||||
articleBody = articleBody sprintf("<p>%s</p>\n", $0)
|
||||
body = body sprintf("<p>%s</p>\n", $0)
|
||||
}
|
||||
|
||||
END {
|
||||
|
@ -129,20 +125,7 @@ END {
|
|||
tocText = tocText "</ol> </details>\n"
|
||||
}
|
||||
|
||||
if (FILENAME == "-") navbarText = ""
|
||||
else
|
||||
navbarText = sprintf("<nav id='navbar'>\n\
|
||||
<a href='%s'>home</a> | \
|
||||
<a href='%s'>notes</a> | \
|
||||
<a href='%s'>useful</a> | \
|
||||
<a href='%s'>sitemap</a> | \
|
||||
<a href='%s'>feed</a>\
|
||||
</nav>\n", \
|
||||
relpath(getDirname(FILENAME), "src/index.html"), \
|
||||
relpath(getDirname(FILENAME), "src/notes/index.html"), \
|
||||
relpath(getDirname(FILENAME), "src/useful/index.html"), \
|
||||
relpath(getDirname(FILENAME), "src/sitemap.html"), \
|
||||
relpath(getDirname(FILENAME), "src/feed.atom"))
|
||||
navbarText = genNavbarHTML(FILENAME, "src/", "html/")
|
||||
|
||||
printf "<!DOCTYPE html>\n\
|
||||
<html>\n\
|
||||
|
@ -172,5 +155,5 @@ body { margin: 20px; }\n\
|
|||
title, \
|
||||
navbarText, \
|
||||
tocText, \
|
||||
articleBody
|
||||
body
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
function genNavbarHTML(filename, sourcePath, outputPath) {
|
||||
dirname = getDirname(filename)
|
||||
gsub(/(\.|\[|\]|\*)/, "\\&", sourcePath)
|
||||
gsub(sourcePath, outputPath, dirname)
|
||||
gsub(sourcePath, outputPath, filename)
|
||||
|
||||
if (filename == "-" || filename == "/dev/stdout/" || filename == "-")
|
||||
return ""
|
||||
else
|
||||
return sprintf("<nav id='navbar'>\n\
|
||||
<a href='%s'>home</a> | \n\
|
||||
<a href='%s'>notes</a> | \n\
|
||||
<a href='%s'>useful</a> | \n\
|
||||
<a href='%s'>sitemap</a> | \n\
|
||||
<a href='%s'>feed</a>\n\
|
||||
</nav>\n", \
|
||||
relpath(dirname, outputPath "/index.html"), \
|
||||
relpath(dirname, outputPath "/notes/index.html"), \
|
||||
relpath(dirname, outputPath "/useful/index.html"), \
|
||||
relpath(dirname, outputPath "/sitemap.html"), \
|
||||
relpath(dirname, outputPath "/feed.atom"))
|
||||
}
|
||||
|
||||
function genNavbarGMI(filename, sourcePath, outputPath) {
|
||||
dirname = getDirname(filename)
|
||||
gsub(/(\.|\[|\]|\*)/, "\\&", sourcePath)
|
||||
gsub(sourcePath, outputPath, dirname)
|
||||
gsub(sourcePath, outputPath, filename)
|
||||
|
||||
if (filename == "-" || filename == "/dev/stdout/" || filename == "-")
|
||||
return ""
|
||||
else
|
||||
return sprintf("Navigation:\n\
|
||||
=> %s home\n\
|
||||
=> %s notes\n\
|
||||
=> %s useful\n\
|
||||
=> %s sitemap\n\
|
||||
=> %s feed\n", \
|
||||
relpath(dirname, outputPath "/index.html"), \
|
||||
relpath(dirname, outputPath "/notes/index.html"), \
|
||||
relpath(dirname, outputPath "/useful/index.html"), \
|
||||
relpath(dirname, outputPath "/sitemap.html"), \
|
||||
relpath(dirname, outputPath "/feed.atom"))
|
||||
}
|
|
@ -16,7 +16,12 @@ body { margin: 20px; }
|
|||
<body>
|
||||
<header>
|
||||
<nav id='navbar'>
|
||||
<a href='../src/index.html'>home</a> | <a href='../src/notes/index.html'>notes</a> | <a href='../src/useful/index.html'>useful</a> | <a href='../src/sitemap.html'>sitemap</a> | <a href='../src/feed.atom'>feed</a> </nav>
|
||||
<a href='../html/index.html'>home</a> |
|
||||
<a href='../html/notes/index.html'>notes</a> |
|
||||
<a href='../html/useful/index.html'>useful</a> |
|
||||
<a href='../html/sitemap.html'>sitemap</a> |
|
||||
<a href='../html/feed.atom'>feed</a>
|
||||
</nav>
|
||||
|
||||
</header><hr>
|
||||
<article id='content'>
|
||||
|
|
Loading…
Reference in New Issue