From d6185c275b1d83d30db413ec0c259503512b105f Mon Sep 17 00:00:00 2001 From: la ninpre Date: Thu, 4 Dec 2025 16:23:10 +0300 Subject: day 04: add scripts to find incoming links i said no automation, but this is somewhat innocent, i guess? --- lib/inc.awk | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/inc.awk (limited to 'lib') 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/ { + match($0, /.*<\/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; + } +} -- cgit v1.2.3