]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/syndication/syndication.factor
Revert "interpolate: allow format directives to be used"
[factor.git] / basis / syndication / syndication.factor
index 86ab6db5fe15252d0772e752a56835eb3a2976a5..8e6010fbca2a393075b2938646584527d9a655fc 100644 (file)
@@ -1,11 +1,10 @@
 ! Copyright (C) 2006 Chris Double, Daniel Ehrenberg.
 ! Portions copyright (C) 2008, 2009 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: xml.traversal kernel assocs math.order strings sequences
-xml.data xml.writer io.streams.string combinators xml
-xml.entities.html io.files io http.client namespaces make
-xml.syntax hashtables calendar.format accessors continuations
-urls present byte-arrays ;
+! See https://factorcode.org/license.txt for BSD license.
+USING: accessors byte-arrays calendar.format calendar.parser
+combinators combinators.short-circuit continuations http.client
+kernel present sequences strings urls xml xml.data
+xml.entities.html xml.syntax xml.traversal xml.writer ;
 IN: syndication
 
 : any-tag-named ( tag names -- tag-inside )
@@ -27,13 +26,16 @@ TUPLE: entry title url description date ;
 : try-parsing-timestamp ( string -- timestamp )
     [ rfc822>timestamp ] [ drop rfc3339>timestamp ] recover ;
 
+: ?children>string ( tag -- str/f )
+    dup [ children>string ] when ; inline
+
 : rss1.0-entry ( tag -- entry )
     <entry> swap {
         [ "title" tag-named children>string >>title ]
         [ "link" tag-named children>string >url >>url ]
         [ "description" tag-named children>string >>description ]
         [
-            f "date" "http://purl.org/dc/elements/1.1/" <name>
+            f "date" "https://purl.org/dc/elements/1.1/" <name>
             tag-named dup [ children>string try-parsing-timestamp ] when
             >>date
         ]
@@ -48,12 +50,12 @@ TUPLE: entry title url description date ;
 
 : rss2.0-entry ( tag -- entry )
     <entry> swap {
-        [ "title" tag-named children>string >>title ]
-        [ { "link" "guid" } any-tag-named children>string >url >>url ]
-        [ { "description" "encoded" } any-tag-named children>string >>description ]
+        [ "title" tag-named ?children>string >>title ]
+        [ { "link" "guid" } any-tag-named ?children>string >url >>url ]
+        [ { "description" "encoded" } any-tag-named ?children>string >>description ]
         [
             { "date" "pubDate" } any-tag-named
-            children>string try-parsing-timestamp >>date
+            ?children>string try-parsing-timestamp >>date
         ]
     } cleave ;
 
@@ -66,7 +68,11 @@ TUPLE: entry title url description date ;
     tri ;
 
 : atom-link ( tag -- url/f )
-    "link" "alternate" "rel" tag-named-with-attr
+    {
+        [ "link" "alternate" "rel" tag-named-with-attr ]
+        [ "link" "self" "rel" tag-named-with-attr ]
+        [ "link" tag-named ]
+    } 1||
     [ "href" attr >url ] [ f ] if* ;
 
 : atom1.0-entry ( tag -- entry )