shithub: news2atom

Download patch

ref: 36c2bc3e210fc11e1b7aa15db04f84db7ddc7016
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Feb 9 03:51:35 EST 2021

adds generator

--- /dev/null	Sun Oct 31 09:34:01 2021
+++ b/mkfile	Tue Feb  9 03:51:35 2021
@@ -0,0 +1,8 @@
+all:VQ:
+	echo usage: mk install
+
+install:VQ: /rc/bin/news2atom
+
+/rc/bin/news2atom: news2atom
+	cp news2atom $target
+	chmod +x $target
--- /dev/null	Sun Oct 31 09:34:01 2021
+++ b/news2atom	Tue Feb  9 03:51:35 2021
@@ -0,0 +1,64 @@
+#!/bin/rc
+#
+# news2atom converter
+#
+# place files named: yyyy-mm-dd-name
+# the owner of the file is the author of the article,
+# the last modified date the <updated> value.
+#
+# sample entry:
+#
+#     First Line: Title Of Post
+#     
+#     First paragraph contains the summary of
+#     the whole entry.
+#     
+#     The rest of the file is full text.
+#
+#
+# usage: news2atom -d domain -u selfurl -t title [ -n newspath ]
+
+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]
+	exit usage
+}
+
+~ $#title 0 && { echo missing arg: title; exit usage }
+~ $#self 0 && { echo missing arg: selfurl; exit usage }
+~ $#newspath 0 && newspath=/lib/news
+
+mdate=`{date -ut}
+nl='
+'
+
+echo '<?xml version="1.0" encoding="utf-8"?>
+<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'"/>'
+
+for(f in `{ls -t $newspath}){
+	fname=`{basename $f}
+	author=`{ls -l $f}
+	author=$author(4)
+	mt=`{mtime $f}
+	pdate=`{echo $fname | sed 's/^([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])-.*$/\1/'}
+	mdate=`{date -ut $mt(1)}
+	summary=`{sed -n '3,/^$/p' $f}
+	fulltext=`'
'{sed '1,2d;3,/^$/d' $f | sed 's/^$/<\/p><p>/g'}
+	taguri=`{echo 'tag:'$domain','$pdate':'$fname}
+	title=`{sed 1q $f}
+	echo '<entry>
+	<title>'$"title'</title>
+	<author><name>'$"author'</name></author>
+	<updated>'$"mdate'</updated>
+	<summary>'$"summary'</summary>
+	<id>'$"taguri'</id>
+	<content type="html"><![CDATA[<p><b>'$"summary'</b></p><p>'$"fulltext'</p>]]></content>
+</entry>'
+}
+echo '</feed>'