mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02:00
proper BaseUrl handling (if has trailing slash or not)
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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())
|
||||||
|
Reference in New Issue
Block a user