From bc1cfc8d5a8baeb4bc21b992e310ee79fdb38c0f Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Wed, 26 Mar 2014 11:30:23 +0100 Subject: Revert "Fix root directory in directory-wise metadata and beautify code" This reverts commit a6ae4eb99dd5f9957adc3b5fe4011e69b9681e4c. --- src/Hakyll/Core/Provider/Metadata.hs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Hakyll/Core/Provider/Metadata.hs b/src/Hakyll/Core/Provider/Metadata.hs index 0101d25..8af3757 100644 --- a/src/Hakyll/Core/Provider/Metadata.hs +++ b/src/Hakyll/Core/Provider/Metadata.hs @@ -142,20 +142,26 @@ page = do -------------------------------------------------------------------------------- -- | Load directory-wise metadata loadGlobalMetadata :: Provider -> FilePath -> IO (M.Map String String) -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) +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 namedMetadata :: Parser [(String, [(String, String)])] namedMetadata = liftA2 (:) (namedMetadataBlock False) $ P.many $ namedMetadataBlock True -- cgit v1.2.3