permalink now respects pretty urls

This commit is contained in:
spf13 2013-07-26 09:51:07 -04:00
parent d5f5543061
commit 92c31bbe10
2 changed files with 14 additions and 4 deletions

View file

@ -228,13 +228,22 @@ func splitPageContent(data []byte, start string, end string) ([]string, []string
func (p *Page) Permalink() template.HTML { func (p *Page) Permalink() template.HTML {
if len(strings.TrimSpace(p.Slug)) > 0 { if len(strings.TrimSpace(p.Slug)) > 0 {
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)) return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+p.Slug))
}
} else if len(strings.TrimSpace(p.Url)) > 2 { } else if len(strings.TrimSpace(p.Url)) > 2 {
return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Url))) return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Url)))
} else { } else {
_, t := filepath.Split(p.FileName) _, t := filepath.Split(p.FileName)
if p.Site.Config.UglyUrls {
x := replaceExtension(strings.TrimSpace(t), p.Extension) x := replaceExtension(strings.TrimSpace(t), p.Extension)
return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+x)) 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))
}
} }
} }

View file

@ -48,6 +48,7 @@ type SiteInfo struct {
Recent *Pages Recent *Pages
LastChange time.Time LastChange time.Time
Title string Title string
Config *Config
} }
func (s *Site) getFromIndex(kind string, name string) Pages { 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) 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) s.Shortcodes = make(map[string]ShortcodeFunc)
} }