some accumulated uncommitted changes
[~bandali/bndl.org] / bandali / feeds.scm
CommitLineData
4b11ed9d
AB
1;;; Copyright © 2019 Amin Bandali <bandali@gnu.org>
2;;;
3;;; This program is free software; you can redistribute it and/or
4;;; modify it under the terms of the GNU General Public License as
5;;; published by the Free Software Foundation; either version 3 of the
6;;; License, or (at your option) any later version.
7;;;
8;;; This program is distributed in the hope that it will be useful,
9;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11;;; General Public License for more details.
12;;;
13;;; You should have received a copy of the GNU General Public License
14;;; along with this program. If not, see
15;;; <http://www.gnu.org/licenses/>.
16
17(define-module (bandali feeds)
18 #:use-module (haunt builder atom) ; atom-feed
19 #:use-module (haunt builder rss) ; rss-feed
20 #:use-module (haunt post) ; post-*
21 #:use-module (ice-9 match) ; match-lambda
22 #:re-export (atom-feed
23 rss-feed)
24 #:export (atom-feeds-by-tag
25 rss-feeds-by-tag))
26
27(define* (atom-feeds-by-tag #:key
28 (prefix "feeds/tags")
29 (filter posts/reverse-chronological)
30 (max-entries 20)
31 (blog-prefix ""))
32 "Return a builder procedure that renders an atom feed for every tag
33used in a post. All arguments are optional:
34
35PREFIX: The directory in which to write the feeds
36FILTER: The procedure called to manipulate the posts list before rendering
37MAX-ENTRIES: The maximum number of posts to render in each feed"
38 (lambda (site posts)
39 (let ((tag-groups (posts/group-by-tag posts)))
40 (map (match-lambda
41 ((tag . posts)
42 ((atom-feed #:file-name (string-append prefix "/" tag ".atom")
43 #:subtitle (string-append "Tag: " tag)
44 #:filter filter
45 #:max-entries max-entries
46 #:blog-prefix blog-prefix)
47 site posts)))
48 tag-groups))))
49
50(define* (rss-feeds-by-tag #:key
51 (prefix "feeds/tags")
52 (filter posts/reverse-chronological)
53 (max-entries 20)
54 (blog-prefix ""))
55 "Return a builder procedure that renders an rss feed for every tag
56used in a post. All arguments are optional:
57
58PREFIX: The directory in which to write the feeds
59FILTER: The procedure called to manipulate the posts list before rendering
60MAX-ENTRIES: The maximum number of posts to render in each feed"
61 (lambda (site posts)
62 (let ((tag-groups (posts/group-by-tag posts)))
63 (map (match-lambda
64 ((tag . posts)
65 ((rss-feed #:file-name (string-append prefix "/" tag ".rss")
66 #:subtitle (string-append "Tag: " tag)
67 #:filter filter
68 #:max-entries max-entries
69 #:blog-prefix blog-prefix)
70 site posts)))
71 tag-groups))))