@@ -24,10 +24,12 @@
;; Provides functions for displaying content in HTML templates.
(require pollen/core
pollen/template
pollen/decode
racket/string
+ racket/function
+ racket/list
txexpr
openssl/sha1
"dust.rkt")
(provide html$-page-head
@@ -38,11 +40,12 @@
html$-page-body-close
html$-note-title
html$-note-contents
html$-note-listing-full
html$-note-in-article
- html$-notes-section)
+ html$-notes-section
+ html$-paginate-navlinks)
(define (html$-page-head [title #f])
◊string-append{
◊if[title title ""]
@@ -159,5 +162,53 @@
(define (html$-notes-section note-htmls)
◊string-append{
Further Notes
◊(apply string-append note-htmls)
})
+
+;; (private) Returns HTML for a list-item link to a particular page in a set of numbered pages
+(define (html$-paginate-link basename pagenum [linktext (format "p. ~a" (number->string pagenum))] [class ""])
+ (define cstr (if (non-empty-string? class) (format " class=\"~a\"" class) ""))
+ (format "~a" cstr basename pagenum linktext))
+
+;; Returns HTML for a series of list items with links to numbered pages
+(define (html$-paginate-navlinks pagenum pagecount basename)
+ (define slots 9)
+ (define on-first-group? (<= pagenum (- slots 4)))
+ (define on-last-group? (>= pagenum (- pagecount slots -4)))
+ (define only-one-group? (<= pagecount slots))
+ (define group-start (- pagenum (quotient (- slots 4) 2))) ; not always used!
+ (define page-func (curry html$-paginate-link basename))
+
+ (define page-group-syms
+ (cond [only-one-group?
+ `(,@(range 1 (+ 1 pagecount)))]
+ [on-first-group?
+ `(,@(range 1 (min (+ 1 pagecount) (- slots 1))) "..." ,pagecount)]
+ [on-last-group?
+ `(1 "..." ,@(range (- pagecount slots -3) (+ pagecount 1)))]
+ [else
+ `(1
+ "..."
+ ,@(range group-start (min (+ 1 pagecount) (+ group-start (- slots 4))))
+ "..."
+ ,pagecount)]))
+
+ (define page-group
+ (for/list ([psym (in-list page-group-syms)])
+ (cond
+ [(and (number? psym) (equal? psym pagenum))
+ (format "~a" psym)]
+ [(number? psym) (page-func psym)]
+ [else "…"])))
+
+ (define prev-link
+ (if (eq? 1 pagenum)
+ "←Newer"
+ (page-func (- pagenum 1) "← Newer" "nav-text")))
+
+ (define next-link
+ (if (eq? pagecount pagenum)
+ "Older→"
+ (page-func (+ pagenum 1) "Older →" "nav-text")))
+
+ (string-join `(,prev-link ,@page-group ,next-link)))