summaryrefslogtreecommitdiff
path: root/haunt/page.scm
blob: 85b2ae659c10f21ab80032b22d0de0ac3ea1cd22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;;; Haunt --- Static site generator for GNU Guile
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;;
;;; This file is part of Haunt.
;;;
;;; Haunt is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; Haunt is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Haunt.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; Page data type.
;;
;;; Code:

(define-module (haunt page)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-9)
  #:use-module (srfi srfi-26)
  #:use-module (haunt utils)
  #:export (make-page
            page?
            page-file-name
            page-contents
            page-writer
            write-page))

(define-record-type <page>
  (make-page file-name contents writer)
  page?
  (file-name page-file-name)
  (contents page-contents)
  (writer page-writer))

(define (write-page page output-directory)
  "Write PAGE to OUTPUT-DIRECTORY."
  (match page
    (($ <page> file-name contents writer)
     (let ((output (string-append output-directory "/" file-name)))
       (mkdir-p (dirname output))
       (call-with-output-file output (cut writer contents <>))))))