Refactor Permalink to private function

This will allow for reuse of this particular function.
This commit is contained in:
Noah Campbell 2013-10-02 19:33:51 -04:00
parent 6fa6f69a4a
commit 06da609138
2 changed files with 15 additions and 7 deletions

View file

@ -207,7 +207,7 @@ func (p *Page) analyzePage() {
p.FuzzyWordCount = int((p.WordCount+100)/100) * 100 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) baseUrl := string(p.Site.BaseUrl)
section := strings.TrimSpace(p.Section) section := strings.TrimSpace(p.Section)
pSlug := strings.TrimSpace(p.Slug) pSlug := strings.TrimSpace(p.Slug)
@ -223,7 +223,7 @@ func (p *Page) Permalink() (string, error) {
permalink = pUrl permalink = pUrl
} else { } else {
_, t := path.Split(p.FileName) _, 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) x := replaceExtension(strings.TrimSpace(t), p.Extension)
permalink = section + "/" + x permalink = section + "/" + x
} else { } else {
@ -234,15 +234,23 @@ func (p *Page) Permalink() (string, error) {
base, err := url.Parse(baseUrl) base, err := url.Parse(baseUrl)
if err != nil { if err != nil {
return "", err return nil, err
} }
path, err := url.Parse(permalink) path, err := url.Parse(permalink)
if err != nil { 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) { func (page *Page) handleTomlMetaData(datum []byte) (interface{}, error) {

View file

@ -551,14 +551,14 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
section := "" section := ""
page, ok := d.(*Page) page, ok := d.(*Page)
if ok { if ok {
section = page.Section section, _ = page.Permalink()
} }
fmt.Println("Section is:", section) fmt.Println("Section is:", section)
transformer := transform.NewChain( transformer := transform.NewChain(
&transform.NavActive{Section: section},
&transform.AbsURL{BaseURL: s.Config.BaseUrl}, &transform.AbsURL{BaseURL: s.Config.BaseUrl},
&transform.NavActive{Section: section},
) )
renderReader, renderWriter := io.Pipe() renderReader, renderWriter := io.Pipe()