proper BaseUrl handling (if has trailing slash or not)

This commit is contained in:
spf13 2013-07-11 22:55:07 -04:00
parent 7a521ad1a1
commit 649560fca2
2 changed files with 14 additions and 8 deletions

View file

@ -22,6 +22,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"strings"
) )
// config file items // config file items
@ -65,6 +66,11 @@ func SetupConfig(cfgfile *string, path *string) *Config {
c.Indexes["tag"] = "tags" c.Indexes["tag"] = "tags"
c.Indexes["category"] = "categories" c.Indexes["category"] = "categories"
} }
if !strings.HasSuffix(c.BaseUrl, "/") {
c.BaseUrl = c.BaseUrl + "/"
}
return &c return &c
} }

View file

@ -188,10 +188,10 @@ func (s *Site) ProcessShortcodes() {
func (s *Site) AbsUrlify() { func (s *Site) AbsUrlify() {
for i, _ := range s.Pages { for i, _ := range s.Pages {
content := string(s.Pages[i].Content) content := string(s.Pages[i].Content)
content = strings.Replace(content, " src=\"/", " src=\""+s.c.BaseUrl+"/", -1) content = strings.Replace(content, " src=\"/", " src=\""+s.c.BaseUrl, -1)
content = strings.Replace(content, " src='/", " src='"+s.c.BaseUrl+"/", -1) content = strings.Replace(content, " src='/", " src='"+s.c.BaseUrl, -1)
content = strings.Replace(content, " href='/", " href='"+s.c.BaseUrl+"/", -1) content = strings.Replace(content, " href='/", " href='"+s.c.BaseUrl, -1)
content = strings.Replace(content, " href=\"/", " href=\""+s.c.BaseUrl+"/", -1) content = strings.Replace(content, " href=\"/", " href=\""+s.c.BaseUrl, -1)
s.Pages[i].Content = template.HTML(content) s.Pages[i].Content = template.HTML(content)
} }
} }
@ -276,7 +276,7 @@ func (s *Site) RenderIndexes() {
// XML Feed // XML Feed
y := s.NewXMLBuffer() y := s.NewXMLBuffer()
n.Url = Urlize(plural + "/" + k + ".xml") n.Url = Urlize(plural + "/" + k + ".xml")
n.Permalink = template.HTML(string(n.Site.BaseUrl) + "/" + plural + "/" + k + ".xml") n.Permalink = template.HTML(string(n.Site.BaseUrl) + plural + "/" + k + ".xml")
s.Tmpl.ExecuteTemplate(y, "rss.xml", n) s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
s.WritePublic(plural, k+".xml", y.Bytes()) s.WritePublic(plural, k+".xml", y.Bytes())
} }
@ -301,7 +301,7 @@ func (s *Site) RenderLists() {
if a := s.Tmpl.Lookup("rss.xml"); a != nil { if a := s.Tmpl.Lookup("rss.xml"); a != nil {
// XML Feed // XML Feed
n.Url = Urlize(section + "/index.xml") n.Url = Urlize(section + "/index.xml")
n.Permalink = template.HTML(string(n.Site.BaseUrl) + "/" + section + "/index.xml") n.Permalink = template.HTML(string(n.Site.BaseUrl) + section + "/index.xml")
y := s.NewXMLBuffer() y := s.NewXMLBuffer()
s.Tmpl.ExecuteTemplate(y, "rss.xml", n) s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
s.WritePublic(section, "index.xml", y.Bytes()) s.WritePublic(section, "index.xml", y.Bytes())
@ -313,7 +313,7 @@ func (s *Site) RenderHomePage() {
n := s.NewNode() n := s.NewNode()
n.Title = n.Site.Title n.Title = n.Site.Title
n.Url = Urlize(string(n.Site.BaseUrl)) n.Url = Urlize(string(n.Site.BaseUrl))
n.RSSlink = template.HTML(MakePermalink(string(n.Site.BaseUrl), string("/index.xml"))) n.RSSlink = template.HTML(MakePermalink(string(n.Site.BaseUrl), string("index.xml")))
n.Permalink = template.HTML(string(n.Site.BaseUrl)) n.Permalink = template.HTML(string(n.Site.BaseUrl))
n.Date = s.Pages[0].Date n.Date = s.Pages[0].Date
if len(s.Pages) < 9 { if len(s.Pages) < 9 {
@ -328,7 +328,7 @@ func (s *Site) RenderHomePage() {
// XML Feed // XML Feed
n.Url = Urlize("index.xml") n.Url = Urlize("index.xml")
n.Title = "Recent Content" n.Title = "Recent Content"
n.Permalink = template.HTML(string(n.Site.BaseUrl) + "/index.xml") n.Permalink = template.HTML(string(n.Site.BaseUrl) + "index.xml")
y := s.NewXMLBuffer() y := s.NewXMLBuffer()
s.Tmpl.ExecuteTemplate(y, "rss.xml", n) s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
s.WritePublic("", "index.xml", y.Bytes()) s.WritePublic("", "index.xml", y.Bytes())