diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2014-03-26 11:30:23 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2014-03-26 12:05:38 +0100 |
commit | bc1cfc8d5a8baeb4bc21b992e310ee79fdb38c0f (patch) | |
tree | b540079bf3c60a6897541d4d27d334a18f0f6d20 /src | |
parent | 6552dd5bc01e122d550e9ce664646a4c719145f7 (diff) | |
download | hakyll-bc1cfc8d5a8baeb4bc21b992e310ee79fdb38c0f.tar.gz |
Revert "Fix root directory in directory-wise metadata and beautify code"
This reverts commit a6ae4eb99dd5f9957adc3b5fe4011e69b9681e4c.
Diffstat (limited to 'src')
-rw-r--r-- | src/Hakyll/Core/Provider/Metadata.hs | 34 |
1 files changed, 20 insertions, 14 deletions
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 |