aboutsummaryrefslogtreecommitdiff
path: root/generate-html.sh
blob: 1faeaf495590c9aa9c14ea4f855957289ad7c17f (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash

usage() {
    printf "%s\n" \
        "generate html page for available pocs" \
        "usage: $(basename ${0}) -o </path/to/output/dir> -p <path/to/pocs/dir>"
    exit 1
}

while getopts "o:p:h" opts; do
    case "${opts}" in
        o) output="${OPTARG}";;
        p) pocs="${OPTARG}";;
        h) usage;;
        *) usage;;
    esac
done

if test "${output}" && test "${pocs}"; then
    date=$(date -u "+%Y-%m-%d %H:%M:%S")
    mkdir -p "${output}" &>/dev/null

    if test -d pandoc/assets; then
        cp -r pandoc/assets "${output}"
    else
        printf "%s\n" "[err] pandoc/assets/ dir not found"
        exit 1
    fi

    if command -v pandoc &>/dev/null; then
        count=$(cat "${pocs}/README.md" | wc -l)
        size=$(du -sh "${pocs}" | awk '{print $1}')
        if (tac "${pocs}/README.md" | pandoc                    \
            -s                                                  \
            --toc                                               \
            --metadata "title=cve proof of concepts"            \
            --metadata "date=${date} utc"                       \
            --metadata "rss_url=https://cve.heqnx.com/feed.xml" \
            --metadata "count=${count}"                         \
            --metadata "size=${size}"                           \
            --template pandoc/template.html                     \
            --lua-filter=pandoc/add-target-blank.lua            \
            -o "${output}/index.html"); then                    \
            printf "%s\n" "[inf] successfully generated html"
        else
            printf "%s\n" "[err] error generating html"
        fi

        if command -v tidy &>/dev/null; then
            if tidy --indent yes --wrap 0 -m --quiet yes --indent-spaces 2 --tidy-mark no "${output}/index.html"; then
                printf "%s\n" "[inf] prettified html"
            else
                printf "%s\n" "[err] failed to prettify html"
            fi
        else
            printf "%s\n" "[warn] tidy not found, skipping html prettify"
        fi
    else
        printf "%s\n" "[err] pandoc not found"
        exit 1
    fi
else
    usage
fi