Skip to content

Instantly share code, notes, and snippets.

@aforemny
Created January 27, 2013 18:49
Show Gist options
  • Select an option

  • Save aforemny/4649730 to your computer and use it in GitHub Desktop.

Select an option

Save aforemny/4649730 to your computer and use it in GitHub Desktop.
Extract the first paragraph of body after pandocCompiler processed the input.
match "posts/*" $ do
route $ setExtension ".html"
compile $ pandocCompiler >>= saveSnapshot "content" >>= ...
postCtx = mconcat
[ Context $ \k i ->
if k == "teaser" then do
i' <- loadSnapshot (itemIdentifier i) "content"
return $ fromMaybe "" $ safeHead $ lines $ itemBody i'
else
fail "obscure error"
]
@jaspervdj

Copy link
Copy Markdown

Use

field :: String -> (Item a -> Compiler String) -> Context a

E.g.

postCtx = mconcat
    [ field "teaser" $ \i -> do
        i' <- loadSnapshot (itemIdentifier i) "content"
        return $ fromMaybe "" $ safeHead $ lines $ itemBody i'
    ]

The mconcat is also unnecessary in this case, you can just have:

postCtx = field "teaser" $ \i -> do
    i' <- loadSnapshot (itemIdentifier i) "content"
    return $ fromMaybe "" $ safeHead $ lines $ itemBody i'

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