shithub: hugo

Download patch

ref: 8f330626bcbe3413b853dda98e17352af9067d44
parent: 0a79edd48aa46d800cc63ee61236ccad975fa532
parent: c713beba4d4ac00f17a28ab4aab10be1acadd0b1
author: spf13 <[email protected]>
date: Sat Aug 17 19:53:35 EDT 2013

Merge branch 'noahcampbell-index_reporting'

--- /dev/null
+++ b/hugolib/indexing_test.go
@@ -1,0 +1,16 @@
+package hugolib
+
+import (
+	"strings"
+	"testing"
+)
+
+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)
+	}
+}
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -28,8 +28,6 @@
 	//"sync"
 )
 
-const slash = string(os.PathSeparator)
-
 var DefaultTimer = nitro.Initalize()
 
 type Site struct {
@@ -110,9 +108,13 @@
 	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
@@ -324,9 +326,9 @@
 	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
@@ -335,7 +337,7 @@
 			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)
 		}
 	}
 
@@ -386,6 +388,26 @@
 	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 {
@@ -428,7 +450,7 @@
 		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"
@@ -441,7 +463,7 @@
 			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
@@ -474,7 +496,7 @@
 }
 
 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()
@@ -488,7 +510,7 @@
 			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
 		}
 	}
@@ -504,13 +526,13 @@
 		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
@@ -522,7 +544,7 @@
 			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
@@ -563,7 +585,7 @@
 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)
 	}
 }