aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgenerate-html.sh85
1 files changed, 51 insertions, 34 deletions
diff --git a/generate-html.sh b/generate-html.sh
index c86ba71..1faeaf4 100755
--- a/generate-html.sh
+++ b/generate-html.sh
@@ -1,47 +1,64 @@
#!/bin/bash
-date=$(date -u "+%Y-%m-%d %H:%M:%S")
-repo="$(git config --get remote.origin.url)/tree/main/pocs"
-mkdir -p docs/ &>/dev/null
-
-if test -d pandoc/assets; then
- cp -r pandoc/assets docs/
-else
- printf "%s\n" "[err] pandoc/assets/ dir not found"
+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
-fi
+}
+
+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 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 "repo=${repo}" \
- --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 docs/index.html); then \
- printf "%s\n" "[inf] successfully generated html"
- > docs/.nojekyll
+ if test -d pandoc/assets; then
+ cp -r pandoc/assets "${output}"
else
- printf "%s\n" "[err] error generating html"
+ printf "%s\n" "[err] pandoc/assets/ dir not found"
+ exit 1
fi
- if command -v tidy &>/dev/null; then
- if tidy --indent yes --wrap 0 -m --quiet yes --indent-spaces 2 --tidy-mark no docs/index.html; then
- printf "%s\n" "[inf] prettified html"
+ 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] failed to prettify html"
+ 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" "[warn] tidy not found, skipping html prettify"
+ printf "%s\n" "[err] pandoc not found"
+ exit 1
fi
else
- printf "%s\n" "[err] pandoc not found"
- exit 1
+ usage
fi