rss.fnl (1440B)
1 (local { : to-html } (require :html)) 2 (local { : string-stream } (require :lib)) 3 4 (local preamble "<?xml version='1.0' encoding='UTF-8'?> 5 <rss version='2.0' xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:trackback='http://madskills.com/public/xml/rss/module/trackback/' xmlns:itunes='http://www.itunes.com/dtds/podcast-1.0.dtd'> 6 <channel> 7 <title> 8 diary at Telent Netowrks 9 </title> 10 <link> 11 https://ww.telent.net/ 12 </link> 13 <atom:link href='https://ww.telent.net/news.rss' rel='self' type='application/rss+xml'/> 14 <description> 15 Daniel Barlow's blog 16 </description> 17 ") 18 19 20 21 (fn make-cdata [body] 22 (.. "<![CDATA[" 23 (string.gsub body "%]%]>" "]]]]><![CDATA[>") 24 "]]>")) 25 26 (fn for-post [base-url site post] 27 (let [link (.. base-url post.url-path) 28 out (string-stream) 29 body (do (post:body site out) (out:to-string)) 30 escaped-text (make-cdata body) 31 date (os.date "!%Y-%m-%dT%TZ" post.date)] 32 [:item 33 [:title post.title] 34 [:link link] 35 [:description escaped-text] 36 [:author "dan@telent.net (Daniel Barlow)"] 37 [:guid link] 38 ["dc:date" date]])) 39 40 (fn feed [stream base-url site posts] 41 (print :s stream ) 42 (stream:write_chunk preamble) 43 (each [_ p (ipairs posts)] 44 (stream:write_chunk (to-html (for-post base-url site p)))) 45 (stream:write_chunk "</channel></rss>" true)) 46 47 { : feed }