another refactor

This commit is contained in:
Abdullah Islam 2023-05-07 17:51:33 +06:00
parent c43c0cc3b5
commit 048822cdae
4 changed files with 44 additions and 32 deletions

View File

@ -2,7 +2,12 @@ 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 html/sitemap.html
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/*

View File

@ -16,26 +16,29 @@ function relpath(base, path, resolvedPath, pathComponents) {
}
function resolvePath(base, path, resolvedPath, pathComponents) {
pathComponents[1] = ""
sub("/$", "", path)
split(path, pathComponents, "/")
# pathComponents[1] = ""
# sub("/$", "", path)
# split(path, pathComponents, "/")
if (pathComponents[1] == "")
return path
else if (pathComponents[1] == ".") {
resolvedPath = base
for (i = 2; i < length(pathComponents); i++)
# if (pathComponents[1] == "")
# return path
# else if (pathComponents[1] == ".") {
# resolvedPath = base
# for (i = 1; i < length(pathComponents) + 1; i++)
resolvedPath = resolvedPath "/" pathComponents[i]
}
else if (pathComponents[1] == "..") {
resolvedPath = getDirname(base) path
}
# }
# else if (pathComponents[1] == "..")
# resolvedPath = getDirname(base) path
# return resolvedPath
sprintf("realpath \"%s\"", path) | getline resolvedPath
return resolvedPath
}
function convertToFilename(string, result) {
result = tolower(string)
sub("^([ ]*)", "", result)
sub("([ ]*)$", "", result)
gsub(" ", "_", result)
return result
}

View File

@ -1,17 +1,16 @@
BEGIN {
FS = " "
title = "techn0path - no title"
articleBody = ""
subHeadings[1] = 0
FS = " "
}
/^#/ {
match($0, "^#([#]*)")
headingLevel = RLENGTH
heading = substr($0, RSTART+RLENGTH)
heading = substr($0, RSTART + RLENGTH, length($0))
sub("^([ ]*)", "", text)
sub("^([ ]*)", "", heading)
if (headingLevel == 1) {
articleBody = articleBody sprintf("<h1>%s</h1>\n", heading)
@ -20,27 +19,30 @@ BEGIN {
else if (headingLevel == 2) {
articleBody = articleBody sprintf("\
<h2 id='%s'>%s</h2>\n\
<a href='#%s'>Permalink</a><br><br>\n", convertToFilename(heading), heading, convertToFilename(heading))
<a href='#%s'>Permalink</a><br><br>\n", \
convertToFilename(heading), \
heading, \
convertToFilename(heading))
subHeadings[length(subHeadings)] = heading
}
else {
else
articleBody = articleBody sprintf("<h%i>%s</h%i>\n", headingLevel, heading, headingLevel)
}
next
}
/^=>/ {
match($0, "^=>([ ]*)([^ ]*)")
descriptionStart = RSTART + RLENGTH
link = substr($0, 3, descriptionStart - 3)
description = substr($0, descriptionStart, length($0))
link = substr($0, 3, RSTART + RLENGTH - 3)
description = substr($0, RSTART + RLENGTH, length($0))
sub("^([ ]*)", "", link)
sub("^([ ]*)", "", description)
if (link !~ "^(\w*):") sub("\.gmi$", ".html", link)
if (link !~ "^([a-zA-Z0-9_]*):")
sub("\.gmi$", ".html", link)
gsub("&", "&amp;", description)
gsub("<", "&lt;", description)
@ -55,6 +57,7 @@ BEGIN {
/^```/ {
articleBody = articleBody "<pre>\n"
getline
while ($0 !~ "^```") {
gsub("&", "\&amp;")
@ -64,8 +67,10 @@ BEGIN {
gsub("\"", "\&quot;")
articleBody = articleBody $0 "\n"
getline
}
articleBody = articleBody "</pre>\n"
next
@ -73,18 +78,18 @@ BEGIN {
/^>/ {
articleBody = articleBody "<blockquote>\n"
while ($0 ~ "^>") {
while (match($0, "^>([ ]*)")) {
gsub("&", "\&amp;")
gsub("<", "\&lt;")
gsub(">", "\&gt;")
gsub("'", "\&apos;")
gsub("\"", "\&quot;")
sub("^>([ ]*)", "")
articleBody = articleBody $0 "\n"
articleBody = articleBody substr($0, RSTART + RLENGTH, length($0)) "\n"
getline
}
articleBody = articleBody "</blockquote>\n"
next
@ -107,7 +112,7 @@ END {
tocText = "<details id='toc'> <summary>Table of content</summary> <nav> <ol>\n"
for (i = 1; i < length(subHeadings); i++)
tocText = tocText "<li><a href='#" convertToFilename(subHeadings[i]) "'>" subHeadings[i] "</a></li>\n"
tocText = tocText sprintf("<li><a href='#%s'>%s</a></li>\n", convertToFilename(subHeadings[i]), subHeadings[i])
tocText = tocText "</ol> </nav> </details>"
}

View File

@ -15,10 +15,9 @@ FILENAME != filename {
/^=>/ {
match($0, "^=>([ ]*)([^ ]*)")
descriptionStart = RSTART + RLENGTH
link = substr($0, 3, descriptionStart - 3)
description = substr($0, descriptionStart, length($0))
link = substr($0, 3, RSTART + RLENGTH - 3)
description = substr($0, RSTART + RLENGTH, length($0))
sub("^([ ]*)", "", link)
sub("^([ ]*)", "", description)