Skip to content

Instantly share code, notes, and snippets.

@mrvdb
Last active April 15, 2016 16:19
Show Gist options
  • Save mrvdb/613f6f66a4f3757dfe4daef61b899902 to your computer and use it in GitHub Desktop.
Save mrvdb/613f6f66a4f3757dfe4daef61b899902 to your computer and use it in GitHub Desktop.
-- Get the number of posts that satisfy a pattern
postCount :: Pattern -> Int
postCount pattern = do
-- something with getMatches sounds right
m' <- getMatches pattern -- getMatches :: MonadMetadata m => Pattern -> m [Identifier]
-- return $ length m' -- Inclined to do return here...
-- what do I put here?
-- Other relevant stuff:
-- https://jaspervdj.be/hakyll/reference/Hakyll-Core-Identifier-Pattern.html
postsPattern :: Pattern
postsPattern = "sites/main/_posts/2*.org"
-- From boomerang:
-- How do I use this then?
postCount' :: MonadMetadata m => Pattern -> m Int
postCount' pattern = length <$> getMatches pattern -- getMatches :: MonadMetadata m => Pattern -> m [Identifier]
@basile-henry
Copy link

Looking at the definition of MonadMetadata it looks like Compiler and Rules are instances of MonadMetadata. So you can call postCount' in a do statement in whatever function with type signature ... -> Rules a or ... -> Compiler a

Boomerang :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment