@@ -44,7 +44,7 @@ loadMetadata p identifier = do
4444 Nothing -> return M.empty
4545 Just mi' -> loadMetadataFile $ resourceFilePath p mi'
4646
47− gmd <- loadGlobalMetadata p $ toFilePath identifier
47+ gmd <- loadGlobalMetadata p identifier
4848
4949 return (M.unions [md, emd, gmd], body)
5050 where
@@ -141,21 +141,17 @@ page = do
141141
142142--------------------------------------------------------------------------------
143143-- | Load directory-wise metadata
144−loadGlobalMetadata :: Provider -> FilePath -> IO (M.Map String String)
145−loadGlobalMetadata p fp = liftM M.fromList $ loadgm $ takeDirectory fp where
146− loadgm :: FilePath -> IO [(String, String)]
147− loadgm dir | dir == "." = return []
148− | otherwise = do
149− let mfp = fromFilePath $ combine dir "metadata"
150− md <- if resourceExists p mfp then loadOne mfp dir else return []
151− others <- loadgm (takeDirectory dir)
152− return $ others ++ md
153− loadOne mfp dir =
144+loadGlobalMetadata :: Provider -> Identifier -> IO Metadata
145+loadGlobalMetadata p fp = liftM M.fromList $ loadgm fp where
146+ loadgm :: Identifier -> IO [(String, String)]
147+ loadgm = liftM concat . mapM loadOne . reverse . filter (resourceExists p) . metadataFiles
148+ loadOne mfp =
154149 let path = resourceFilePath p mfp
150+ dir = takeDirectory $ toFilePath mfp
155151 -- TODO: It might be better to print warning and continue
156152 in either (error.show) (findMetadata dir) . P.parse namedMetadata path <$> readFile path
157153 findMetadata dir =
158− concatMap snd . filter (flip matches (fromFilePath fp) . fromGlob . combine dir . fst)
154+ concatMap snd . filter (flip matches fp . fromGlob . combine dir . fst)
159155
160156namedMetadata :: Parser [(String, [(String, String)])]
161157namedMetadata = P.many namedMetadataBlock