~abcdw/trop.in

305532090489f3c3ea7a893c2228eab2dd94c86b — Andrew Tropin 11 days ago 9932a47
Update blog layout
1 files changed, 53 insertions(+), 36 deletions(-)

M src/tropin/site.scm
M src/tropin/site.scm => src/tropin/site.scm +53 -36
@@ 1,15 1,15 @@
(define-module (tropin site))

(use-modules (haunt asset)
             (haunt site)
             (haunt post)
             (haunt builder blog)
             (haunt builder atom)
             (haunt builder assets)
             (haunt html)
             (haunt reader)
             (haunt reader skribe)
             (haunt reader commonmark))
(define-module (tropin site)
  #:use-module (srfi srfi-19)
  #:use-module (haunt asset)
  #:use-module (haunt site)
  #:use-module (haunt post)
  #:use-module (haunt builder blog)
  #:use-module (haunt builder atom)
  #:use-module (haunt builder assets)
  #:use-module (haunt html)
  #:use-module (haunt reader)
  #:use-module (haunt reader skribe)
  #:use-module (haunt reader commonmark))

(define (stylesheet name)
  `(link (@ (rel "stylesheet")


@@ 28,11 28,6 @@
            (small "The content for this site is " ,%cc-by-sa-link " licensed. "
                   "The source code is " ,%source-code "."))))

(use-modules (srfi srfi-19))
(define (date->string* date)
  "Convert DATE to human readable string."
  (date->string date "~B ~d, ~Y"))

(define* (page-theme
          #:key
          (footer %default-footer))


@@ 52,6 47,16 @@
   (lambda (post)
     `((div ,(post-sxml post))))))

;; Paper theme

(define (date->paper-string date)
  "Convert DATE to human paper-like string."
  (date->string date "~B ~d, ~Y"))

(define (date->iso-string date)
  "Convert DATE to human readable string ISO-8601."
  (date->string date "~1"))

(define (paper-layout site title body)
  `((doctype "html")
    (head


@@ 64,20 69,22 @@
          ,body
          ,%default-footer))))


(define (paper-collection-template site title posts prefix)
  (define (post-uri post)
    (string-append (or prefix "") "/"
                   (site-post-slug site post) ".html"))

  `((h1 ,title)
    (ul
     ,@(map (lambda (post)
              `(li
                (a (@ (href ,(post-uri post)))
                   ,(post-ref post 'title)
                   " — "
                   ,(date->string* (post-date post)))))
            posts))))
    (div (@ (class "post-list"))
         ,@(map (lambda (post)
                  `(span
                    ,(date->iso-string (post-date post))
                    " — "
                    (a (@ (href ,(post-uri post)))
                       ,(post-ref post 'title))
                    (br)))
                posts))))

(define (paper-post-template post)
  `((h1 (@ (style "text-align:center")) ,(post-ref post 'title))


@@ 85,9 92,11 @@
       ,(post-ref post 'author)
       (br)
       (small
        "Department of Blog Posts, " (a (@ (href "/")) "trop.in"))
        (a (@ (class "invisible-link") (href "/blog"))
           "Department of Blog Posts, ")
        (a (@ (href "/")) "trop.in"))
       (br)
       (small ,(date->string* (post-date post))))
       (small ,(date->paper-string (post-date post))))
    (div
     (h2 "Abstract")
     ,(post-ref post 'abstract)


@@ 114,26 123,34 @@
                      #:key
                      (theme (page-theme))
                      (reader commonmark-reader))
  "Return a builder procedure that convert file to html and put it to
build-directory of the site."
  "Return a builder procedure that reads FILE into SXML, adjusts it
according to the THEME and serialize to HTML and put it to
build-directory of the site.  DESTINATION is a relative resulting file
path."
  (lambda (site posts)
    (list
     (serialized-artifact
      destination
      (render-post theme site
                   (read-post reader file '()))
      (render-post theme site (read-post reader file '()))
      sxml->html))))

(define (post-draft? post)
  (not (post-ref post 'date)))

(define (posts/published posts)
  (posts/reverse-chronological
   (filter (lambda (x) (not (post-draft? x))) posts)))

(define (posts/filter-by-tag tag)
  (lambda (posts)
    (posts/reverse-chronological
     (or
      (assoc-ref (posts/group-by-tag posts) tag)
      (list)))))
    (let ((published-posts (posts/published posts)))
      (posts/reverse-chronological
       (or
        (assoc-ref (posts/group-by-tag published-posts) tag)
        (list))))))

(define %blog-collections
  `(("trop.in/blog" "index.html" ,posts/reverse-chronological)
  `(("trop.in/blog" "index.html" ,posts/published)
    ("trop.in/tech" "tech.html" ,(posts/filter-by-tag "tech"))
    ("trop.in/life" "life.html" ,(posts/filter-by-tag "life"))))