haskellhakyll

How to combine multiple Pattern for match?


I want to match files with extensions *.md and *.tex in posts directory.

The reason I can't use "posts/*" :: Pattern is because there are files *.tex.metadata in the posts directory. And site will give error on that files.

[ERROR] Hakyll.Web.readPandocWith: I don't know how to read a file of the type Binary for: posts/2017-06-02-tex.metadata

Try following code and fail with empty match (no html output).

match (fromList ["posts/*.md", "posts/*.tex"]) $ do
    route $ setExtension "html"
    compile $ pandocCompiler

let postFiles :: Pattern
    postFiles = fromGlob "posts/*.md" `mappend` fromGlob "posts/*.tex"

match postFiles $ do
    route $ setExtension "html"
    compile $ pandocCompiler

Maybe I should use fromRegex but I have no idea how to write regex for that.

Addition learning resource is very much welcome. The documentation is lack of sample.


Solution

  • Try

    let postFiles :: Pattern
        postFiles = fromGlob "posts/*.md" .||. fromGlob "posts/*.tex"
    
    match postFiles $ do
        route $ setExtension "html"
        compile $ pandocCompiler
    

    you can read "Composing patterns" from documentation what different functions there are to compose multiple Pattern values.

    pattern1 .||. pattern2 creates a pattern, that matches if pattern1 or pattern2 or both matches (this is what you want).

    pattern1 .&&. pattern2 creates a pattern that matches, if pattern1 and pattern2 match (you don't want this but it illustrates what can be done, too).