summaryrefslogtreecommitdiff
path: root/.zs/generate_nav
blob: 28289afa42cc730025018a218fe48c48545f80c8 (plain)
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
#!/bin/sh

echo "/:home /projects.html:projects /posts.html:ramblings" | awk '
function normalize(file) {
    sub(".[^.]*$", "", file)
    sub(".*/", "", file)
    return file
}

{
    for (i=1; i<=NF; i++) {
        match($i, /:.+/)
        name = substr($i, RSTART+1, RLENGTH)

        match($i, /.+:/)
        file = substr($i, RSTART, RLENGTH-1)

        parsed_file = ENVIRON["ZS_FILE"]

        if (normalize(file) == normalize(parsed_file) || (normalize(parsed_file) == "index" && file == "/")) {
            name = sprintf("[%s]", name)
        }

        printf "<li><a href=\"%s\">%s</a></li>", file, name
        if (i<NF) print ""
    }
}'