ref: f4e0733bbabdcedd5de6032eea1e17f6ec66a93c
parent: 36c2bc3e210fc11e1b7aa15db04f84db7ddc7016
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Feb 9 05:22:10 EST 2021
adds stylesheet support and sample stylesheet
--- a/news2atom
+++ b/news2atom
@@ -16,13 +16,13 @@
# The rest of the file is full text.
#
#
-# usage: news2atom -d domain -u selfurl -t title [ -n newspath ]
+# usage: news2atom -d domain -u selfurl -t title [ -n newspath ] [ -s stylesheet ]
rfork e
-flagfmt='d:domain domain, u:self selfurl, n:newspath newspath, t:title title'
-if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0){
- echo 'usage: news2atom -d domain -u selfurl -t title [ -n newspath ]' >[1=2]
+flagfmt='d:domain domain, u:self selfurl, n:newspath newspath, t:title title, s:stylesheet stylesheet'
+if(! ifs=() eval `{aux/getflags $*}){
+ echo 'usage: news2atom -d domain -u selfurl -t title [ -n newspath ] [ -s stylesheet ]' >[1=2]
exit usage
}
@@ -34,12 +34,13 @@
nl='
'
-echo '<?xml version="1.0" encoding="utf-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
+echo '<?xml version="1.0" encoding="utf-8"?>'
+~ $#stylesheet 0 || echo '<?xml-stylesheet type="text/xsl" href="'$"stylesheet'"?>'
+echo '<feed xmlns="http://www.w3.org/2005/Atom">
<title>'$title'</title>
-<updated>'$mdate'</updated>'
-echo '<id>http://'$"domain'/</id>'
-echo '<link rel="self" href="'$"self'"/>'
+<updated>'$mdate'</updated>
+<id>http://'$"domain'/</id>
+<link rel="self" href="'$"self'"/>'
for(f in `{ls -t $newspath}){
fname=`{basename $f}
@@ -56,7 +57,7 @@
<title>'$"title'</title>
<author><name>'$"author'</name></author>
<updated>'$"mdate'</updated>
- <summary>'$"summary'</summary>
+ <summary type="html"><![CDATA[<p>'$"summary'</p>]]></summary>
<id>'$"taguri'</id>
<content type="html"><![CDATA[<p><b>'$"summary'</b></p><p>'$"fulltext'</p>]]></content>
</entry>'
--- /dev/null
+++ b/style.xsl
@@ -1,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:atom="http://www.w3.org/2005/Atom"
+ exclude-result-prefixes="atom"
+>
+
+<xsl:template match="/">
+<html>
+<body>
+<section>
+<xsl:apply-templates select="atom:feed" />
+<xsl:apply-templates select="atom:feed/atom:entry" />
+</section>
+</body>
+</html>
+</xsl:template>
+
+<xsl:template match="atom:feed">
+<header style="margin-bottom:80px;">
+<h1><xsl:value-of select="atom:title"/></h1>
+<p>Last updated: <xsl:value-of select="atom:updated"/></p>
+</header>
+</xsl:template>
+
+<xsl:template match="atom:entry">
+<article style="border:solid;border-width:1px 0 0 0;">
+<header>
+<h2><xsl:value-of select="atom:title"/></h2>
+<p><xsl:value-of select="atom:updated"/><br/>
+Author: <xsl:value-of select="atom:author/atom:name"/></p>
+</header>
+<p><xsl:value-of select="atom:content" disable-output-escaping="yes"/></p>
+</article>
+</xsl:template>
+
+</xsl:stylesheet>