1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#lang racket/base
; SPDX-License-Identifier: BlueOak-1.0.0
; This file is licensed under the Blue Oak Model License 1.0.0.
;; Generates an Atom feed from the SQLite cache
(require txexpr
racket/match
racket/file
racket/date
racket/string
db/base
"dust.rkt"
"cache.rkt")
(provide main)
(define feed-author default-authorname)
(define feed-author-email "joel@jdueck.net")
|
>
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#lang racket/base
; SPDX-License-Identifier: BlueOak-1.0.0
; This file is licensed under the Blue Oak Model License 1.0.0.
;; Generates an Atom feed from the SQLite cache
(require txexpr
deta
racket/match
racket/file
racket/date
racket/string
racket/sequence
"dust.rkt"
"cache.rkt")
(provide main)
(define feed-author default-authorname)
(define feed-author-email "joel@jdueck.net")
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
(define timestamp
(parameterize [(date-display-format 'iso-8601)]
(date->string now #t)))
(string-append timestamp "Z"))
;; Get the data out of the SQLite cache as vectors
(define (fetch-rows)
(define fields '(pagenode title_plain published updated author doc_html))
(define select #<<---
SELECT `path`, `title`, `published`, `updated`, `author`, `entry_contents` FROM
(SELECT `page` AS `path`,
`title_plain` AS `title`,
`published`,
`updated`,
`author`,
`doc_html` AS `entry_contents`
FROM `articles` WHERE (NOT (`conceal` LIKE "%all%")) AND (NOT (`conceal` LIKE "%feed%"))
UNION
SELECT `page` || '#' || `html_anchor` AS `path`,
`title_plain` AS `title`,
`published`,
"" AS `updated`,
`author`,
`content_html` as `entry_contents`
FROM `notes` WHERE (NOT (`conceal` LIKE "%all%")) AND (NOT (`conceal` LIKE "%feed%")))
ORDER BY `published` DESC LIMIT ~a
---
)
(query-rows (cache-conn) (format select feed-item-limit)))
(define (vector->rss-item vec)
(match-define
(vector path title published updated author contents) vec)
(define entry-url (string-append feed-site-url web-root path))
(define update-ts
(cond [(non-empty-string? updated) updated]
[else published]))
`(entry (author (name ,author))
(published ,(ymd->rfc3339 published))
(updated ,(ymd->rfc3339 update-ts))
(title ,title)
(link [[rel "alternate"] [href ,entry-url]])
(id ,entry-url)
(summary [[type "html"]]
,(as-cdata contents))))
(define (rss-feed)
(define feed-xpr
`(feed [[xml:lang "en-us"] [xmlns "http://www.w3.org/2005/Atom"]]
(title ,feed-title)
(link [[rel "self"] [href ,(string-append feed-site-url web-root "feed.xml")]])
(generator [[uri "http://pollenpub.com/"]] "Pollen")
(id ,(string-append feed-site-url web-root))
(updated ,(current-rfc3339))
(author
(name ,feed-author)
(email ,@(email-encode feed-author-email)))
,@(map vector->rss-item (fetch-rows))))
(string-append "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
(xexpr->string feed-xpr)))
(define (main)
(display-to-file (rss-feed) "feed.xml" #:mode 'text #:exists 'replace))
|
<
<
<
<
<
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
|
|
|
<
<
|
<
|
|
|
|
|
|
|
|
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
(define timestamp
(parameterize [(date-display-format 'iso-8601)]
(date->string now #t)))
(string-append timestamp "Z"))
;; Get the data out of the SQLite cache as vectors
(define (fetch-rows)
(sequence->list
(in-entities (cache-conn)
(articles+notes 'content #:series #f #:limit feed-item-limit))))
(define (listing->rss-item lst)
(match-define (listing _ path title author published updated html) lst)
(define entry-url (string-append feed-site-url web-root path))
(define updated-ts (if (non-empty-string? updated) updated published))
`(entry (author (name ,author))
(published ,(ymd->rfc3339 published))
(updated ,(ymd->rfc3339 updated-ts))
(title ,title)
(link [[rel "alternate"] [href ,entry-url]])
(id ,entry-url)
(summary [[type "html"]]
,(as-cdata html))))
(define (rss-feed)
(define feed-xpr
`(feed [[xml:lang "en-us"] [xmlns "http://www.w3.org/2005/Atom"]]
(title ,feed-title)
(link [[rel "self"] [href ,(string-append feed-site-url web-root "feed.xml")]])
(generator [[uri "http://pollenpub.com/"]] "Pollen")
(id ,(string-append feed-site-url web-root))
(updated ,(current-rfc3339))
(author
(name ,feed-author)
(email ,@(email-encode feed-author-email)))
,@(map listing->rss-item (fetch-rows))))
(string-append "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
(xexpr->string feed-xpr)))
(define (main)
(display-to-file (rss-feed) "feed.xml" #:mode 'text #:exists 'replace))
|