From 4369dc61c237b299b2035a5d882b904da57905a1 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Wed, 21 Nov 2007 03:19:32 -0600 Subject: [PATCH] Planet Factor Atom feed --- extra/rss/rss.factor | 35 +++++++++++++++++++----------- extra/webapps/planet/planet.factor | 12 ++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/extra/rss/rss.factor b/extra/rss/rss.factor index b0fdc65adb..458f09642f 100644 --- a/extra/rss/rss.factor +++ b/extra/rss/rss.factor @@ -1,24 +1,14 @@ -! Copyright (C) 2006 Chris Double. +! Copyright (C) 2006 Chris Double, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. IN: rss -! USING: kernel http-client xml xml-utils xml-data errors io strings -! sequences xml-writer parser-combinators lazy-lists entities ; USING: xml.utilities kernel promises parser-combinators assocs - parser-combinators.replace strings sequences xml.data xml.writer + strings sequences xml.data xml.writer io.streams.string combinators xml xml.entities io.files io - http.client ; + http.client namespaces xml.generator hashtables ; : ?children>string ( tag/f -- string/f ) [ children>string ] [ f ] if* ; -LAZY: '&' ( -- parser ) - "&" token - [ blank? ] satisfy &> - [ "&" swap add ] <@ ; - -: &>& ( string -- string ) - '&' replace ; - TUPLE: feed title link entries ; C: feed @@ -95,3 +85,22 @@ C: entry ] [ 2drop "Error retrieving newsfeed file" throw ] if ; + +! Atom generation +: simple-tag, ( content name -- ) + [ , ] tag, ; + +: (generate-atom) ( entry -- ) + "entry" [ + dup entry-title "title" simple-tag, + "link" over entry-link "href" associate contained*, + dup entry-pub-date "published" simple-tag, + entry-description "content" simple-tag, + ] tag, ; + +: generate-atom ( feed -- xml ) + "feed" [ + dup feed-title "title" simple-tag, + "link" over feed-link "href" associate contained*, + feed-entries [ (generate-atom) ] each + ] make-xml ; diff --git a/extra/webapps/planet/planet.factor b/extra/webapps/planet/planet.factor index 3f7fed6446..5b5879ff9e 100644 --- a/extra/webapps/planet/planet.factor +++ b/extra/webapps/planet/planet.factor @@ -123,3 +123,15 @@ SYMBOL: last-update [ update-thread ] in-thread ; "planet" "planet-factor" "extra/webapps/planet" web-app + +: merge-feeds ( feeds -- feed ) + [ feed-entries ] map concat sort-entries ; + +: planet-feed ( -- feed ) + default-blogroll get [ second news-get ] map merge-feeds + >r "[ planet-factor ]" "http://planet.factorcode.org" r> + generate-atom ; + +: feed.xml planet-feed ; + +\ feed.xml { } define-action