Next: , Up: Readers   [Contents][Index]

5.3.1 Reader

(use-modules (haunt reader))

The purpose of a reader is to translate the markup within a post file into an SXML tree representing the HTML structure and associate some metadata with it.

Procedure: make-reader matcher proc

Create a new reader. The reader is to be activated when matcher, a procedure that accepts a file name as its only argument, returns #t. When a post file matches, the procedure proc, which also accepts a file name as its only argument, reads the contents and returns a post object (see Posts).

Procedure: reader? object

Return #t if object is a reader.

Procedure: reader-matcher reader

Return the match procedure for reader.

Procedure: reader-proc reader

Return the read procedure for reader.

Procedure: reader-match? reader file-name

Return #t if file-name is a file supported by reader.

Procedure: reader-find? readers file-name

Return the first reader in readers that can parse file-name, or #f if there is no such reader.

Procedure: reader-read reader file-name

Parse file-name using reader and return two values: an alist of metadata and an SXML tree.

Procedure: read-post reader file-name [default-metadata]

Read a post object from file-name using reader, merging its metadata with default-metadata, or the empty list if not specified.

Procedure: read-posts directory keep? readers [default-metadata]

Read all of the files in directory that match keep? as post objects. The readers list must contain a matching reader for every post.

Procedure: make-file-extension-matcher ext

Create a procedure that returns #t when a file name ends with “.ext”.

Procedure: sxml-reader

A basic reader for posts written as Scheme code that evaluates to an an association list. The special key content contains the post body as an SXML tree.


(use-modules (haunt utils))

`((title . "Hello, world!")
  (date . ,(string->date* "2015-04-10 23:00"))
  (tags "foo" "bar")
  (summary . "Just a test")
   ((h2 "Hello!")
    (p "This is Haunt.  A static site generator for GNU Guile."))))
Procedure: html-reader

A basic reader for posts written in plain ol’ HTML. Metadata is encoded as the key: value pairs, one per line, at the beginning of the file. A line with the --- sentinel marks the end of the metadata section and the rest of the file is encoded as HTML.


title: A Foo Walks Into a Bar
date: 2015-04-11 20:00
tags: bar
  This is an example using raw HTML, because Guile doesn't have a
  Markdown parser.

Next: Texinfo, Up: Readers   [Contents][Index]