haunt.scm 3.66 KB
Newer Older
Ludovic Courtès's avatar
Ludovic Courtès committed
1 2 3 4 5 6 7 8 9 10 11
;;; This module is part of Guix-HPC and is licensed under the same terms,
;;; those of the GNU GPL version 3 or (at your option) any later version.
;;;
;;; Copyright © 2017 Inria

;; This is a build file for Haunt.  Run 'haunt build' to build the web site,
;; and 'haunt serve' to serve it locally.  Alternatively, you can run
;; 'guix build -f guix.scm' to have everything built in the store.
(use-modules (haunt site)
             (haunt reader)
             (haunt reader commonmark)
Roel Janssen's avatar
Roel Janssen committed
12
             (haunt post)
Ludovic Courtès's avatar
Ludovic Courtès committed
13 14 15 16 17 18 19 20
             (haunt page)
             (haunt html)
             (haunt utils)
             (haunt builder assets)
             (haunt builder blog)
             (haunt builder atom)
             (ice-9 match)
             (srfi srfi-1)
Roel Janssen's avatar
Roel Janssen committed
21
             (srfi srfi-19)
22
             (srfi srfi-26)
Ludovic Courtès's avatar
Ludovic Courtès committed
23 24
             (guix-hpc))

Ludovic Courtès's avatar
Ludovic Courtès committed
25 26 27
(define %web-site-title
  "Guix-HPC — Reproducible software deployment for high-performance computing")

Roel Janssen's avatar
Roel Janssen committed
28 29 30
(define* (post->sxml post #:key post-uri)
  "Return the SXML for POST."
  `(div (@ (class "post"))
31
        (h1 (@ (class "title"))
Roel Janssen's avatar
Roel Janssen committed
32 33 34 35 36 37 38 39 40
            ,(if post-uri
                 `(a (@ (href ,post-uri))
                     ,(post-ref post 'title))
                 (post-ref post 'title)))
        (div (@ (class "post-about"))
             ,(post-ref post 'author)
             " — " ,(date->string (post-date post) "~B ~e, ~Y"))
        (hr)
        (div (@ (class "post-body"))
41
             ,(syntax-highlight (post-sxml post)))))
Roel Janssen's avatar
Roel Janssen committed
42 43 44 45 46 47 48 49 50

(define (page->sxml site title posts prefix)
  "Return the SXML for the news page of SITE, containing POSTS."
  `((div (@ (class "header"))
         (div (@ (class "post-list"))
              ,@(map (lambda (post)
                       (post->sxml post #:post-uri (post-url post site)))
                     posts)))))

51 52 53 54 55
(define (post->page post site)
  (make-page (string-append (post-url post site) "/index.html")
             (render-post %hpc-haunt-theme site post)
             sxml->html))

Roel Janssen's avatar
Roel Janssen committed
56 57
(define %hpc-haunt-theme
  ;; Theme for the rendering of the news pages.
Ludovic Courtès's avatar
Ludovic Courtès committed
58
  (theme #:name "Guix-HPC"
Roel Janssen's avatar
Roel Janssen committed
59
         #:layout (lambda (site title body)
Ludovic Courtès's avatar
Ludovic Courtès committed
60
                    (base-layout body #:title %web-site-title))
Roel Janssen's avatar
Roel Janssen committed
61 62 63
         #:post-template post->sxml
         #:collection-template page->sxml))

Ludovic Courtès's avatar
Ludovic Courtès committed
64 65 66 67 68 69 70 71
(define %local-test?
  ;; True when we're testing locally, as opposed to producing things to
  ;; install to gnu.org.
  (or (getenv "WEB_SITE_LOCAL")
      (member "serve" (command-line))))           ;'haunt serve' command

(when %local-test?
  ;; The URLs produced in these pages are only meant for local consumption.
Roel Janssen's avatar
Roel Janssen committed
72
  (format #t "~%Producing Web pages for local tests *only*!~%~%"))
Ludovic Courtès's avatar
Ludovic Courtès committed
73

Ludovic Courtès's avatar
Ludovic Courtès committed
74
(site #:title %web-site-title
Ludovic Courtès's avatar
Ludovic Courtès committed
75 76 77 78 79 80
      #:domain "//hpc.guixsd.org/"
      #:default-metadata
      '((author . "Guix-HPC Contributors")
        (email  . "guix-devel@gnu.org"))
      #:readers (list commonmark-reader)
      #:builders
81 82 83 84 85 86 87 88 89 90 91 92
      (cons* (lambda (site posts)
               ;; Pages for each post.
               (map (cut post->page <> site) posts))

             (lambda (site posts)
               ;; The main collection.
               (make-page
                "/blog/index.html"
                (render-collection %hpc-haunt-theme site
                                   %web-site-title
                                   posts "/blog")
                sxml->html))
Ludovic Courtès's avatar
Ludovic Courtès committed
93 94 95

             ;; Apparently the <link> tags of Atom entries must be absolute URLs,
             ;; hence this #:blog-prefix.
96
             (atom-feed #:file-name "blog/feed.xml"
Ludovic Courtès's avatar
Ludovic Courtès committed
97 98
                        #:blog-prefix "https://hpc.guixsd.org")

Roel Janssen's avatar
Roel Janssen committed
99
             (static-directory "static")
Ludovic Courtès's avatar
Ludovic Courtès committed
100 101 102 103 104

             (map (lambda (page)
                    (lambda (site posts)
                      page))
                  (static-pages))))