From aa7aae9d3e168a903ce25a2ecc992f2c36700925 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 10 Apr 2015 23:39:07 -0400 Subject: Add page module. * haunt/page.scm: New file. * Makefile.am (SOURCES): Add it. --- Makefile.am | 1 + haunt/page.scm | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 haunt/page.scm diff --git a/Makefile.am b/Makefile.am index eafc93f..b1924da 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,6 +43,7 @@ SOURCES = \ haunt/config.scm \ haunt/post.scm \ haunt/reader.scm \ + haunt/page.scm \ haunt/ui.scm \ haunt/ui/serve.scm \ haunt/serve/mime-types.scm \ diff --git a/haunt/page.scm b/haunt/page.scm new file mode 100644 index 0000000..4d9fa69 --- /dev/null +++ b/haunt/page.scm @@ -0,0 +1,49 @@ +;;; Haunt --- Static site generator for GNU Guile +;;; Copyright © 2015 David Thompson +;;; +;;; 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 . + +;;; 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 build html) + #:export (make-page + page? + page-file-name + page-contents + page-writer + write-page)) + +(define-record-type + (make-page file-name sxml writer) + page? + (file-name page-file-name) + (sxml page-sxml) + (writer page-writer)) + +(define (write-page page output-directory) + "Write PAGE to OUTPUT-DIRECTORY." + (match page + (($ file-name sxml writer) + (let ((output (string-append output-directory "/" file-name))) + (call-with-output-file output (cut writer sxml <>)))))) -- cgit v1.2.3