]> git.jsancho.org Git - blog.git/blob - haunt.scm
Fix issue reading posts body with Haunt 0.2.5
[blog.git] / haunt.scm
1 (use-modules (haunt asset)
2              (haunt builder blog)
3              (haunt builder atom)
4              (haunt builder assets)
5              (haunt html)
6              (haunt page)
7              (haunt reader)
8              (haunt reader texinfo)
9              (haunt site)
10              (haunt post)
11              (srfi srfi-1)
12              (srfi srfi-19))
13
14 (define (stylesheet name)
15   `(link (@ (rel "stylesheet")
16             (href ,(string-append "css/" name ".css")))))
17
18 (define (static-page title file-name body)
19   (lambda (site posts)
20     (make-page file-name
21                (with-layout flex-theme site title body)
22                sxml->html)))
23
24 (define (get-tags post)
25   (or (assoc-ref (post-metadata post) 'tags) '()))
26
27 (define (post-date-and-tags date tags)
28   (let ((div `(div (@ (class "date-and-tags"))
29                    (time (@ (datetime ,(date->string date "~Y-~m-~dT~H:~M:~S")))
30                          ,(date->string date "~Y-~m-~d")))))
31     (cond ((> (length tags) 0)
32            (append div
33                    `(" "
34                      (span (@ (style "margin: 0 3px")) ⦿)
35                      (span (@ (class "tags"))
36                            ,@(drop-right
37                               (apply
38                                append
39                                (map (lambda (tag)
40                                       `((a (@ (href ,(format #f "tags/~a.html" tag))) ,tag) ", "))
41                                     tags))
42                               1)))))
43           (else
44            div))))
45
46 (define flex-theme
47   (theme #:name "Flex"
48          #:layout
49          (lambda (site title body)
50            `((doctype "html")
51              (html
52               (head
53                (meta (@ (charset "utf-8")))
54                (title ,(string-append title " - " (site-title site)))
55                (link (@ (rel "stylesheet") (href "https://fonts.googleapis.com/css?family=Merriweather+Sans:400,300,300italic,400italic,700,700italic,800,800italic|Merriweather:400,300,300italic,400italic,700,700italic,900,900italic|Source+Code+Pro:200,300,400,500,600,700,900")))
56                ,(stylesheet "application.min")
57                ,(stylesheet "pygments.min")
58                ,(stylesheet "custom")
59                (meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0"))))
60               (body
61                ,(let ((metadata (site-default-metadata site)))
62                   `(div (@ (id "page-content"))
63                         (header
64                          (nav (@ (role "navigation") (class "navigation-bar"))
65                               (ul (@ (class "navigation-items left"))
66                                   (li (@ (id "blog-title-header"))
67                                       (a (@ (href "index.html"))
68                                          (h1 ,(assoc-ref metadata 'author)))))
69                               (ul (@ (class "navigation-items center")))
70                               (ul (@ (class "navigation-items right"))
71                                   ,@(map (lambda (page)
72                                            `(li (a (@ (href ,(cdr page))) ,(car page))))
73                                          (assoc-ref metadata 'pages)))))
74                         (section (@ (role "main"))
75                                  (div (@ (class "content") (class "col-md-12")) ,body))))))))
76
77          #:post-template
78          (lambda (post)
79            `((article (@ (class "inline"))
80                       (header
81                        (h1 (@ (class "title")) ,(post-ref post 'title))
82                        ,(post-date-and-tags (post-date post) (get-tags post)))
83                       ,(post-sxml post))))
84
85          #:collection-template
86          (lambda (site title posts prefix)
87            (define (post-uri post)
88              (string-append (or prefix "")
89                             (site-post-slug site post) ".html"))
90
91            (define (get-paragraphs sxml count)
92              (define (getp sxml count res)
93                (cond ((or (= count 0) (null? sxml))
94                       res)
95                      ((and (pair? (car sxml)) (eq? (caar sxml) 'p))
96                       (getp (cdr sxml) (- count 1) (cons (car sxml) res)))
97                      (else
98                       (getp (cdr sxml) count (cons (car sxml) res)))))
99              (reverse (getp sxml count '())))
100                      
101            (define (post-summary post)
102              (or (post-ref post 'summary)
103                  (get-paragraphs (cdr (post-sxml post)) 3)))
104
105            `(
106              ,@(map (lambda (post)
107                       `(article (@ (class "inline"))
108                                 (header
109                                  (h2 (@ (class "title"))
110                                      (a (@ (href ,(post-uri post)))
111                                         ,(post-ref post 'title)))
112                                  ,(post-date-and-tags (post-date post) (get-tags post)))
113                                 ,(post-summary post)
114                                 (footer (@ (class "read-more"))
115                                            (a (@ (href ,(post-uri post))) "...read more..."))))
116                     (posts/reverse-chronological posts))))))
117
118 (define about-page
119   (static-page
120    "About me"
121    "about.html"
122    `((h2 "hi."))))
123
124 (define %collections
125   `(("Home" "index.html" ,posts/reverse-chronological)))
126
127 (site #:title "Javier Sancho"
128       #:domain "jsancho.org"
129       #:default-metadata
130       '((author . "Javier Sancho")
131         (description . "Free Software Evangelist - Programmer")
132         (email . "jsf@jsancho.org")
133         (picture . "images/jsancho.jpg")
134         (pages . (("projects" . "http://git.jsancho.org/")
135                   ("about me" . "about.html"))))
136       #:readers (list sxml-reader html-reader)
137       #:builders (list (blog #:theme flex-theme #:collections %collections)
138                        (atom-feed)
139                        (atom-feeds-by-tag)
140                        about-page
141                        (static-directory "images")
142                        (static-directory "fonts")
143                        (static-directory "css")))