add ?with=guile&without=gnu
* tekuti/page.scm (page-feed-atom): Reimplement Brian's thing with "with" and "without" query args, to allow for multiple tags to be included or excluded. * tekuti/request.scm (request-query-ref-all): New helper.
This commit is contained in:
parent
26216a593a
commit
08e1e58f1f
3 changed files with 38 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
||||||
;; Tekuti
|
;; Tekuti
|
||||||
;; Copyright (C) 2008, 2010 Andy Wingo <wingo at pobox dot com>
|
;; Copyright (C) 2008, 2010, 2011 Andy Wingo <wingo at pobox dot com>
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or
|
;; This program is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU General Public License as
|
;; modify it under the terms of the GNU General Public License as
|
||||||
|
@ -34,6 +34,7 @@
|
||||||
#:use-module (web request)
|
#:use-module (web request)
|
||||||
#:use-module (tekuti request)
|
#:use-module (tekuti request)
|
||||||
#:use-module (tekuti page-helpers)
|
#:use-module (tekuti page-helpers)
|
||||||
|
#:use-module ((srfi srfi-1) #:select (fold))
|
||||||
#:use-module (srfi srfi-34)
|
#:use-module (srfi srfi-34)
|
||||||
#:use-module (srfi srfi-19)
|
#:use-module (srfi srfi-19)
|
||||||
#:export (page-admin
|
#:export (page-admin
|
||||||
|
@ -55,7 +56,6 @@
|
||||||
page-debug
|
page-debug
|
||||||
page-search
|
page-search
|
||||||
page-feed-atom
|
page-feed-atom
|
||||||
page-feed-atom-tag
|
|
||||||
page-debug
|
page-debug
|
||||||
page-not-found))
|
page-not-found))
|
||||||
|
|
||||||
|
@ -337,14 +337,28 @@
|
||||||
(atom-entry post))
|
(atom-entry post))
|
||||||
posts)))))))
|
posts)))))))
|
||||||
|
|
||||||
|
|
||||||
(define (page-feed-atom request body index)
|
(define (page-feed-atom request body index)
|
||||||
(atom-feed-from-posts request body index (published-posts index 10)))
|
(let ((with (request-query-ref-all request "with"))
|
||||||
|
(without (request-query-ref-all request "without"))
|
||||||
(define (page-feed-atom-tag request body index tag)
|
(tags (assq-ref index 'tags))
|
||||||
(let* ((tags (assq-ref index 'tags))
|
(posts (assq-ref index 'posts))
|
||||||
(posts (filter-mapn (lambda (key)
|
(master (assq-ref index 'master)))
|
||||||
(post-from-key (assq-ref index 'master) key))
|
(atom-feed-from-posts
|
||||||
(hash-ref tags tag '())
|
request body index
|
||||||
10)))
|
(filter-mapn (fold (lambda (tag cont)
|
||||||
(atom-feed-from-posts request body index posts)))
|
(let ((posts (hash-ref tags tag '())))
|
||||||
|
(lambda (post)
|
||||||
|
(and (not (member (post-key post) posts))
|
||||||
|
(cont post)))))
|
||||||
|
(fold (lambda (tag cont)
|
||||||
|
(let ((posts (hash-ref tags tag '())))
|
||||||
|
(lambda (post)
|
||||||
|
(and (member (post-key post) posts)
|
||||||
|
(cont post)))))
|
||||||
|
(lambda (post)
|
||||||
|
(and (post-published? post)
|
||||||
|
post))
|
||||||
|
with)
|
||||||
|
without)
|
||||||
|
posts
|
||||||
|
10))))
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(define-module (tekuti request)
|
(define-module (tekuti request)
|
||||||
#:use-module ((srfi srfi-1) #:select (find-tail))
|
#:use-module ((srfi srfi-1) #:select (find-tail filter-map))
|
||||||
#:use-module (tekuti match-bind)
|
#:use-module (tekuti match-bind)
|
||||||
#:use-module (tekuti util)
|
#:use-module (tekuti util)
|
||||||
#:use-module (web uri)
|
#:use-module (web uri)
|
||||||
|
@ -38,6 +38,7 @@
|
||||||
#:export (request-relative-path
|
#:export (request-relative-path
|
||||||
request-relative-path-str
|
request-relative-path-str
|
||||||
request-query-ref
|
request-query-ref
|
||||||
|
request-query-ref-all
|
||||||
request-path-case
|
request-path-case
|
||||||
request-authenticated?
|
request-authenticated?
|
||||||
request-form-data))
|
request-form-data))
|
||||||
|
@ -68,6 +69,15 @@
|
||||||
((and q (assoc param (parse-www-form-urlencoded q))) => cdr)
|
((and q (assoc param (parse-www-form-urlencoded q))) => cdr)
|
||||||
(else default))))
|
(else default))))
|
||||||
|
|
||||||
|
(define (request-query-ref-all r param)
|
||||||
|
(let ((q (uri-query (request-uri r))))
|
||||||
|
(if q
|
||||||
|
(filter-map (lambda (pair)
|
||||||
|
(and (equal? (car pair) param)
|
||||||
|
(cdr pair)))
|
||||||
|
(parse-www-form-urlencoded q))
|
||||||
|
'())))
|
||||||
|
|
||||||
(define (decode-string bv charset)
|
(define (decode-string bv charset)
|
||||||
(if (string-ci=? charset "utf-8")
|
(if (string-ci=? charset "utf-8")
|
||||||
(utf8->string bv)
|
(utf8->string bv)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
;; Tekuti
|
;; Tekuti
|
||||||
;; Copyright (C) 2008, 2010 Andy Wingo <wingo at pobox dot com>
|
;; Copyright (C) 2008, 2010, 2011 Andy Wingo <wingo at pobox dot com>
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or
|
;; This program is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU General Public License as
|
;; modify it under the terms of the GNU General Public License as
|
||||||
|
@ -54,7 +54,6 @@
|
||||||
((POST archives year! month! day! post!) page-new-comment)
|
((POST archives year! month! day! post!) page-new-comment)
|
||||||
((GET feed) page-feed-atom)
|
((GET feed) page-feed-atom)
|
||||||
((GET feed atom) page-feed-atom)
|
((GET feed atom) page-feed-atom)
|
||||||
((GET feed atom tag!) page-feed-atom-tag)
|
|
||||||
((POST search) page-search)
|
((POST search) page-search)
|
||||||
((GET tags) page-show-tags)
|
((GET tags) page-show-tags)
|
||||||
((GET tags tag!) page-show-tag)
|
((GET tags tag!) page-show-tag)
|
||||||
|
|
Loading…
Reference in a new issue