summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorla ninpre <aaoth@aaoth.xyz>2025-12-04 16:23:10 +0300
committerla-ninpre <aaoth@aaoth.xyz>2025-12-04 16:28:52 +0300
commitd6185c275b1d83d30db413ec0c259503512b105f (patch)
tree51e14bdfddf33fdf90771973fc708fa6723b0932
parent8d169d142b6f063895555bd24b5db6390976b956 (diff)
downloadaaothxyz-decadv-d6185c275b1d83d30db413ec0c259503512b105f.tar.gz
aaothxyz-decadv-d6185c275b1d83d30db413ec0c259503512b105f.zip
day 04: add scripts to find incoming links
i said no automation, but this is somewhat innocent, i guess?
-rw-r--r--.gitignore2
-rwxr-xr-xbuild.sh26
-rw-r--r--footer.htm9
-rw-r--r--lib/inc.awk43
4 files changed, 80 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..71156ff
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+dist/
+*-inc.htm
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..bd3b5bc
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+[ ! -d dist ] && mkdir dist
+
+rm -f dist/*
+
+cp ./*.css ./*.svg ./*.png ./*.jpg dist/
+
+awk -f lib/inc.awk ./*.html
+
+for file in ./*.html; do
+ if [ "$file" = "index.html" ] ||
+ [ ! -f "${file%%.html}-inc.htm" ]; then
+ cp "$file" dist/
+ continue
+ fi
+ ed "$file" <<EOF
+?<\/body>?-r footer.htm
+?{{incoming}}?d
+-r ${file%%.html}-inc.htm
+w dist/$file
+q
+EOF
+done
+
+rm ./*-inc.htm
diff --git a/footer.htm b/footer.htm
new file mode 100644
index 0000000..1278590
--- /dev/null
+++ b/footer.htm
@@ -0,0 +1,9 @@
+<footer>
+<h2>incoming links</h2>
+<div class="win">
+{{incoming}}
+<hr>
+<p>copyright © 2025 la ninpre,
+<a href="https://creativecommons.org/licenses/by-nc/4.0/">cc by-nc 4.0</a></p>
+</div>
+</footer>
diff --git a/lib/inc.awk b/lib/inc.awk
new file mode 100644
index 0000000..b6978bc
--- /dev/null
+++ b/lib/inc.awk
@@ -0,0 +1,43 @@
+# usage: awk -f inc.awk *.html
+
+function nodot(name) {
+ if(name ~ /^\.\//){
+ name=substr(name,3);
+ }
+ return name;
+}
+
+BEGIN {
+ for(i=1;i<ARGC;i++){
+ files[nodot(ARGV[i])] = 1;
+ }
+}
+
+/<title>/ {
+ match($0, /<title>.*<\/title>/);
+ t=substr($0,RSTART+7,RLENGTH-7-8);
+ match(t, / — /);
+ title[nodot(FILENAME)]=substr(t,1,RSTART-1);
+}
+
+/<a href=/ {
+ if(match($0, /<a href="[a-zA-Z0-9].*\.html">/)){
+ l=substr($0,RSTART+9,RLENGTH-9-2);
+ incoming[l][nodot(FILENAME)]=1;
+ if(!(l in files)) {
+ printf("warning: redlink '%s' in '%s'\n", l, nodot(FILENAME));
+ }
+ }
+}
+
+END {
+ for(f in incoming){
+ split(f,fbase,".");
+ fname=fbase[1] "-inc.htm";
+ print "<ul>" > fname;
+ for(l in incoming[f]) {
+ printf("\t<li><a href=\"%s\">%s</a></li>\n",l,title[l]) >> fname;
+ }
+ printf "</ul>\n" >> fname;
+ }
+}