From 5664780ccabc5c1f7113ae305fe89074fd7a0afb Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Mon, 12 Aug 2013 20:38:37 -0700 Subject: [PATCH 1/2] gofmt pass Clean up test files. --- hugolib/path_seperators_test.go | 8 +++----- hugolib/path_seperators_windows_test.go | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/hugolib/path_seperators_test.go b/hugolib/path_seperators_test.go index f13eea1ef..9e112f82d 100644 --- a/hugolib/path_seperators_test.go +++ b/hugolib/path_seperators_test.go @@ -23,10 +23,10 @@ func TestDegenerateMissingFolderInPageFilename(t *testing.T) { } func TestNewPageWithFilePath(t *testing.T) { - toCheck := []struct{ - input string + toCheck := []struct { + input string section string - layout string + layout string }{ {filepath.Join("sub", "foobar.html"), "sub", "sub/single.html"}, {filepath.Join("content", "sub", "foobar.html"), "sub", "sub/single.html"}, @@ -47,5 +47,3 @@ func TestNewPageWithFilePath(t *testing.T) { } } } - - diff --git a/hugolib/path_seperators_windows_test.go b/hugolib/path_seperators_windows_test.go index 85b97222b..c6df7f61e 100644 --- a/hugolib/path_seperators_windows_test.go +++ b/hugolib/path_seperators_windows_test.go @@ -7,7 +7,7 @@ import ( func TestTemplatePathSeperator(t *testing.T) { config := Config{ LayoutDir: "c:\\a\\windows\\path\\layout", - Path: "c:\\a\\windows\\path", + Path: "c:\\a\\windows\\path", } s := &Site{Config: config} if name := s.generateTemplateNameFrom("c:\\a\\windows\\path\\layout\\sub1\\index.html"); name != "sub1/index.html" { From 97eb9225a72fd08f671e5000bbc4c94cf6b78d7e Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Mon, 12 Aug 2013 16:10:38 -0700 Subject: [PATCH 2/2] 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. --- hugolib/content_directory_test.go | 25 +++++++++++++++++++++++++ hugolib/site.go | 13 +++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 hugolib/content_directory_test.go diff --git a/hugolib/content_directory_test.go b/hugolib/content_directory_test.go new file mode 100644 index 000000000..8b8d7c4f6 --- /dev/null +++ b/hugolib/content_directory_test.go @@ -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) + } + } +} diff --git a/hugolib/site.go b/hugolib/site.go index 105034878..a16fec3fc 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -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) }