on master help sign in
Cleaner page reading.
commit77f9129e732c9273c6f92d5c0666f8d4d82b8664 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 19 Jan 2010, 10:08 (17 years ago) parent7af4014
1 file changed+10−10
src/Text/Hakyll/Page.hs+10−10
src/Text/Hakyll/Page.hs+10−10
@@ -113,23 +113,23 @@ readSection :: (String -> String) -- ^ Render function.
113113 -> [String] -- ^ Lines in the section.
114114 -> [(String, String)] -- ^ Key-values extracted.
115115readSection _ _ [] = []
116−readSection renderFunction True ls
117− | isDelimiter (head ls) = readSimpleMetaData (tail ls)
118− | otherwise = [("body", renderFunction $ unlines ls)]
116+readSection renderFunction isFirst ls
117+ | not isDelimiter' = body ls
118+ | isNamedDelimiter = readSectionMetaData ls
119+ | isFirst = readSimpleMetaData (tail ls)
120+ | otherwise = body (tail ls)
119121 where
122+ isDelimiter' = isDelimiter (head ls)
123+ isNamedDelimiter = (head ls) `matchesRegex` "----* *[a-zA-Z][a-zA-Z]*"
124+ body ls' = [("body", renderFunction $ unlines ls')]
125+
120126 readSimpleMetaData = map readPair
121127 readPair = (trimPair . break (== ':'))
122128 trimPair (key, value) = (trim key, trim $ tail value)
123129
124−readSection renderFunction False ls
125− | isDelimiter (head ls) = readSectionMetaData ls
126− | otherwise = error $ "Page parsing error at: " ++ head ls
127− where
128130 readSectionMetaData [] = []
129131 readSectionMetaData (header:value) =
130− let key = if header `matchesRegex` "----* *[a-zA-Z][a-zA-Z]*"
131− then substituteRegex "[^a-zA-Z]" "" header
132− else "body"
132+ let key = substituteRegex "[^a-zA-Z]" "" header
133133 in [(key, renderFunction $ unlines value)]
134134
135135-- | Read a page from a file. Metadata is supported, and if the filename