Ignore dotfiles in content directory
authorNoah Campbell <noahcampbell@gmail.com>
Mon, 12 Aug 2013 23:10:38 +0000 (16:10 -0700)
committerNoah Campbell <noahcampbell@gmail.com>
Tue, 13 Aug 2013 03:40:52 +0000 (20:40 -0700)
This supports my personal workflow of using vim which places a temporary file in the same directory as the file I'm editing.

hugolib/content_directory_test.go [new file with mode: 0644]
hugolib/site.go

diff --git a/hugolib/content_directory_test.go b/hugolib/content_directory_test.go
new file mode 100644 (file)
index 0000000..8b8d7c4
--- /dev/null
@@ -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)
+               }
+       }
+}
index 10503487806ad06f19886cc60839cd901fb77845..a16fec3fc2125f7b86e51524f8c0290b26ed3aa6 100644 (file)
@@ -106,7 +106,9 @@ func (site *Site) Render() (err error) {
        site.timerStep("render shortcodes")
        site.AbsUrlify()
        site.timerStep("absolute URLify")
-       site.RenderIndexes()
+       if err = site.RenderIndexes(); err != nil {
+               return
+       }
        site.RenderIndexesIndexes()
        site.timerStep("render and write indexes")
        site.RenderLists()
@@ -199,18 +201,25 @@ func (s *Site) initialize() {
                        site.Directories = append(site.Directories, path)
                        return nil
                } else {
+                       if ignoreDotFile(path) {
+                               return nil
+                       }
                        site.Files = append(site.Files, path)
                        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.Shortcodes = make(map[string]ShortcodeFunc)
 }
 
+func ignoreDotFile(path string) bool {
+       return filepath.Base(path)[0] == '.'
+}
+
 func (s *Site) absLayoutDir() string {
        return s.Config.GetAbsPath(s.Config.LayoutDir)
 }