From e66ba5d2a7dd1a043a24bf86a271a5440b7b1385 Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Tue, 13 Aug 2013 10:44:40 -0700 Subject: [PATCH 1/4] Return errors when rendering --- hugolib/site.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hugolib/site.go b/hugolib/site.go index c0bce9f06..966208f92 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -110,9 +110,13 @@ func (site *Site) Render() (err error) { if err = site.RenderIndexes(); err != nil { return } - site.RenderIndexesIndexes() + if err = site.RenderIndexesIndexes(); err != nil { + return + } site.timerStep("render and write indexes") - site.RenderLists() + if err = site.RenderLists(); err != nil { + return + } site.timerStep("render and write lists") if err = site.RenderPages(); err != nil { return From 8eca8f8aa08d5d95386c34979f653a5b5463c8c9 Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Tue, 13 Aug 2013 10:46:05 -0700 Subject: [PATCH 2/4] Detect missed index from front matter --- hugolib/indexing_test.go | 18 ++++++++++++++++++ hugolib/site.go | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 hugolib/indexing_test.go diff --git a/hugolib/indexing_test.go b/hugolib/indexing_test.go new file mode 100644 index 000000000..4d7d04f31 --- /dev/null +++ b/hugolib/indexing_test.go @@ -0,0 +1,18 @@ +package hugolib + +import ( + "testing" + "strings" +) + +func TestSitePossibleIndexes(t *testing.T) { + site := new(Site) + page, _ := ReadFrom(strings.NewReader(PAGE_YAML_WITH_INDEXES_A), "path/to/page") + site.Pages = append(site.Pages, page) + indexes := site.possibleIndexes() + if !compareStringSlice(indexes, []string{"tags", "categories"}) { + t.Fatalf("possible indexes do not match [tags categories]. Got: %s", indexes) + } +} + + diff --git a/hugolib/site.go b/hugolib/site.go index 966208f92..5011cf6b2 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -390,6 +390,26 @@ func (s *Site) BuildSiteMeta() (err error) { return } +func (s *Site) possibleIndexes() (indexes []string) { + for _, p := range s.Pages { + for k, _ := range p.Params { + if !inStringArray(indexes, k) { + indexes = append(indexes, k) + } + } + } + return +} + +func inStringArray(arr []string, el string) bool { + for _, v := range arr { + if v == el { + return true + } + } + return false +} + func (s *Site) RenderAliases() error { for i, p := range s.Pages { for _, a := range p.Aliases { From ec821739bc31e2decb568bec1153a871a82a1cc7 Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Tue, 13 Aug 2013 14:47:14 -0700 Subject: [PATCH 3/4] Removing the use of slash An oversight on my behalf. The FromSlash method is used when writing out the public file name. There is one place where the slashes are required which is setting the output file. I replaced those instances with filepath.Join which should do the right thing depending on the OS. --- hugolib/site.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hugolib/site.go b/hugolib/site.go index 5011cf6b2..a35300d21 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -28,8 +28,6 @@ import ( //"sync" ) -const slash = string(os.PathSeparator) - var DefaultTimer = nitro.Initalize() type Site struct { @@ -452,7 +450,7 @@ func (s *Site) RenderIndexes() error { for k, o := range s.Indexes[plural] { n := s.NewNode() n.Title = strings.Title(k) - url := Urlize(plural + slash + k) + url := Urlize(plural + "/" + k) plink := url if s.Config.UglyUrls { n.Url = url + ".html" @@ -465,7 +463,7 @@ func (s *Site) RenderIndexes() error { n.Date = o[0].Date n.Data[singular] = o n.Data["Pages"] = o - layout := "indexes" + slash + singular + ".html" + layout := "indexes/" + singular + ".html" x, err := s.RenderThing(n, layout) if err != nil { return err @@ -498,7 +496,7 @@ func (s *Site) RenderIndexes() error { } func (s *Site) RenderIndexesIndexes() (err error) { - layout := "indexes" + slash + "indexes.html" + layout := "indexes/indexes.html" if s.Tmpl.Lookup(layout) != nil { for singular, plural := range s.Config.Indexes { n := s.NewNode() @@ -512,7 +510,7 @@ func (s *Site) RenderIndexesIndexes() (err error) { n.Data["OrderedIndex"] = s.Info.Indexes[plural] x, err := s.RenderThing(n, layout) - s.WritePublic(plural+slash+"index.html", x.Bytes()) + s.WritePublic(plural+"/index.html", x.Bytes()) return err } } @@ -528,13 +526,13 @@ func (s *Site) RenderLists() error { n.RSSlink = template.HTML(MakePermalink(string(n.Site.BaseUrl), string(section+".xml"))) n.Date = data[0].Date n.Data["Pages"] = data - layout := "indexes" + slash + section + ".html" + layout := "indexes/" + section + ".html" x, err := s.RenderThing(n, layout) if err != nil { return err } - s.WritePublic(section+slash+"index.html", x.Bytes()) + s.WritePublic(section+"/index.html", x.Bytes()) if a := s.Tmpl.Lookup("rss.xml"); a != nil { // XML Feed @@ -546,7 +544,7 @@ func (s *Site) RenderLists() error { n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url) y := s.NewXMLBuffer() s.Tmpl.ExecuteTemplate(y, "rss.xml", n) - s.WritePublic(section+slash+"index.xml", y.Bytes()) + s.WritePublic(section+"/index.xml", y.Bytes()) } } return nil @@ -587,7 +585,7 @@ func (s *Site) RenderHomePage() error { func (s *Site) Stats() { fmt.Printf("%d pages created \n", len(s.Pages)) for _, pl := range s.Config.Indexes { - fmt.Printf("%d %s created\n", len(s.Indexes[pl]), pl) + fmt.Printf("%d %s index created\n", len(s.Indexes[pl]), pl) } } From c713beba4d4ac00f17a28ab4aab10be1acadd0b1 Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Tue, 13 Aug 2013 14:58:50 -0700 Subject: [PATCH 4/4] Formatting cleanup --- hugolib/indexing_test.go | 4 +--- hugolib/site.go | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/hugolib/indexing_test.go b/hugolib/indexing_test.go index 4d7d04f31..8bf74188b 100644 --- a/hugolib/indexing_test.go +++ b/hugolib/indexing_test.go @@ -1,8 +1,8 @@ package hugolib import ( - "testing" "strings" + "testing" ) func TestSitePossibleIndexes(t *testing.T) { @@ -14,5 +14,3 @@ func TestSitePossibleIndexes(t *testing.T) { t.Fatalf("possible indexes do not match [tags categories]. Got: %s", indexes) } } - - diff --git a/hugolib/site.go b/hugolib/site.go index a35300d21..c9104564a 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -326,9 +326,9 @@ func (s *Site) setOutFile(p *Page) { if len(strings.TrimSpace(p.Slug)) > 0 { // Use Slug if provided if s.Config.UglyUrls { - outfile = p.Slug + "." + p.Extension + outfile = strings.TrimSpace(p.Slug) + "." + p.Extension } else { - outfile = p.Slug + slash + "index." + p.Extension + outfile = filepath.Join(strings.TrimSpace(p.Slug), "index."+p.Extension) } } else { // Fall back to filename @@ -337,7 +337,7 @@ func (s *Site) setOutFile(p *Page) { outfile = replaceExtension(strings.TrimSpace(t), p.Extension) } else { file, _ := fileExt(strings.TrimSpace(t)) - outfile = file + slash + "index." + p.Extension + outfile = filepath.Join(file, "index."+p.Extension) } }