Improve furnace RSS support
parent
19044920dc
commit
608276fe9a
|
@ -8,7 +8,6 @@ xml
|
||||||
xml.data
|
xml.data
|
||||||
xml.entities
|
xml.entities
|
||||||
xml.writer
|
xml.writer
|
||||||
xml.utilities
|
|
||||||
html.components
|
html.components
|
||||||
html.elements
|
html.elements
|
||||||
html.templates
|
html.templates
|
||||||
|
@ -20,6 +19,7 @@ http.server.redirection
|
||||||
http.server.responses
|
http.server.responses
|
||||||
qualified ;
|
qualified ;
|
||||||
QUALIFIED-WITH: assocs a
|
QUALIFIED-WITH: assocs a
|
||||||
|
EXCLUDE: xml.utilities => children>string ;
|
||||||
IN: furnace
|
IN: furnace
|
||||||
|
|
||||||
: nested-responders ( -- seq )
|
: nested-responders ( -- seq )
|
||||||
|
@ -97,7 +97,7 @@ SYMBOL: exit-continuation
|
||||||
[ drop f ] [ "," split [ dup value ] H{ } map>assoc ] if ;
|
[ drop f ] [ "," split [ dup value ] H{ } map>assoc ] if ;
|
||||||
|
|
||||||
CHLOE: atom
|
CHLOE: atom
|
||||||
[ "title" required-attr ]
|
[ children>string ]
|
||||||
[ "href" required-attr ]
|
[ "href" required-attr ]
|
||||||
[ "query" optional-attr parse-query-attr ] tri
|
[ "query" optional-attr parse-query-attr ] tri
|
||||||
<url>
|
<url>
|
||||||
|
|
|
@ -1,14 +1,52 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors kernel fry
|
USING: accessors kernel sequences fry sequences.lib
|
||||||
rss http.server.responses furnace.actions ;
|
combinators rss http.server.responses http.server.redirection
|
||||||
|
furnace furnace.actions ;
|
||||||
IN: furnace.rss
|
IN: furnace.rss
|
||||||
|
|
||||||
|
GENERIC: feed-entry-title ( object -- string )
|
||||||
|
|
||||||
|
GENERIC: feed-entry-date ( object -- timestamp )
|
||||||
|
|
||||||
|
GENERIC: feed-entry-url ( object -- url )
|
||||||
|
|
||||||
|
GENERIC: feed-entry-description ( object -- description )
|
||||||
|
|
||||||
|
M: object feed-entry-description drop f ;
|
||||||
|
|
||||||
|
GENERIC: >entry ( object -- entry )
|
||||||
|
|
||||||
|
M: entry >entry ;
|
||||||
|
|
||||||
|
M: object >entry
|
||||||
|
<entry>
|
||||||
|
swap {
|
||||||
|
[ feed-entry-title >>title ]
|
||||||
|
[ feed-entry-date >>date ]
|
||||||
|
[ feed-entry-url >>url ]
|
||||||
|
[ feed-entry-description >>description ]
|
||||||
|
} cleave ;
|
||||||
|
|
||||||
|
: process-entries ( seq -- seq' )
|
||||||
|
20 short head-slice [
|
||||||
|
>entry clone
|
||||||
|
[ adjust-url relative-to-request ] change-url
|
||||||
|
] map ;
|
||||||
|
|
||||||
: <feed-content> ( body -- response )
|
: <feed-content> ( body -- response )
|
||||||
feed>xml "application/atom+xml" <content> ;
|
feed>xml "application/atom+xml" <content> ;
|
||||||
|
|
||||||
TUPLE: feed-action < action feed ;
|
TUPLE: feed-action < action title url entries ;
|
||||||
|
|
||||||
: <feed-action> ( -- feed )
|
: <feed-action> ( -- action )
|
||||||
feed-action new-action
|
feed-action new-action
|
||||||
dup '[ , feed>> call <feed-content> ] >>display ;
|
dup '[
|
||||||
|
feed new
|
||||||
|
,
|
||||||
|
[ title>> call >>title ]
|
||||||
|
[ url>> call adjust-url relative-to-request >>url ]
|
||||||
|
[ entries>> call process-entries >>entries ]
|
||||||
|
tri
|
||||||
|
<feed-content>
|
||||||
|
] >>display ;
|
||||||
|
|
|
@ -2,6 +2,9 @@ USING: rss io kernel io.files tools.test io.encodings.utf8
|
||||||
calendar urls ;
|
calendar urls ;
|
||||||
IN: rss.tests
|
IN: rss.tests
|
||||||
|
|
||||||
|
\ download-feed must-infer
|
||||||
|
\ feed>xml must-infer
|
||||||
|
|
||||||
: load-news-file ( filename -- feed )
|
: load-news-file ( filename -- feed )
|
||||||
#! Load an news syndication file and process it, returning
|
#! Load an news syndication file and process it, returning
|
||||||
#! it as an feed tuple.
|
#! it as an feed tuple.
|
||||||
|
|
|
@ -14,7 +14,7 @@ TUPLE: feed title url entries ;
|
||||||
|
|
||||||
: <feed> ( -- feed ) feed new ;
|
: <feed> ( -- feed ) feed new ;
|
||||||
|
|
||||||
TUPLE: entry title url description pub-date ;
|
TUPLE: entry title url description date ;
|
||||||
|
|
||||||
: set-entries ( feed entries -- feed )
|
: set-entries ( feed entries -- feed )
|
||||||
[ dup url>> ] dip
|
[ dup url>> ] dip
|
||||||
|
@ -35,7 +35,7 @@ TUPLE: entry title url description pub-date ;
|
||||||
[
|
[
|
||||||
f "date" "http://purl.org/dc/elements/1.1/" <name>
|
f "date" "http://purl.org/dc/elements/1.1/" <name>
|
||||||
tag-named dup [ children>string try-parsing-timestamp ] when
|
tag-named dup [ children>string try-parsing-timestamp ] when
|
||||||
>>pub-date
|
>>date
|
||||||
]
|
]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ TUPLE: entry title url description pub-date ;
|
||||||
[ "description" tag-named children>string >>description ]
|
[ "description" tag-named children>string >>description ]
|
||||||
[
|
[
|
||||||
{ "date" "pubDate" } any-tag-named
|
{ "date" "pubDate" } any-tag-named
|
||||||
children>string try-parsing-timestamp >>pub-date
|
children>string try-parsing-timestamp >>date
|
||||||
]
|
]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ TUPLE: entry title url description pub-date ;
|
||||||
swap
|
swap
|
||||||
"channel" tag-named
|
"channel" tag-named
|
||||||
[ "title" tag-named children>string >>title ]
|
[ "title" tag-named children>string >>title ]
|
||||||
[ "link" tag-named children>string >>link ]
|
[ "link" tag-named children>string >url >>url ]
|
||||||
[ "item" tags-named [ rss2.0-entry ] map set-entries ]
|
[ "item" tags-named [ rss2.0-entry ] map set-entries ]
|
||||||
tri ;
|
tri ;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ TUPLE: entry title url description pub-date ;
|
||||||
[
|
[
|
||||||
{ "published" "updated" "issued" "modified" }
|
{ "published" "updated" "issued" "modified" }
|
||||||
any-tag-named children>string try-parsing-timestamp
|
any-tag-named children>string try-parsing-timestamp
|
||||||
>>pub-date
|
>>date
|
||||||
]
|
]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ TUPLE: entry title url description pub-date ;
|
||||||
{
|
{
|
||||||
[ title>> "title" { { "type" "html" } } simple-tag*, ]
|
[ title>> "title" { { "type" "html" } } simple-tag*, ]
|
||||||
[ url>> present "href" associate "link" swap contained*, ]
|
[ url>> present "href" associate "link" swap contained*, ]
|
||||||
[ pub-date>> timestamp>rfc3339 "published" simple-tag, ]
|
[ date>> timestamp>rfc3339 "published" simple-tag, ]
|
||||||
[ description>> [ "content" { { "type" "html" } } simple-tag*, ] when* ]
|
[ description>> [ "content" { { "type" "html" } } simple-tag*, ] when* ]
|
||||||
} cleave
|
} cleave
|
||||||
] tag, ;
|
] tag, ;
|
||||||
|
|
Loading…
Reference in New Issue