diff options
| -rw-r--r-- | README.md | 1 | ||||
| -rwxr-xr-x | gemtexter | 7 | ||||
| -rw-r--r-- | lib/atomfeed.source.sh | 7 | ||||
| -rw-r--r-- | lib/generate.source.sh | 8 | ||||
| -rw-r--r-- | lib/log.source.sh | 4 |
5 files changed, 23 insertions, 4 deletions
@@ -28,6 +28,7 @@ These are the requirements of the `gemtexter` static site generator script: * GNU Date * GNU Grep * Git +* XMLLint (optional for validating the atom feed syntax) The script is tested on a recent Fedora Linux. For *BSD or macOS, you would need to install GNU Sed, GNU Date, GNU Grep and a newer version of Bash. @@ -10,6 +10,7 @@ declare -r VERSION_DESCR=develop declare DATE=date declare SED=sed declare GREP=grep +declare XMLLINT='' which gdate &>/dev/null && DATE=gdate which gsed &>/dev/null && SED=gsed which ggrep &>/dev/null && GREP=ggrep @@ -70,6 +71,12 @@ check_dependencies () { exit 2 fi done + + if ! xmllint --version &>/dev/null; then + log WARN "WARN, \"xmllint\" command is not installed, but it's recommended!" + else + export XMLLINT=xmllint + fi } setup () { diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh index 65afa5a..7e7124d 100644 --- a/lib/atomfeed.source.sh +++ b/lib/atomfeed.source.sh @@ -143,6 +143,13 @@ ATOMENTRY </feed> ATOMFOOTER + if [ -n "$XMLLINT" ]; then + log INFO 'XMLLinting Atom feed' + $XMLLINT "$atom_file.tmp" >/dev/null || + log PANIC "Atom feed $atom_file.tmp isn't valid XML, please re-try" + log INFO 'Atom feed is OK' + fi + # Delete the 3rd line of the atom feeds (global feed update timestamp) if ! diff -u <($SED 3d "$atom_file") <($SED 3d "$atom_file.tmp"); then log INFO 'Feed got something new!' diff --git a/lib/generate.source.sh b/lib/generate.source.sh index 9a9e90b..281fbe0 100644 --- a/lib/generate.source.sh +++ b/lib/generate.source.sh @@ -129,7 +129,7 @@ generate::fromgmi () { # Add content while read -r src; do # User can specify a content filter - if test ! -z "$CONTENT_FILTER" && ! $GREP -q "$CONTENT_FILTER" <<< "$src"; then + if test -n "$CONTENT_FILTER" && ! $GREP -q "$CONTENT_FILTER" <<< "$src"; then continue fi @@ -188,13 +188,13 @@ generate::fromgmi () { # Only generate draft posts generate::draft () { - if [ ! -z "$CONTENT_FILTER" ]; then + if [ -n "$CONTENT_FILTER" ]; then log ERROR "ERROR, you can't set a content filter manually in draft mode" exit 2 fi CONTENT_FILTER=DRAFT- - generate::fromgmi $@ + generate::fromgmi "$@" log INFO 'For HTML preview, open in your browser:' - find $CONTENT_BASE_DIR/html -name DRAFT-\*.html + find "$CONTENT_BASE_DIR/html" -name DRAFT-\*.html } diff --git a/lib/log.source.sh b/lib/log.source.sh index 2feb119..a93a35d 100644 --- a/lib/log.source.sh +++ b/lib/log.source.sh @@ -28,4 +28,8 @@ log::_pipe () { while read -r line; do echo "$level|$stamp|$pid|$callee|$line" >&2 done + + if [ "$level" = PANIC ]; then + exit 2 + fi } |
