page-links-renderer.rkt 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. #lang racket
  2. (require "../utils/list-operations.rkt")
  3. (provide create-page-links-renderer)
  4. (define (create-page-links-renderer #:prefix-parts [prefix-parts '()])
  5. (λ (total-posts# posts-per-page# active-page#)
  6. (define (render-page-links total-posts#)
  7. (define (render-page-link page-index)
  8. `(a ((class ,(if (= page-index active-page#)
  9. "page-link inactive"
  10. "page-link active"))
  11. (href ,(apply string-append
  12. (cons "/" ; make link absolute, all the prefix parts should be given, so we should have the complete path
  13. (list-join (append prefix-parts
  14. (list "page"
  15. (number->string page-index)))
  16. "/")))))
  17. ,(number->string page-index)))
  18. (let* ([pages# (inexact->exact
  19. (max (ceiling (/ total-posts# posts-per-page#))
  20. 1))]
  21. [rendered-page-links (for/list ([page-index (in-range pages#)])
  22. (render-page-link page-index))])
  23. `(div ((class "page-links"))
  24. (p ((class "page-links-label")) "Pages")
  25. ,@(list-join rendered-page-links `(span " - ")))))
  26. (render-page-links total-posts#)))