shithub: hugo

Download patch

ref: 97eb9225a72fd08f671e5000bbc4c94cf6b78d7e
parent: 5664780ccabc5c1f7113ae305fe89074fd7a0afb
author: Noah Campbell <[email protected]>
date: Mon Aug 12 12:10:38 EDT 2013

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.

--- /dev/null
+++ b/hugolib/content_directory_test.go
@@ -1,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)
+		}
+	}
+}
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -106,7 +106,9 @@
 	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,16 +201,23 @@
 			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 {