简体   繁体   English

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

[英]How to combine multiple Pattern for match?

I want to match files with extensions *.md and *.tex in posts directory. 我想在posts目录中匹配扩展名为*.md*.tex的文件。

The reason I can't use "posts/*" :: Pattern is because there are files *.tex.metadata in the posts directory. 我不能使用"posts/*" :: Pattern的原因是因为posts目录中有*.tex.metadata文件。 And site will give error on that files. site将在该文件上显示错误。

[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). 尝试下面的代码,但失败并显示为空(没有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

Maybe I should use fromRegex but I have no idea how to write regex for that. 也许我应该使用fromRegex但是我不知道如何为此编写正则表达式。

Addition learning resource is very much welcome. 非常欢迎添加学习资源。 The documentation is lack of sample. 文档缺少样本。

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. 您可以从文档中阅读“组成样式”,以了解组成多个Pattern值的不同功能。

pattern1 .||. pattern2 pattern1 .||. pattern2 creates a pattern, that matches if pattern1 or pattern2 or both matches (this is what you want). pattern1 .||. pattern2创建一个模式,如果pattern1pattern2或两者都匹配则匹配(这就是您想要的)。

pattern1 .&&. pattern2 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). 如果pattern1pattern2匹配, pattern1 .&&. pattern2创建一个匹配的模式(您不希望这样做,但是它也说明了可以做什么)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM