hakyll-3.2.0.3: A static website compiler library

Hakyll.Web.Page

Description

A page is a key-value mapping, representing a page on your site

A page is an important concept in Hakyll. It is a key-value mapping, and has one field with an arbitrary type. A Page thus consists of

  • metadata (of the type Map String String);
  • the actual value (of the type a).

Usually, the value will be a String as well, and the value will be the body of the page.

However, this is certainly no restriction. For example, Page ByteString could be used to represent a binary item (e.g. an image) and some metadata.

Pages can be constructed using Haskell, but they are usually parsed from a file. The file format for pages is pretty straightforward.

 This is a simple page
 consisting of two lines.

This is a valid page with two lines. If we load this in Hakyll, there would be no metadata, and the body would be the given text. Let's look at a page with some metadata:

 ---
 title: Alice's Adventures in Wonderland
 author: Lewis Caroll
 year: 1865
 ---

 Chapter I
 =========

 Down the Rabbit-Hole
 --------------------

 Alice was beginning to get very tired of sitting by her sister on the bank,
 and of having nothing to do: once or twice she had peeped into the book her
 sister was reading, but it had no pictures or conversations in it, "and
 what is the use of a book," thought Alice "without pictures or
 conversation?"

 ...

As you can see, we construct a metadata header in Hakyll using ---. Then, we simply list all key: value pairs, and end with --- again. This page contains three metadata fields and a body. The body is given in markdown format, which can be easily rendered to HTML by Hakyll, using pandoc.

Synopsis

Documentation

data Page a Source

Type used to represent pages

Constructors

Page 

Instances

Functor Page 
Typeable1 Page 
Eq a => Eq (Page a) 
Show a => Show (Page a) 
Monoid a => Monoid (Page a) 
Binary a => Binary (Page a) 
Writable a => Writable (Page a) 

fromBody :: a -> Page aSource

Create a page from a body, without metadata

fromMap :: Monoid a => Map String String -> Page aSource

Create a metadata page, without a body

toMap :: Page String -> Map String StringSource

Convert a page to a map. The body will be placed in the body key.

readPageCompiler :: Compiler Resource (Page String)Source

Read a page (do not render it)

pageCompiler :: Compiler Resource (Page String)Source

Read a page, add default fields, substitute fields and render using pandoc

pageCompilerWith :: ParserState -> WriterOptions -> Compiler Resource (Page String)Source

A version of pageCompiler which allows you to specify your own pandoc options

pageCompilerWithPandoc :: ParserState -> WriterOptions -> (Pandoc -> Pandoc) -> Compiler Resource (Page String)Source

An extension of pageCompilerWith which allows you to specify a custom pandoc transformer for the content

pageCompilerWithFields :: ParserState -> WriterOptions -> (Pandoc -> Pandoc) -> Compiler (Page String) (Page String) -> Compiler Resource (Page String)Source

This is another, even more advanced version of pageCompilerWithPandoc. This function allows you to provide an arrow which is applied before the fields in a page are rendered. This means you can use this extra customizable stage to add custom fields which are inserted in the page.

addDefaultFields :: Compiler (Page a) (Page a)Source

Add a number of default metadata fields to a page. These fields include:

  • $url
  • $category
  • $title
  • $path