~abcdw/trop.in

6de65a8ec78ff25e4f53ee7168dc00bf4f72f03d — Andrew Tropin 1 year, 5 months ago b9b73e4
Add site draft.
1 files changed, 161 insertions(+), 0 deletions(-)

A src/tropin/site.scm
A src/tropin/site.scm => src/tropin/site.scm +161 -0
@@ 0,0 1,161 @@
(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 (stylesheet name)
  `(link (@ (rel "stylesheet")
            (href ,(string-append "/assets/" name ".css")))))

(define %cc-by-sa-link
  '(a (@ (href "https://creativecommons.org/licenses/by-sa/4.0/"))
      "CC-BY-SA"))

(define %source-code
  '(a (@ (href "https://git.sr.ht/~abcdw/trop.in"))
      "here"))

(define %default-footer
  `(footer (p
            (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 simple-theme
  (theme #:name "Paper Like"
         #:layout
         (lambda (site title body)
           `((doctype "html")
             (head
              (meta (@ (charset "utf-8")))
              (title ,(string-append title " — " (site-title site)))
              ,(stylesheet "simple")
              ,(stylesheet "paper"))
             (body
              (div (@ (class "container"))
                   ,body
                   ,%default-footer))))
         #:post-template
         (lambda (post)
           `((h1 (@ (style "text-align:center")) ,(post-ref post 'title))
             (p (@ (style "text-align:center"))
                ,(post-ref post 'author)
                (br)
                (small
                 "Department of Blog Posts, " (a (@ (href "/")) "trop.in"))
                (br)
                (small ,(date->string* (post-date post))))
             (div
              (h2 (@ (class "nonumber")) "Abstract")
              ,(post-ref post 'abstract)
              ,(post-sxml post))))))

(define* (page-theme
          #:key
          (footer %default-footer))
  (theme
   #:layout
   (lambda (site title body)
     `((doctype "html")
       (head
        (meta (@ (charset "utf-8")))
        (title ,(string-append title " — " (site-title site)))
        ,(stylesheet "simple"))
       (body
        (div (@ (class "container"))
             ,body
             ,footer))))
   #:post-template
   (lambda (post)
     `((div ,(post-sxml post))))))

(use-modules (haunt artifact))

(define (verbatim-artifact source destination)
  (unless (file-exists? source)
    (error "verbatim artifact source file does not exist" source))
  (make-artifact destination
                 (lambda (output)
                   (format #t "copy '~a' → '~a'~%" source destination)
                   (copy-file source output))))

(define* (static-page file destination
                      #: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."
  (lambda (site posts)
    (list
     (serialized-artifact
      destination
      (render-post theme site
                   (read-post reader file '()))
      sxml->html))))

(define (wrap f)
  (lambda (site posts)
    ((@ (ice-9 pretty-print) pretty-print)
     site)
    ((@ (ice-9 pretty-print) pretty-print)
     posts)
    (let ((sd (f site posts)))
      ((@ (ice-9 pretty-print) pretty-print)
       sd)
      sd)))


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

(define %blog-collections
  `(("All" "index.html" ,posts/reverse-chronological)
    ("Tech" "tech.html" ,(posts/filter-by-tag "tech"))
    ("Personal" "personal.html" ,(posts/filter-by-tag "personal"))))

(define-public main-site
  (site #:title "trop.in"
        #:domain "trop.in"
        #:default-metadata
        '((author . "Andrew Tropin")
          (email  . "andrew@trop.in"))
        #:readers (list skribe-reader commonmark-reader)
        #:build-directory "target/tmp-site"
        #:posts-directory "pages/posts"
        #:builders (list
                    (static-page "pages/index.html" "index.html"
                                 #:reader html-reader)
                    (static-page "pages/stream.html" "stream.html"
                                 #:reader html-reader)
                    (static-page "pages/guix.md" "guix.html")
                    (static-page "pages/contact.md" "contact.html")
                    (static-page "pages/sport.md" "sport.html")
                    (static-page "pages/rde/index.md" "rde/index.html")
                    (blog #:theme simple-theme
                          #:prefix "/blog"
                          #:collections %blog-collections)
                    (static-directory "assets" "assets")
                    ;; (atom-feed)
                    ;; (atom-feeds-by-tag)
                    )))

;; (build-site main-site)

;; ((@ (haunt serve web-server) serve) "target/tmp-site")