@@ -17,9 +17,16 @@ import Text.Hakyll.HakyllAction
1717import Text.Hakyll.Regex (substituteRegex, matchesRegex)
1818import Text.Hakyll.Util (trim)
1919
20−-- | Page info handle: (key, value, needs rendering)
20+-- | A page is first parsed into a number of page sections. A page section
21+-- consists of:
2122--
22−data PageSection = PageSection {unPageSection :: [(String, String, Bool)]}
23+-- * A key
24+--
25+-- * A value
26+--
27+-- * A 'Bool' flag, indicating if the value is applicable for rendering
28+--
29+data PageSection = PageSection {unPageSection :: (String, String, Bool)}
2330 deriving (Show)
2431
2532-- | Split a page into sections.
@@ -48,26 +55,26 @@ isPossibleDelimiter = isPrefixOf "---"
4855--
4956readSection :: Bool -- ^ If this section is the first section in the page.
5057 -> [String] -- ^ Lines in the section.
51− -> PageSection -- ^ Key-values extracted.
52−readSection _ [] = PageSection []
58+ -> [PageSection] -- ^ Key-values extracted.
59+readSection _ [] = []
5360readSection isFirst ls
54− | not isDelimiter' = body ls
55− | isNamedDelimiter = PageSection $ readSectionMetaData ls
56− | isFirst = PageSection $ readSimpleMetaData (drop 1 ls)
57− | otherwise = body (drop 1 ls)
61+ | not isDelimiter' = [body ls]
62+ | isNamedDelimiter = readSectionMetaData ls
63+ | isFirst = readSimpleMetaData (drop 1 ls)
64+ | otherwise = [body (drop 1 ls)]
5865 where
5966 isDelimiter' = isPossibleDelimiter (head ls)
6067 isNamedDelimiter = head ls `matchesRegex` "^----* *[a-zA-Z0-9][a-zA-Z0-9]*"
61− body ls' = PageSection [("body", unlines ls', True)]
68+ body ls' = PageSection ("body", unlines ls', True)
6269
6370 readSimpleMetaData = map readPair . filter (not . all isSpace)
6471 readPair = trimPair . break (== ':')
65− trimPair (key, value) = (trim key, trim (drop 1 value), False)
72+ trimPair (key, value) = PageSection (trim key, trim (drop 1 value), False)
6673
6774 readSectionMetaData [] = []
6875 readSectionMetaData (header:value) =
6976 let key = substituteRegex "[^a-zA-Z0-9]" "" header
70− in [(key, unlines value, True)]
77+ in [PageSection (key, unlines value, True)]
7178
7279-- | Read a page from a file. Metadata is supported.
7380--
@@ -79,14 +86,14 @@ readPage path = do
7986 contents <- liftIO $ readFile path
8087 url <- toUrl path
8188 let sections = evalState (splitAtDelimiters $ lines contents) Nothing
82− sectionsData = zipWith ($) sectionFunctions sections
89+ sectionsData = concat $ zipWith ($) sectionFunctions sections
8390
84− return $ PageSection [ ("url", url, False)
85− , ("path", path, False)
86− ] : category : sectionsData
91+ return $ PageSection ("url", url, False)
92+ : PageSection ("path", path, False)
93+ : (category ++ sectionsData)
8794 where
8895 category = let dirs = splitDirectories $ takeDirectory path
89− in PageSection [("category", last dirs, False) | not (null dirs)]
96+ in [PageSection ("category", last dirs, False) | not (null dirs)]
9097
9198-- | Read a page from a file. Metadata is supported.
9299--