shithub: hugo

Download patch

ref: 06da609138475de317e7e5fbf3a0a8c3af3c64e4
parent: 6fa6f69a4a2ae3f1b278349bb78b565b4e4851ba
author: Noah Campbell <[email protected]>
date: Wed Oct 2 15:33:51 EDT 2013

Refactor Permalink to private function

This will allow for reuse of this particular function.

--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -207,7 +207,7 @@
 	p.FuzzyWordCount = int((p.WordCount+100)/100) * 100
 }
 
-func (p *Page) Permalink() (string, error) {
+func (p *Page) permalink() (*url.URL, error) {
 	baseUrl := string(p.Site.BaseUrl)
 	section := strings.TrimSpace(p.Section)
 	pSlug := strings.TrimSpace(p.Slug)
@@ -223,7 +223,7 @@
 		permalink = pUrl
 	} else {
 		_, t := path.Split(p.FileName)
-		if p.Site.Config.UglyUrls {
+		if p.Site.Config != nil && p.Site.Config.UglyUrls {
 			x := replaceExtension(strings.TrimSpace(t), p.Extension)
 			permalink = section + "/" + x
 		} else {
@@ -234,15 +234,23 @@
 
 	base, err := url.Parse(baseUrl)
 	if err != nil {
-		return "", err
+		return nil, err
 	}
 
 	path, err := url.Parse(permalink)
 	if err != nil {
-		return "", err
+		return nil, err
 	}
 
-	return MakePermalink(base, path).String(), nil
+	return MakePermalink(base, path), nil
+}
+
+func (p *Page) Permalink() (string, error) {
+	link, err := p.permalink()
+	if err != nil {
+		return "", err
+	}
+	return link.String(), nil
 }
 
 func (page *Page) handleTomlMetaData(datum []byte) (interface{}, error) {
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -551,14 +551,14 @@
 	section := ""
 	page, ok := d.(*Page)
 	if ok {
-		section = page.Section
+		section, _ = page.Permalink()
 	}
 
 	fmt.Println("Section is:", section)
 
 	transformer := transform.NewChain(
-		&transform.NavActive{Section: section},
 		&transform.AbsURL{BaseURL: s.Config.BaseUrl},
+		&transform.NavActive{Section: section},
 	)
 
 	renderReader, renderWriter := io.Pipe()