Ignore dotfiles in content directory

This supports my personal workflow of using vim which places a temporary file in the same directory as the file I'm editing.
This commit is contained in:
Noah Campbell 2013-08-12 16:10:38 -07:00
parent 5664780cca
commit 97eb9225a7
2 changed files with 36 additions and 2 deletions

View file

@ -0,0 +1,25 @@
package hugolib
import (
"testing"
)
func TestIgnoreDotFiles(t *testing.T) {
tests := []struct {
path string
ignore bool
} {
{"barfoo.md", false},
{"foobar/barfoo.md", false},
{"foobar/.barfoo.md", true},
{".barfoo.md", true},
{".md", true},
{"", true},
}
for _, test := range tests {
if ignored := ignoreDotFile(test.path); test.ignore != ignored {
t.Errorf("File not ignored. Expected: %t, got: %t", test.ignore, ignored)
}
}
}

View file

@ -106,7 +106,9 @@ func (site *Site) Render() (err error) {
site.timerStep("render shortcodes") site.timerStep("render shortcodes")
site.AbsUrlify() site.AbsUrlify()
site.timerStep("absolute URLify") site.timerStep("absolute URLify")
site.RenderIndexes() if err = site.RenderIndexes(); err != nil {
return
}
site.RenderIndexesIndexes() site.RenderIndexesIndexes()
site.timerStep("render and write indexes") site.timerStep("render and write indexes")
site.RenderLists() site.RenderLists()
@ -199,18 +201,25 @@ func (s *Site) initialize() {
site.Directories = append(site.Directories, path) site.Directories = append(site.Directories, path)
return nil return nil
} else { } else {
if ignoreDotFile(path) {
return nil
}
site.Files = append(site.Files, path) site.Files = append(site.Files, path)
return nil return nil
} }
} }
filepath.Walk(s.Config.GetAbsPath(s.Config.ContentDir), walker) filepath.Walk(s.absContentDir(), walker)
s.Info = SiteInfo{BaseUrl: template.URL(s.Config.BaseUrl), Title: s.Config.Title, Config: &s.Config} s.Info = SiteInfo{BaseUrl: template.URL(s.Config.BaseUrl), Title: s.Config.Title, Config: &s.Config}
s.Shortcodes = make(map[string]ShortcodeFunc) s.Shortcodes = make(map[string]ShortcodeFunc)
} }
func ignoreDotFile(path string) bool {
return filepath.Base(path)[0] == '.'
}
func (s *Site) absLayoutDir() string { func (s *Site) absLayoutDir() string {
return s.Config.GetAbsPath(s.Config.LayoutDir) return s.Config.GetAbsPath(s.Config.LayoutDir)
} }