mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Don't process dotfiles
This commit makes it so that not only files but also folders which start with a dot are ignored. Fixes #239
This commit is contained in:
parent
5581e33a34
commit
f271faea06
2 changed files with 7 additions and 5 deletions
|
@ -4,11 +4,13 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIgnoreDotFiles(t *testing.T) {
|
func TestIgnoreDotFilesAndDirectories(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
path string
|
path string
|
||||||
ignore bool
|
ignore bool
|
||||||
}{
|
}{
|
||||||
|
{".foobar/", true },
|
||||||
|
{"foobar/.barfoo/", true },
|
||||||
{"barfoo.md", false},
|
{"barfoo.md", false},
|
||||||
{"foobar/barfoo.md", false},
|
{"foobar/barfoo.md", false},
|
||||||
{"foobar/.barfoo.md", true},
|
{"foobar/.barfoo.md", true},
|
||||||
|
@ -22,7 +24,7 @@ func TestIgnoreDotFiles(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if ignored := ignoreDotFile(test.path); test.ignore != ignored {
|
if ignored := isNonProcessablePath(test.path); test.ignore != ignored {
|
||||||
t.Errorf("File not ignored. Expected: %t, got: %t", test.ignore, ignored)
|
t.Errorf("File not ignored. Expected: %t, got: %t", test.ignore, ignored)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,12 +87,12 @@ func (f *Filesystem) captureFiles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
if f.avoid(filePath) {
|
if f.avoid(filePath) || isNonProcessablePath(filePath) {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
if ignoreDotFile(filePath) {
|
if isNonProcessablePath(filePath) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(filePath)
|
data, err := ioutil.ReadFile(filePath)
|
||||||
|
@ -116,7 +116,7 @@ func (f *Filesystem) avoid(filePath string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func ignoreDotFile(filePath string) bool {
|
func isNonProcessablePath(filePath string) bool {
|
||||||
base := filepath.Base(filePath)
|
base := filepath.Base(filePath)
|
||||||
if base[0] == '.' {
|
if base[0] == '.' {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue