Summary Files Commits Branches @commit @diff @stats
path: root / generate-hooks / create-title.awk
blob: f1eaa4f2f2527cea18b4d119bdd8930d1af5a7cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
BEGIN {
	h1Index = 0

	# When this loop finishes, $0 will have the first line containing an h1 header
	# tag, and h1Index will have it's starting position
	while (h1Index == 0 && getline < ARGV[1])
		h1Index = index($0, "<h1")
	close(ARGV[1]) # FILENAME isn't set during BEGIN

	# Removes the opening tag and substrings everything that is normally
	# inside the heading tag
	gsub(/<h1[^>]*>/, "")
	title = substr($0, h1Index, index($0, "</h1") - h1Index)
}

"\\[TITLE\\]" {
	gsub("\\[TITLE\\]", title)
}

{
	print
}