-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncs.awk
More file actions
71 lines (60 loc) · 1.34 KB
/
Copy pathfuncs.awk
File metadata and controls
71 lines (60 loc) · 1.34 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function header(page, title) {
gsub("\\$\\$TITLE\\$\\$", title, page)
gsub("\\$\\$EXT\\$\\$", ENVIRON["EXT"], page)
return page
}
function read_file(filename) {
file = ""
while(getline < filename) {
if (file)
file = file "\n" $0
else
file = $0
}
close(filename)
return file
}
function parse_post(filename, info, i) {
delete info
info["tags"][0] = "untagged"
info["template"] = "default"
info["filename"] = filename
info["path"] = strip_post_filename(filename)
FS=":"
while(getline < filename && $0 != "--- body ---") {
# Trim whitespace
sub(/[ \t]+$/, "", $2);
sub(/^[ \t]+/, "", $2);
if ($1 == "tags")
patsplit($2, info["tags"], "([^, ]+[^,]+[^, ]+)")
else
info[$1] = $2
}
FS=" "
tags_string = ""
if (info["tags"][0] != "untagged") {
for (i in info["tags"]) {
tag = info["tags"][i]
if (!tag)
continue
if (i > 1)
tags_string = tags_string ", "
tags_string = tags_string sprintf("<a href=\"LINK(tags/%s)\">%s</a>", tag, tag)
}
}
info["tags_string"] = tags_string
info["body"] = read_file(filename)
}
function print_header_and_stop(filename) {
while (getline < filename) {
print
if ($0 == "--- body ---")
break
}
}
function strip_post_filename(file) {
sub("^"ENVIRON["PAGES_DIR"]"/", "", file)
sub("^"ENVIRON["TMP_HTML"]"/", "", file)
sub("\\..*$", "", file)
return file
}