Summary Files Commits Branches @commit @diff @stats
path: root / awk-edits / Pagenav.awk
blob: 13c3fee9a5402f7e5fc0cfa85ea23680374424d9 (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
34
35
36
37
38
39
40
41
42
43
44
45
#
# == About ==
#
# I call pagenav the stuff directly below the first h1. These include file dates
# and GitLab source link.
# Currently it only works for blog and tutorial pages.
#
# This is by far the most hard-coded and inefficient awk script in awk-edits.
# Creation and last edited dates are taken from git commits, and getting the correct info
# by file name can only be done (easily) with git log, which is unfortunately very slow.
# Another issue is that it depends on the build directories in build scripts, meaning
# it won't work without modification if you try to build it somewhere else.
#
# Split into Pagenav.awk and post-pagenav.awk

BEGIN {
	fileCheck = ARGV[1]; # FILENAME isn't available in BEGIN

	elem = "";
	if (match(fileCheck, /(blog|slides|teaching|tutorials|misc)\/.*\//)) {
		dateCreate = "";
		dateEdited = "";
		FS = "\t"
		while ((getline < "./timestamps.txt") > 0) {
			if ($1 == fileCheck) {
				dateCreate = $2;
				dateEdited = $3;
				break;
			}
		}
		FS = " " # gawk only?

		start = index(fileCheck, "website") + 8;
		elem = ORS \
"<div id=\"pagenav\">" ORS \
"	<strong>Created: " dateCreate "</strong> || <strong>Edited: " dateEdited "</strong>" ORS \
"	|| <a href=\"https://gitlab.com/Syndamia/syndamiadotcom/-/blob/master/src/" substr(fileCheck, start, length(fileCheck) - start - 3) "md\"><strong>GitLab source</strong></a>" ORS \
"</div>"
	}
}

/<h1/ && nopagenav == 0 {
	$0 = $0 elem
	nopagenav = 1
}