all repos — aaothxyz-decadv @ d6185c275b1d83d30db413ec0c259503512b105f

aaoth.xyz website, but new.

lib/inc.awk (view raw)

 1# usage: awk -f inc.awk *.html
 2
 3function nodot(name) {
 4		if(name ~ /^\.\//){
 5			name=substr(name,3);
 6		}
 7		return name;
 8}
 9
10BEGIN {
11	for(i=1;i<ARGC;i++){
12		files[nodot(ARGV[i])] = 1;
13	}
14}
15
16/<title>/ {
17	match($0, /<title>.*<\/title>/);
18	t=substr($0,RSTART+7,RLENGTH-7-8);
19	match(t, / — /);
20	title[nodot(FILENAME)]=substr(t,1,RSTART-1);
21}
22
23/<a href=/ {
24	if(match($0, /<a href="[a-zA-Z0-9].*\.html">/)){
25		l=substr($0,RSTART+9,RLENGTH-9-2);
26		incoming[l][nodot(FILENAME)]=1;
27		if(!(l in files)) {
28			printf("warning: redlink '%s' in '%s'\n", l, nodot(FILENAME));
29		}
30	}
31}
32
33END {
34	for(f in incoming){
35		split(f,fbase,".");
36		fname=fbase[1] "-inc.htm";
37		print "<ul>" > fname;
38		for(l in incoming[f]) {
39			printf("\t<li><a href=\"%s\">%s</a></li>\n",l,title[l]) >> fname;
40		}
41		printf "</ul>\n" >> fname;
42	}
43}