shithub: news2atom

ref: fb5ab9787a06b5ab0002147c94957a65782607f9
dir: /news2html/

View raw version
#!/bin/rc
#
# news2html converter - basically the same as news2atom
#
# 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 ] [ -s stylesheet ]

rfork e

flagfmt='d:domain domain, u:self selfurl, n:newspath newspath, t:title title, s:stylesheet stylesheet, m:max maxentries'
if(! ifs=() eval `{aux/getflags $*}){
	echo 'usage: news2atom -d domain -u selfurl -t title [ -n newspath ] [ -s stylesheet ] [ -m maxentries ]' >[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
~ $#max 0 && max=30

mdate=`{date -ut}
nl='
'
n=()

echo '<html><body><section>'
echo '<feed xmlns="http://www.w3.org/2005/Atom">
<header style="margin-bottom:80px;">
<h1>'$title'</h1>
<p>Last updated: '$mdate'</p>
</header>'

for(f in `{ls -t $newspath}){
	if(~ $#n $max){
		echo '</feed>'
		exit
	}
	n=($n 1)
	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 '<article style="border:solid;border-width:1px 0 0 0;">
<header>
<h2>'$"title'</h2>
<p>'$"mdate'<br/>
Author: '$"author'</p>
</header>
<p><b>'$"summary'</b></p><p>'$"fulltext'</p>
</article>'
}
echo '</section>
</body>
</html>'