@@ -1,23 +1,15 @@
1-- | A module for dealing with @Page@s. This module is mostly internally used.
1-- | A module for dealing with @Page@s. This module is mostly internally used.
2module Text.Hakyll.Internal.Page
2module Text.Hakyll.Internal.Page
7− , readPage
3+ ( readPage
10import qualified Data.Map as M
6import qualified Data.Map as M
11import Data.List (isPrefixOf)
7import Data.List (isPrefixOf)
12import Data.Char (isSpace)
8import Data.Char (isSpace)
13−import Data.Maybe (fromMaybe)
14−import Control.Monad (liftM, replicateM)
15import Control.Monad.Reader (liftIO)
9import Control.Monad.Reader (liftIO)
16import System.FilePath
10import System.FilePath
18−import Test.QuickCheck
19import Text.Pandoc
12import Text.Pandoc
22import Text.Hakyll.Context (Context)
14import Text.Hakyll.Context (Context)
23import Text.Hakyll.File
15import Text.Hakyll.File
@@ -26,25 +18,6 @@ import Text.Hakyll.Regex (substituteRegex, matchesRegex)
26import Text.Hakyll.Util (trim)
18import Text.Hakyll.Util (trim)
27import Text.Hakyll.Internal.Cache
19import Text.Hakyll.Internal.Cache
29−-- | A Page is basically key-value mapping. Certain keys have special
30−-- meanings, like for example url, body and title.
31−data Page = Page Context
32− deriving (Ord, Eq, Show, Read)
34−-- | Create a Page from a key-value mapping.
35−fromContext :: Context -> Page
38−-- | Obtain a value from a page. Will resturn an empty string when nothing is
40−getValue :: String -> Page -> String
41−getValue str (Page page) = fromMaybe [] $ M.lookup str page
43−-- | Get the body for a certain page. When not defined, the body will be
45−getBody :: Page -> String
46−getBody (Page page) = fromMaybe [] $ M.lookup "body" page
48-- | The default reader options for pandoc parsing.
21-- | The default reader options for pandoc parsing.
49readerOptions :: ParserState
22readerOptions :: ParserState
50readerOptions = defaultParserState
23readerOptions = defaultParserState
@@ -143,22 +116,3 @@ readPage path = do
143 return page
116 return page
145 fileName = "pages" </> path
118 fileName = "pages" </> path
147−-- Make pages serializable.
148−instance Binary Page where
149− put (Page context) = put $ M.toAscList context
150− get = liftM (Page . M.fromAscList) get
152−-- | Generate an arbitrary page.
153−arbitraryPage :: Gen Page
154−arbitraryPage = do keys <- listOf key'
156− return $ Page $ M.fromList $ zip keys values
158− key' = do l <- choose (5, 10)
159− replicateM l $ choose ('a', 'z')
161−-- Make pages testable
162−instance Arbitrary Page where
163− arbitrary = arbitraryPage
164− shrink (Page context) = map (Page . flip M.delete context) $ M.keys context