[REBOL] Re: REBOL Script to convert REBOL format to RSS XML
From: volker::nitsch::gmail::com at: 31-Dec-2004 6:54
On Thu, 30 Dec 2004 17:12:12 -0700, Gregg Irwin
<[greggirwin--mindspring--com]> wrote:
> Hi Premshree,
>
> PP> Anyway, I wrote a small script that generates valid RSS 2.0 feeds from
> PP> the REBOL data for Carl's blog. The code is available here:
> PP> http://premshree.seacrow.com/code/rebol/carl-rss.r/download
>
> Very cool!
>
> PP> If there are improvements possible, please point so/do so. :)
>
Good scripts :)
I add another version which is not that advanced.
But keeps the original structure.
As intermediate step.
Together with some comments (single ";").
REBOL [
Title: "RSS Generator for Carl's Blog"
Date: 31-Dec-2004
Version: 0.0.1
File: %carl-rss.r
Home: http://www.livejournal.com/~premshree
Author: "Premshree Pillai"
Version: 0.0.1
Purpose: {
Generates valid RSS 2.0 feeds for Carl's blogs
}
]
;; channel data
channel: [
title "Carl's REBOL Blog - Vive la REBOLution"
link http://www.rebol.net/
description "describes this blog channel"
language "English"
copyright "2005 Carl Sassenrath"
generator "REBOL Messaging Language"
]
;; blog items go here
items: [
[
title "Blog item title...."
link http://www.rebol.net/cgi-bin/blog.r?view=0080
author "Carl Sassenrath"
pubdate 30-Dec-2004
content {the blog goes here}
]
[
title "Blog item title 2...."
link http://www.rebol.net/cgi-bin/blog.r?view=0081
author "Carl Sassenrath"
pubdate 31-Dec-2004
content {the blog 2 goes here}
]
]
;; no edits required below this point
; instead of "channel-title"
; we can use "channel/title"
; directly. so we drop this:
; channel-link: select channel 'link
; ...
; instead of
; output: rejoin[ output new-stuff]
; we can use for performance
; append output rejoin[ new-stuff ]
; which is the same as
; repend output [new-stuff]
; (repend is a shortcut because such things occur soo often)
; and then we shrink some more by a function "emit".
; It is usually copypasted and patched everywhere.
; Its not inbuild because each script needs a slighly
; different version.
output: copy""
emit: func[block][ repend output block append output newline]
; tags are inbuild and {"} around them are not needed.
; looks sometimes cleaner.
; and i did some linebreaks for email
emit [
<?xml version='1.0' encoding='utf-8' ?>
<rss version='2.0'><channel>
<title> channel/title </title>
]
emit [
<link> channel/link </link>
<description> channel/description </description>
]
emit [
<language> channel/language </language>
<copyright> channel/copyright </copyright>
]
emit [<generator> channel/generator </generator>]
; instead of "for" and indexing:
foreach item items[
title: item/title
link: item/link
author: item/author
; dropped the date-making, to-idate works similar
pubdate: to-idate item/pubdate
content: item/content
emit [
<item>
<guid isPermaLink='true'> link </guid>
<pubDate> pubdate </pubDate>
]
emit [<title> title </title><link> link </link>]
emit [<description> content </description></item>]
]
emit[</channel></rss>]
write %carl-rss2.xml output