summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-19 10:08:31 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-19 10:08:31 +0100
commit77f9129e732c9273c6f92d5c0666f8d4d82b8664 (patch)
treeafb1b8ab12476e3a9ccaaf020cd4a7a5490b5b48
parent7af4014e3fb650db497249e113fe007a53ae6d09 (diff)
downloadhakyll-77f9129e732c9273c6f92d5c0666f8d4d82b8664.tar.gz
Cleaner page reading.
-rw-r--r--src/Text/Hakyll/Page.hs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs
index 6571d96..70724e2 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Page.hs
@@ -113,23 +113,23 @@ readSection :: (String -> String) -- ^ Render function.
-> [String] -- ^ Lines in the section.
-> [(String, String)] -- ^ Key-values extracted.
readSection _ _ [] = []
-readSection renderFunction True ls
- | isDelimiter (head ls) = readSimpleMetaData (tail ls)
- | otherwise = [("body", renderFunction $ unlines ls)]
+readSection renderFunction isFirst ls
+ | not isDelimiter' = body ls
+ | isNamedDelimiter = readSectionMetaData ls
+ | isFirst = readSimpleMetaData (tail ls)
+ | otherwise = body (tail ls)
where
+ isDelimiter' = isDelimiter (head ls)
+ isNamedDelimiter = (head ls) `matchesRegex` "----* *[a-zA-Z][a-zA-Z]*"
+ body ls' = [("body", renderFunction $ unlines ls')]
+
readSimpleMetaData = map readPair
readPair = (trimPair . break (== ':'))
trimPair (key, value) = (trim key, trim $ tail value)
-readSection renderFunction False ls
- | isDelimiter (head ls) = readSectionMetaData ls
- | otherwise = error $ "Page parsing error at: " ++ head ls
- where
readSectionMetaData [] = []
readSectionMetaData (header:value) =
- let key = if header `matchesRegex` "----* *[a-zA-Z][a-zA-Z]*"
- then substituteRegex "[^a-zA-Z]" "" header
- else "body"
+ let key = substituteRegex "[^a-zA-Z]" "" header
in [(key, renderFunction $ unlines value)]
-- | Read a page from a file. Metadata is supported, and if the filename