Fix tag query

parent d039ee1d
......@@ -21,14 +21,10 @@
(use-modules (app models posts)
(colt git)
(colt config)
(srfi srfi-1))
(define (filter-posts-by-tag tag posts)
(filter (lambda (p) (member tag (string-split (post-tags p) #\,))) posts))
(colt config))
(define (gen-content tag)
(let ((posts (filter-posts-by-tag tag (get-all-posts))))
(let ((posts (get-posts-by-tag tag)))
(tpl->html
`(div (@ (class "blog-post-content"))
(h2 "Articles contains tag: "
......
......@@ -30,6 +30,7 @@
update-index-posts-cache
get-one-article
get-all-posts
get-posts-by-tag
count-tags
get-ordered-tags-list
get-intro-page
......@@ -102,8 +103,8 @@
(lambda (o)
(for-each
(lambda (t)
(let ((cnt (hash-ref *all-tags* t 0)))
(hash-set! *all-tags* t (1+ cnt))))
(let ((pl (hash-ref *all-tags* t '())))
(hash-set! *all-tags* t (cons (get-post o) pl))))
(tags-string->list (post-tags (get-post o)))))
all)))
(return *all-post-objs*)))))
......@@ -111,11 +112,15 @@
(define* (get-all-posts #:key (latest-top? #t) (refresh? #f))
(map get-post (get-all-post-objs #:latest-top? latest-top? #:refresh? refresh?)))
(define (get-posts-by-tag tag)
(hash-ref *all-tags* (uri-decode tag) '()))
(define (count-tags)
(hash-count (const #t) *all-tags*))
(define (get-ordered-tags-list)
(sort (hash-map->list cons *all-tags*) (lambda (x y) (<= (cdr x) (cdr y))) ))
(sort (hash-map->list cons *all-tags*)
(lambda (x y) (<= (length x) (length y)))))
(define (get-intro-page)
(when (null? *intro*)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment