如何组合多个模式进行匹配?

时间:2017-06-02 09:20:14

标签: haskell hakyll

我想在*.md目录中匹配扩展名为*.texposts的文件。

我无法使用"posts/*" :: Pattern的原因是因为posts目录中有文件*.tex.metadatasite会对这些文件造成错误。

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

尝试使用以下代码并使用空匹配失败(无html输出)。

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

也许我应该使用fromRegex,但我不知道如何为此编写正则表达式。

非常欢迎加入学习资源。 documentation缺少样本。

1 个答案:

答案 0 :(得分:1)

尝试

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

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

您可以阅读documentation中的“撰写模式” 有哪些不同的函数可以组成多个Pattern值。

pattern1 .||. pattern2创建一个模式,匹配pattern1pattern2或两者匹配(这是您想要的)。

如果pattern1 .&&. pattern2pattern1匹配,则

pattern2会创建匹配的模式(您不希望这样,但它也说明了可以执行的操作)。

相关问题