6de65a8ec78ff25e4f53ee7168dc00bf4f72f03d — Andrew Tropin 4 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/"))

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

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

(define* (page-theme
          (footer %default-footer))
   (lambda (site title body)
     `((doctype "html")
        (meta (@ (charset "utf-8")))
        (title ,(string-append title " — " (site-title site)))
        ,(stylesheet "simple"))
        (div (@ (class "container"))
   (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
                      (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)
      (render-post theme site
                   (read-post reader file '()))

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

(define (posts/filter-by-tag tag)
  (lambda (posts)
      (assoc-ref (posts/group-by-tag posts) tag)

(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"
        '((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")