about summary refs log tree commit diff stats
path: root/generate
diff options
context:
space:
mode:
Diffstat (limited to 'generate')
-rwxr-xr-xgenerate30
1 files changed, 22 insertions, 8 deletions
diff --git a/generate b/generate
index 0d5705d..47fb755 100755
--- a/generate
+++ b/generate
@@ -1,15 +1,29 @@
 #!/bin/sh
-test $# -ne 1 &&
-	{
-		echo "Usage: ${0} <xslt-stylesheet-file>"
-		exit 2
-	}
+
+usage() {
+	echo "Usage: ${0} <xslt-stylesheet-file> [atom | html]"
+	exit 2
+}
+
+test $# -ne 2 && usage "$0"
 
 echo "$1" | grep 'derstandard.at/international/asien/hongkong' -q && url='https://www.derstandard.at/international/asien/hongkong'
 # TODO: Add option to aggregate older articles using e.g. https://www.derstandard.at/international/asien/hongkong/2020/1/1
 
-curl -sL -b cookies "$url" |
+out=$(curl -sL -b cookies "$url" |
 	xmllint --html --xpath '//main' /dev/stdin 2>/dev/null |
-	xsltproc "$1" /dev/stdin |
-	xmllint --format /dev/stdin \
+	xsltproc "$1" /dev/stdin)
+
+case "$2" in
+atom)
+	printf "%s" "$out" | xmllint --format /dev/stdin \
 		>"$(dirname "$1")/feed.xml"
+	;;
+html)
+	printf "%s" "$out" | xmllint --format --html /dev/stdin \
+		>"$(dirname "$1")/index.html"
+	;;
+*)
+	usage "$0"
+	;;
+esac