permalink now respects pretty urls
authorspf13 <steve.francia@gmail.com>
Fri, 26 Jul 2013 13:51:07 +0000 (09:51 -0400)
committerspf13 <steve.francia@gmail.com>
Fri, 26 Jul 2013 13:56:00 +0000 (09:56 -0400)
hugolib/page.go
hugolib/site.go

index 7887ca4883169d8922f25b812f4b1a4aec349a25..7541257d05e7f1fa72b47fc3da7ab89b6ada308b 100644 (file)
@@ -228,13 +228,22 @@ func splitPageContent(data []byte, start string, end string) ([]string, []string
 
 func (p *Page) Permalink() template.HTML {
        if len(strings.TrimSpace(p.Slug)) > 0 {
-               return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+p.Slug))
+               if p.Site.Config.UglyUrls {
+                       return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+p.Slug+"."+p.Extension))
+               } else {
+                       return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+p.Slug))
+               }
        } else if len(strings.TrimSpace(p.Url)) > 2 {
                return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Url)))
        } else {
                _, t := filepath.Split(p.FileName)
-               x := replaceExtension(strings.TrimSpace(t), p.Extension)
-               return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+x))
+               if p.Site.Config.UglyUrls {
+                       x := replaceExtension(strings.TrimSpace(t), p.Extension)
+                       return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+x))
+               } else {
+                       file, _ := fileExt(strings.TrimSpace(t))
+                       return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+file))
+               }
        }
 }
 
index 7066dfbf0b58887fae1a22eed6077f7d5f8dea8e..8d33b70082d62661f4199656d76b702d4fad05b9 100644 (file)
@@ -48,6 +48,7 @@ type SiteInfo struct {
        Recent     *Pages
        LastChange time.Time
        Title      string
+       Config     *Config
 }
 
 func (s *Site) getFromIndex(kind string, name string) Pages {
@@ -166,7 +167,7 @@ func (s *Site) initialize() {
 
        filepath.Walk(s.c.GetAbsPath(s.c.SourceDir), walker)
 
-       s.Info = SiteInfo{BaseUrl: template.URL(s.c.BaseUrl), Title: s.c.Title}
+       s.Info = SiteInfo{BaseUrl: template.URL(s.c.BaseUrl), Title: s.c.Title, Config: &s.c}
 
        s.Shortcodes = make(map[string]ShortcodeFunc)
 }