about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorManuel Graf <postmaster@grafoo.at>2021-01-15 17:04:21 +0100
committerManuel Graf <postmaster@grafoo.at>2021-01-15 17:04:21 +0100
commit4ec786cd24d2eafe5b924b24958d173f5e7e9db8 (patch)
tree3938d762038762d61059ece3d140049f58b6ed5f
parent7cc673178f3c44d2509d823ea19171e2288308f9 (diff)
downloadtransfeed-4ec786cd24d2eafe5b924b24958d173f5e7e9db8.tar.gz
Add html rendering
-rw-r--r--.gitignore1
-rw-r--r--derstandard.at/international/asien/hongkong/stylesheet_html.xml25
-rwxr-xr-xgenerate30
3 files changed, 48 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index fbd9934..1591f35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 cookies
 feed.xml
+*.html
diff --git a/derstandard.at/international/asien/hongkong/stylesheet_html.xml b/derstandard.at/international/asien/hongkong/stylesheet_html.xml
new file mode 100644
index 0000000..30842e4
--- /dev/null
+++ b/derstandard.at/international/asien/hongkong/stylesheet_html.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  <xsl:output method="html" encoding="utf-8" indent="yes" />
+  <xsl:template match="/main">
+    <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;</xsl:text>
+      <head>
+        <title>derStandard.at - <xsl:value-of select="normalize-space(//header/h1)"/></title>
+        <link rel="alternate" type="application/atom+xml" href="https://grafoo.tilde.institute/transfeed/derstandard.at/international/asien/hongkong/feed.xml" />
+      </head>
+      <body>
+        <xsl:for-each select="//section">
+          <article>
+            <header>
+              <a>
+                <xsl:attribute name="href">https://www.derstandard.at<xsl:value-of select="article//a/@href"/></xsl:attribute>
+                <h1><xsl:value-of select="normalize-space(article//header/h1[@class='teaser-title'])"/></h1>
+              </a>
+              <p><time><xsl:value-of select="normalize-space(article//header/time/@datetime)"/></time></p>
+            </header>
+            <p><xsl:value-of select="normalize-space(article//header/p[@class='teaser-subtitle'])"/></p>
+          </article>
+        </xsl:for-each>
+      </body>
+  </xsl:template>
+</xsl:stylesheet>
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