summaryrefslogtreecommitdiff
path: root/example/entries/entries.sh
blob: 0479d96aba7eb3d25a99d0189e333e69a28cfe20 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh

# add a special header to all entries
cat << EOF
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$1</title>
</head>
<body>
<h1>my blog</h1>
EOF

# make this page be the index if it is called with no arguments
[ -z "$1" ] && {
    cat << EOF
    <h2>blog entries</h2>
    <ul>
EOF
    # list all the files in the directory
    for file in *.md; do
        printf "<li><a href=\"%s\">%s</a></li>" "${file%.*}.html" "$file"
    done

    cat << EOF
    </ul>
EOF

} || {
    # convert the markdown page to html text
    md2html $1

    # add a back button
    cat << EOF
<span><a href="entries.html">go back to list</a></span>
EOF
}

# and a footer
cat << EOF
</body>
</html>
EOF