Add configurable list to ignore files in server watch
authorbep <bjorn.erik.pedersen@gmail.com>
Wed, 3 Jun 2015 11:37:57 +0000 (13:37 +0200)
committerbep <bjorn.erik.pedersen@gmail.com>
Wed, 3 Jun 2015 11:38:05 +0000 (13:38 +0200)
The following inside `config.toml` will ignore files ending with `.foo` and `.boo`.

```
watchIgnoreFiles = [ "\\.foo$", "\\.boo$" ]
```

The above is is a list of Reqular Expressions, but note the escaping of the `\` to make TOML happy.

Fixes #1189

source/filesystem.go

index d30eea8da4ac8cbebaacc21ee2ebab725fdf7023..4565c7f48727d870073cbc89337abe0c4207b2b6 100644 (file)
@@ -15,10 +15,12 @@ package source
 
 import (
        "bytes"
+       "github.com/spf13/viper"
        "io"
        "io/ioutil"
        "os"
        "path/filepath"
+       "regexp"
        "strings"
 
        "github.com/spf13/hugo/helpers"
@@ -146,5 +148,14 @@ func isNonProcessablePath(filePath string) bool {
                return true
        }
 
+       ignoreFiles := viper.GetStringSlice("WatchIgnoreFiles")
+       if len(ignoreFiles) > 0 {
+               for _, ignorePattern := range ignoreFiles {
+                       match, _ := regexp.MatchString(ignorePattern, filePath)
+                       if match {
+                               return true
+                       }
+               }
+       }
        return false
 }