82f6f7f0df7a83447c79ce83758ceb39bf757921
[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 flex-theme
28   (theme #:name "Flex"
29          #:layout
30          (lambda (site title body)
31            `((doctype "html")
32              (html
33               (head
34                (meta (@ (charset "utf-8")))
35                (title ,(string-append title " - " (site-title site)))
36                (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")))
37                ,(stylesheet "application.min")
38                ,(stylesheet "pygments.min")
39                (meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0"))))
40               (body
41                ,(let ((metadata (site-default-metadata site)))
42                   `(div (@ (id "page-content"))
43                         (header
44                          (nav (@ (role "navigation") (class "navigation-bar"))
45                               (ul (@ (class "navigation-items left"))
46                                   (li (@ (id "blog-title-header"))
47                                       (a (@ (href "index.html"))
48                                          (h1 ,(assoc-ref metadata 'author)))))
49                               (ul (@ (class "navigation-items center")))
50                               (ul (@ (class "navigation-items right"))
51                                   ,@(map (lambda (page)
52                                            `(li (a (@ (href ,(cdr page))) ,(car page))))
53                                          (assoc-ref metadata 'pages)))))
54                         (section (@ (role "main"))
55                                  (div (@ (class "content") (class "col-md-12")) ,body))))))))
56
57          #:post-template
58          (lambda (post)
59            `((article (@ (class "single"))
60                       (header
61                        (h1 ,(post-ref post 'title))
62                        (p "Posted on " ,(date->string (post-date post) "~B ~d, ~Y")))
63                       ,(post-sxml post)
64                       (div (@ (class "tag-cloud"))
65                            (p
66                             ,@(map (lambda (tag)
67                                      `((a (@ (href "")) ,tag) " "))
68                                    (get-tags post)))))))
69
70          #:collection-template
71          (lambda (site title posts prefix)
72            (define (post-uri post)
73              (string-append (or prefix "")
74                             (site-post-slug site post) ".html"))
75
76            (define (get-paragraphs sxml count)
77              (let ((pars (filter
78                           (lambda (e) (and (pair? e) (eq? (car e) 'p)))
79                           sxml)))
80                (list-head pars (min count (length pars)))))
81                      
82            (define (post-summary post)
83              (or (post-ref post 'summary)
84                  (get-paragraphs (cdr (post-sxml post)) 3)))
85
86            `(
87              ,@(map (lambda (post)
88                       `(article (@ (class "inline"))
89                                 (header
90                                  (h2 (@ (class "title"))
91                                      (a (@ (href ,(post-uri post)))
92                                         ,(post-ref post 'title)))
93                                  (div (@ (class "date-and-tags"))
94                                       (time (@ (datetime ,(date->string (post-date post) "~Y-~m-~dT~H:~M:~S")))
95                                             ,(date->string (post-date post) "~Y-~m-~d"))
96                                       " "
97                                       ,(let ((tags (get-tags post)))
98                                          (cond ((= (length tags) 0)
99                                                 `(span (@ (style "margin: 0 3px")) ÔŽ┐)
100                                                 `(span (@ (class "tags"))
101                                                       ,@(map (lambda (tag)
102                                                                `((a (@ (href (format #f "tags/~a.html" ,tag))) ,tag) " "))
103                                                              tags)))))))
104                                 ,(post-summary post)
105                                 (footer (@ (class "read-more"))
106                                            (a (@ (href ,(post-uri post))) "...more..."))))
107                     (posts/reverse-chronological posts))))))
108
109 (define about-page
110   (static-page
111    "About me"
112    "about.html"
113    `((h2 "hi."))))
114
115 (define %collections
116   `(("Home" "index.html" ,posts/reverse-chronological)))
117
118 (site #:title "Javier Sancho"
119       #:domain "jsancho.org"
120       #:default-metadata
121       '((author . "Javier Sancho")
122         (description . "Free Software Evangelist - Programmer")
123         (email . "jsf@jsancho.org")
124         (picture . "images/jsancho.jpg")
125         (pages . (("projects" . "http://git.jsancho.org/")
126                   ("about me" . "about.html"))))
127       #:readers (list sxml-reader html-reader)
128       #:builders (list (blog #:theme flex-theme #:collections %collections)
129                        (atom-feed)
130                        (atom-feeds-by-tag)
131                        about-page
132                        (static-directory "images")
133                        (static-directory "fonts")
134                        (static-directory "css")))