-- | 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---- * a key-value mapping (of the type @Map String String@);---- * a value (of the type @a@).---- Usually, the value will be a 'String' as well, and the value will be the body-- of the page.---- 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.--{-# LANGUAGE DeriveDataTypeable #-}moduleHakyll.Web.Page(Page(..),fromBody,fromMap,toMap,readPageCompiler,pageCompiler,pageCompilerWith,addDefaultFields,sortByBaseName)whereimportPreludehiding(id)importControl.Category(id)importControl.Arrow(arr,(>>^),(&&&),(>>>))importSystem.FilePath(takeBaseName,takeDirectory)importqualifiedData.MapasMimportData.List(sortBy)importData.Ord(comparing)importText.Pandoc(ParserState,WriterOptions)importHakyll.Core.IdentifierimportHakyll.Core.CompilerimportHakyll.Core.ResourceimportHakyll.Web.Page.InternalimportHakyll.Web.Page.ReadimportHakyll.Web.Page.MetadataimportHakyll.Web.PandocimportHakyll.Web.TemplateimportHakyll.Web.Util.Url-- | Create a page from a body, without metadata--fromBody::a->PageafromBody=PageM.empty-- | Read a page (do not render it)--readPageCompiler::CompilerResource(PageString)readPageCompiler=getResourceString>>^readPage-- | Read a page, add default fields, substitute fields and render using pandoc--pageCompiler::CompilerResource(PageString)pageCompiler=cached"Hakyll.Web.Page.pageCompiler"$readPageCompiler>>>addDefaultFields>>>arrapplySelf>>>pageRenderPandoc-- | A version of 'pageCompiler' which allows you to specify your own pandoc-- options--pageCompilerWith::ParserState->WriterOptions->CompilerResource(PageString)pageCompilerWithstateoptions=cached"pageCompilerWith"$readPageCompiler>>>addDefaultFields>>>arrapplySelf>>>pageRenderPandocWithstateoptions-- | Add a number of default metadata fields to a page. These fields include:---- * @$url@---- * @$category@---- * @$title@---- * @$path@--addDefaultFields::Compiler(Pagea)(Pagea)addDefaultFields=(getRoute&&&id>>^uncurryaddRoute)>>>(getIdentifier&&&id>>^uncurryaddIdentifier)where-- Add root and url, based on routeaddRouteNothing=idaddRoute(Justr)=trySetField"url"(toUrlr)-- Add title and category, based on identifieraddIdentifieri=trySetField"title"(takeBaseNamep).trySetField"category"(takeBaseName$takeDirectoryp).trySetField"path"pwherep=toFilePathi-- | Sort posts based on the basename of the post. This is equivalent to a-- chronologival sort, because of the @year-month-day-title.extension@ naming-- convention in Hakyll.--sortByBaseName::[Pagea]->[Pagea]sortByBaseName=sortBy$comparing$takeBaseName.getField"path"