tweak tag cloud code
* tekuti/page-helpers.scm (top-tags, tag-cloud, main-sidebar): Make the tag cloud code a bit more modular. Up the number of tags shown to 30. * tekuti/util.scm: Allow # in the path part of a URL. Yick.
This commit is contained in:
parent
11eed1fbc8
commit
062e0f109a
2 changed files with 28 additions and 24 deletions
|
@ -183,41 +183,44 @@
|
|||
(define (admin-post-redirect request post)
|
||||
(redirect request (admin-post-url post)))
|
||||
|
||||
;; fixme: borks in the no-tags case; ugly code
|
||||
(define (tag-cloud index)
|
||||
(define (top-tags index n)
|
||||
(let ((hash (assq-ref index 'tags)))
|
||||
(if hash
|
||||
(dsu-sort
|
||||
(take-max
|
||||
(dsu-sort
|
||||
(hash-fold (lambda (k v seed) (acons k (length v) seed))
|
||||
'() hash)
|
||||
cdr >) n)
|
||||
car string<?)
|
||||
'())))
|
||||
|
||||
(define (tag-cloud tags)
|
||||
(define (determine-sizes counts)
|
||||
(let ((maxcount (apply max counts)))
|
||||
(let ((maxcount (if (null? counts) '() (apply max counts))))
|
||||
(map (lambda (x)
|
||||
(floor (+ 80 (* 120 (/ x maxcount)))))
|
||||
counts)))
|
||||
(let* ((hash (assq-ref index 'tags))
|
||||
(cats (if hash
|
||||
(hash-fold (lambda (k v seed) (acons k (length v) seed))
|
||||
'() hash)
|
||||
'()))
|
||||
(top-20 (dsu-sort (take-max (dsu-sort cats cdr >) 20)
|
||||
car string<?)))
|
||||
`(ul (li (@ (style "line-height: 150%"))
|
||||
,@(list-intersperse
|
||||
(map (lambda (name size)
|
||||
`(a (@ (href ,(relurl "tags/" (url:encode name)))
|
||||
(rel "tag")
|
||||
(style ,(format #f "font-size: ~d%" size)))
|
||||
,name))
|
||||
(map car top-20)
|
||||
(determine-sizes (map cdr top-20)))
|
||||
" "))
|
||||
)))
|
||||
(list-intersperse
|
||||
(map (lambda (name size)
|
||||
`(a (@ (href ,(relurl "tags/" (url:encode name)))
|
||||
(rel "tag")
|
||||
(style ,(format #f "font-size: ~d%" size)))
|
||||
,name))
|
||||
(map car tags)
|
||||
(determine-sizes (map cdr tags)))
|
||||
" "))
|
||||
|
||||
(define (main-sidebar request index)
|
||||
(sidebar-ul
|
||||
`((li (h2 (a (@ (href ,(relurl "feed/atom")))
|
||||
"subscribe "
|
||||
(img (@ (src ,(relurl "wp-content/feed-icon-14x14.png"))
|
||||
(alt "subscribe to this feed")))
|
||||
(alt "[feed]")))
|
||||
)))
|
||||
(li (h2 "tags " ,(rellink "tags/" ">>"))
|
||||
,(tag-cloud index)))))
|
||||
(ul (li (@ (style "line-height: 150%"))
|
||||
,@(tag-cloud (top-tags index 30))))))))
|
||||
|
||||
(define (with-authentication request thunk)
|
||||
(if (request-authenticated? request)
|
||||
|
|
|
@ -44,8 +44,9 @@
|
|||
x
|
||||
#f))
|
||||
|
||||
;; hacky #fragment interpreting...
|
||||
(define (urlish? x)
|
||||
(match-bind "^https?://([a-zA-Z0-9-]+\\.)+[a-zA-Z]+(/[a-zA-Z0-9$_.+!*'(),;/?:@&=-]*)?$"
|
||||
(match-bind "^https?://([a-zA-Z0-9-]+\\.)+[a-zA-Z]+(/[a-zA-Z0-9$_.+!*'(),;/?:#@&=-]*)?$"
|
||||
x (_ . args)
|
||||
x
|
||||
#f))
|
||||
|
|
Loading…
Reference in a new issue