summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexey Kreshchuk <akrsch@gmail.com>2013-10-15 03:59:16 +0400
committerAlexey Kreshchuk <akrsch@gmail.com>2013-10-15 03:59:16 +0400
commita6ae4eb99dd5f9957adc3b5fe4011e69b9681e4c (patch)
tree47a84fde12843a97794d6be635bb7a2804949049 /src
parente71bbd90a8fb4b5de7796498aed4b95bb7abaebb (diff)
downloadhakyll-a6ae4eb99dd5f9957adc3b5fe4011e69b9681e4c.tar.gz
Fix root directory in directory-wise metadata and beautify code
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Core/Provider/Metadata.hs34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/Hakyll/Core/Provider/Metadata.hs b/src/Hakyll/Core/Provider/Metadata.hs
index fcc1d6c..8f39f22 100644
--- a/src/Hakyll/Core/Provider/Metadata.hs
+++ b/src/Hakyll/Core/Provider/Metadata.hs
@@ -142,26 +142,20 @@ page = do
--------------------------------------------------------------------------------
-- | Load directory-wise metadata
loadGlobalMetadata :: Provider -> FilePath -> IO (M.Map String String)
-loadGlobalMetadata p fp = do
- let dir = takeDirectory fp
- liftM M.fromList $ loadgm dir
- where
- loadgm :: FilePath -> IO [(String, String)]
- loadgm dir | dir == providerDirectory p = return []
- | otherwise = do
- let mfp = combine dir "metadata"
- md <- if M.member (fromFilePath mfp) (providerFiles p)
- then loadOne mfp dir
- else return []
- others <- loadgm (takeDirectory dir)
- return $ others ++ md
- loadOne mfp dir = do
- contents <- IO.readFile $ resourceFilePath p $ fromFilePath mfp
- return $ case P.parse namedMetadata mfp contents of
- Left err -> error (show err)
- Right mds -> findMetadata mds dir
- findMetadata mds dir =
- concatMap snd $ filter (flip matches (fromFilePath fp) . fromGlob . combine dir . fst) mds
+loadGlobalMetadata p fp = liftM M.fromList $ loadgm $ takeDirectory fp where
+ loadgm :: FilePath -> IO [(String, String)]
+ loadgm dir | dir == "." = return []
+ | otherwise = do
+ let mfp = fromFilePath $ combine dir "metadata"
+ md <- if resourceExists p mfp then loadOne mfp dir else return []
+ others <- loadgm (takeDirectory dir)
+ return $ others ++ md
+ loadOne mfp dir =
+ let path = resourceFilePath p mfp
+ -- TODO: It might be better to print warning and continue
+ in either (error.show) (findMetadata dir) . P.parse namedMetadata path <$> readFile path
+ findMetadata dir =
+ concatMap snd . filter (flip matches (fromFilePath fp) . fromGlob . combine dir . fst)
namedMetadata :: Parser [(String, [(String, String)])]
namedMetadata = P.many namedMetadataBlock