diff --git a/news.arc b/news.arc index f9dc723..de0e277 100644 --- a/news.arc +++ b/news.arc @@ -55,7 +55,8 @@ dead nil deleted nil parent nil - kids nil) + kids nil + rssdisplay nil) ; Load and Save @@ -1310,15 +1311,16 @@ function vote(node) { (= (fieldfn* 'story) (fn (user s) (with (a (admin user) e (editor user) x (canedit user s)) - `((string1 title ,(s 'title) t ,x) - (url url ,(s 'url) t ,e) - (mdtext2 text ,(s 'text) t ,x) - (int votes ,(len (s 'votes)) ,a nil) - (int score ,(s 'score) t ,a) - (int sockvotes ,(s 'sockvotes) ,e ,a) - (yesno dead ,(s 'dead) ,e ,e) - (yesno deleted ,(s 'deleted) ,a ,a) - (string ip ,(s 'ip) ,e nil))))) + `((string1 title ,(s 'title) t ,x) + (url url ,(s 'url) t ,e) + (mdtext2 text ,(s 'text) t ,x) + (int votes ,(len (s 'votes)) ,a nil) + (int score ,(s 'score) t ,a) + (int sockvotes ,(s 'sockvotes) ,e ,a) + (yesno dead ,(s 'dead) ,e ,e) + (yesno deleted ,(s 'deleted) ,a ,a) + (yesno rssdisplay ,(s 'rssdisplay) t nil) + (string ip ,(s 'ip) ,e nil))))) (= (fieldfn* 'comment) (fn (user s) @@ -1540,7 +1542,22 @@ function vote(node) { (newsop rss () (rsspage nil)) (newscache rsspage user 90 - (rss-stories (firstn 25 ranked-stories*))) + (rss-stories (rss-list))) + +(= nrss-stories 25) + +(def rss-list () + (gen-topstories) + (let stories (firstn (+ nrss-stories 10) ranked-stories*) + (let groups (split stories (min nrss-stories (len stories))) + (each s (groups 0) + (if (no (is s!rssdisplay 1)) + (and (= s!rssdisplay 1) + (save-item s)))) + (each s (groups 1) + (if (is s!rssdisplay 1) + (push s (groups 0)))) + (sort (fn (first second) (> first!time second!time)) (groups 0))))) (def rss-stories (stories) (tag (rss version "2.0") @@ -1552,11 +1569,70 @@ function vote(node) { (tag item (let comurl (+ site-url* (item-url s)) (tag title (pr (eschtml s!title))) + (tag pubDate (pr (unix-to-utc s!time))) + (tag guid (pr comurl)) (tag link (pr (if (blank s!url) comurl (eschtml s!url)))) (tag comments (pr comurl)) (tag description (cdata (link "Comments" comurl))))))))) +(= seconds-per-minute 60) +(= seconds-per-hour (* 60 seconds-per-minute)) +(= seconds-per-day (* 24 seconds-per-hour)) + +(def is-leap-year (year) + (or + (and + (is (mod year 4) 0) + (no (is (mod year 100) 0))) + (is (mod year 400) 0))) + +(def seconds-per-year (year) + (if (is-leap-year year) + (* seconds-per-day 366) + (* seconds-per-day 365))) + +(def seconds-per-month (year month) + (* seconds-per-day + (`(31 ,(if (is-leap-year year) 29 28) 31 30 31 30 31 31 30 31 30 31) (-- month)))) + +(def month-name (month) + ('("Jan" "Feb" "Mar" "Apr" "May" "Jun" + "Jul" "Aug" "Sep" "Oct" "Nov" "Dec") (-- month))) + +(def day-of-week (seconds) + ('("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun") + (mod (+ (/ (- seconds (mod seconds seconds-per-day)) seconds-per-day) 3) 7))) + +(def pad-number (number) + (if (< (len (string number)) 2) + (string "0" number) + (string number))) + +(def unix-to-utc (seconds) + (with (year 1970 + month 1 + day 1 + day-name (day-of-week seconds) + hour 0 + minute 0) + (while (> seconds (seconds-per-year year)) + (zap [- _ (seconds-per-year year)] seconds) + (++ year)) + (while (> seconds (seconds-per-month year month)) + (zap [- _ (seconds-per-month year month)] seconds) + (++ month)) + (while (> seconds seconds-per-day) + (zap [- _ seconds-per-day] seconds) + (++ day)) + (while (> seconds seconds-per-hour) + (zap [- _ seconds-per-hour] seconds) + (++ hour)) + (while (> seconds seconds-per-minute) + (zap [- _ seconds-per-minute] seconds) + (++ minute)) + (string day-name ", " day " " (month-name month) " " year " " + (pad-number hour) ":" (pad-number minute) ":" (pad-number seconds) " +0000"))) ; User Stats