noxz-sites

A collection of a builder and various scripts creating the noxz.tech sites
git clone https://noxz.tech/git/noxz-sites.git
noxz-sites

commit: 5f8ca255fd6caf9dfb2b8a8d6971e0c2185c7635
parent: 486385f711eaa6f8205082f6b001ccae7e0c5345
author: Chris Noxz <chris@noxz.tech>
date:   Mon, 27 Jun 2022 10:58:10 +0200
add a somewhat dirty fix for dot files resulting in 403 errors
Mbuild40+++++++++++++++++---
1 file changed, 35 insertions(+), 5 deletions(-)
diff --git a/build b/build
@@ -14,6 +14,7 @@ SITE_GIT_COMMIT_PH="repo-logs"
 SITE_GIT_COMMIT_COUNT="15"
 SITE_WWW=
 SITE_HTML=
+SITE_REPLACE_DOT=1
 # ------------------------------ config files ------------------------------- #
 CFG_DIR="./config"
 # ------------------- groff www macro configuration files ------------------- #
@@ -27,6 +28,27 @@ CFG_GIT_HEAD_HTML="${CFG_DIR}/git_head.html"
 CFG_SITEMAP_XML="${CFG_DIR}/sitemap.xml"
 CFG_SITEMAP_XML_ITEM="${CFG_DIR}/sitemap_item.xml"
 
+# helper function to fix dot files if asked to do so
+# shellcheck disable=SC2120
+fix_dot_file() {
+	if [ ${SITE_REPLACE_DOT} -ne 1 ]; then
+		if [ ! -t 0 ]; then
+			cat -
+		elif [ -n "${1}" ]; then
+			echo "${1}"
+		fi
+	else
+		if [ ! -t 0 ]; then
+			cat -
+		elif [ -n "${1}" ]; then
+			echo "${1}"
+		fi                                                                  \
+		| sed                                                               \
+			-e "s,/\.,/_\.,g"                                               \
+			-e "s,^\.,_\.,g"
+	fi
+}
+
 # helper function to html encode stdin
 # shellcheck disable=SC2120
 html_encode() {
@@ -141,7 +163,7 @@ render_main_menu() {
 					"${ff}"                                                 \
 					"${fn}")
 				# dump output to buffer if existing (sub menu)
-				[ "${menu_output}" != "" ]                                    \
+				[ "${menu_output}" != "" ]                                  \
 				&& menu_buffer=$(printf '%s<ul>%s</ul>'                     \
 					"${menu_buffer}"                                        \
 					"${menu_output}")
@@ -193,7 +215,7 @@ render_main_menu() {
 
 render_main_menu_extra() {
 	printf '<li><a class="%s" href="%s">%s</a></li>\n'                      \
-		"twtxt" "//[site]/twtxt.txt" "twtxt"                                         \
+		"twtxt" "//[site]/twtxt.txt" "twtxt"                                \
 	| awk                                                                   \
 	'
 		BEGIN {
@@ -474,7 +496,7 @@ render_git_repo() {
 		| grep '^100[0-9][0-9][0-9]$' -A1                                   \
 		| grep -v '^--$\|^100[0-9][0-9][0-9]$'                              \
 		| while read -r file; do
-			file_path="${repo_path_file}/${file}"
+			file_path="$(echo "${repo_path_file}/${file}" | fix_dot_file)"
 			mkdir -p "${file_path%/*}"
 			render_git_file "${1}/${2}" "${file}" > "${file_path}.html.tmp"
 		done
@@ -545,11 +567,19 @@ render_git_repo() {
 	git -C "${1}/${2}" ls-tree                                              \
 		-r --format="%(objectmode)%x0a%(path)%x0a%(objectsize)" HEAD        \
 	| html_encode                                                           \
+	| fix_dot_file                                                          \
 	| awk '
+		function dotrep(data)
+		{
+			output = data
+			gsub(/\/_\./, "/.", output)
+			gsub(/^_\./, ".", output)
+			return output
+		}
+
 		function oct2sym(data)
 		{
 			type = substr(data, 0, 3)
-
 			if (type == "100") {
 				type = "-"
 			} else if (type == "060") {
@@ -596,7 +626,7 @@ render_git_repo() {
 				printf "\t\t\t<tr>"
 				for (i = 0; i < 3; i++) {
 					if (i == 1 && substr(entry[0], 0, 3) == "100") {
-						printf "<td><a href=\"./file/%s.html\">%s</a></td>",entry[i],entry[i]
+						printf "<td><a href=\"file/%s.html\">%s</a></td>", entry[i], dotrep(entry[i])
 					} else {
 						printf "<td>%s</td>", i == 0 ? oct2sym(entry[i]) : entry[i]
 					}