on master help sign in
Unified code for global and external metadata

Didn't clean up unused code though

commitdbabe0325b9d7bca3b14c2b33e686b8151fa79aa authorAlexey Kreshchuk <akrsch@gmail.com> dateWed 22 Jan 2014, 00:11 (13 years ago) parentd406db4
4 files changed+12−6
src/Hakyll/Core/Metadata.hs+2−1 src/Hakyll/Core/Provider/Metadata.hs+7−5 src/Hakyll/Core/Rules/Default.hs+1 tests/data/posts/metadata+2
src/Hakyll/Core/Metadata.hs+2−1
@@ -67,7 +67,8 @@ makePatternDependency pattern = do
6767--------------------------------------------------------------------------------
6868-- | Returns a list of all directory-wise metadata files, subdir first, global last
6969metadataFiles :: Identifier -> [Identifier]
70−metadataFiles = go . takeDirectory . toFilePath where
70+metadataFiles identifier = local : go (takeDirectory $ toFilePath identifier) where
7171 go "." = [fromFilePath "metadata"]
7272 go dir = fromFilePath (dir </> "metadata") : go (takeDirectory dir)
73+ local = fromFilePath $ toFilePath identifier ++ ".metadata"
7374
src/Hakyll/Core/Provider/Metadata.hs+7−5
@@ -46,7 +46,7 @@ loadMetadata p identifier = do
4646
4747 gmd <- loadGlobalMetadata p identifier
4848
49− return (M.unions [md, emd, gmd], body)
49+ return (M.unions [md, gmd], body)
5050 where
5151 normal = setVersion Nothing identifier
5252 fp = resourceFilePath p identifier
@@ -154,11 +154,13 @@ loadGlobalMetadata p fp = liftM M.fromList $ loadgm fp where
154154 concatMap snd . filter (flip matches fp . fromGlob . normalise . combine dir . fst)
155155
156156namedMetadata :: Parser [(String, [(String, String)])]
157−namedMetadata = P.many namedMetadataBlock
157+namedMetadata = liftA2 (:) (namedMetadataBlock False) $ P.many $ namedMetadataBlock True
158158
159−namedMetadataBlock :: Parser (String, [(String, String)])
160−namedMetadataBlock = do
161− name <- P.many1 (P.char '-') *> P.many inlineSpace *> P.manyTill P.anyChar newline
159+namedMetadataBlock :: Bool -> Parser (String, [(String, String)])
160+namedMetadataBlock isNamed = do
161+ name <- if isNamed
162+ then P.many1 (P.char '-') *> P.many inlineSpace *> P.manyTill P.anyChar newline
163+ else pure "**"
162164 metadata' <- metadata
163165 P.skipMany P.space
164166 return (name, metadata')
src/Hakyll/Core/Rules/Default.hs+1
@@ -14,6 +14,7 @@ internalRules :: Rules ()
1414internalRules = do
1515 match "metadata" $ compile $ makeItem ()
1616 match "**/metadata" $ compile $ makeItem ()
17+ match "**.metadata" $ compile $ makeItem ()
1718
1819--------------------------------------------------------------------------------
1920addMetadataDependencies :: Compiler ()
tests/data/posts/metadata+2
@@ -16,3 +16,5 @@ a1: 3
1616a2: 3
1717a3: 3
1818
19+--- nonexistent
20+a3: 0