Summary Files Commits Branches @commit @diff @stats
path: root / meta.awk
blob: d0aacbb67c2574df795b0597989bff2347f93b9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
BEGIN {
	FS="\t"
	while ((getline < ENVIRON["META"]) > 0) {
		if ($1 == "") continue
		meta_title[$1] = $2 " \\&mdash; Syndamia"
		meta_description[$1] = $3
		if (length($3) > 200)
			print "Description for file \"" $1 "\" is longer than 200 characters!", "Shorten the description field in the \"" ENVIRON["META"] "\" file." > "/dev/stderr"
	}
	FS=" "

	HEADER = getfile("./html/header.html")
	FOOTER = getfile("./html/footer.html")

	for (i = ARGC; i > 0; --i) {
		if (!ARGV[i]) continue

		start = HEADER
		FILENAME = substr(ARGV[i], length(ENVIRON["GEN_DIR"]) + 2)
		gsub(/\$TITLE/, meta_title[FILENAME], start)
		gsub(/\$DESCRIPTION/, meta_description[FILENAME], start)

		print start getfile(ARGV[i]) FOOTER > ARGV[i]
	}
}

function getfile(filename,    status, linebuf, filebuf) {
	while ((status = getline linebuf < filename) > 0)
		filebuf = filebuf linebuf ORS
	close(filename)
	sub(ORS "$", "", filebuf)
	return filebuf
}