shithub: hugo

Download patch

ref: 649560fca2bcbe7edb48f67404fb4cfe76274d36
parent: 7a521ad1a1ac956dc638f1934509220760f9171f
author: spf13 <[email protected]>
date: Thu Jul 11 18:55:07 EDT 2013

proper BaseUrl handling (if has trailing slash or not)

--- a/hugolib/config.go
+++ b/hugolib/config.go
@@ -22,6 +22,7 @@
 	"os"
 	"path"
 	"path/filepath"
+	"strings"
 )
 
 // config file items
@@ -65,6 +66,11 @@
 		c.Indexes["tag"] = "tags"
 		c.Indexes["category"] = "categories"
 	}
+
+    if !strings.HasSuffix(c.BaseUrl, "/") {
+        c.BaseUrl = c.BaseUrl + "/"
+    }
+
 	return &c
 }
 
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -188,10 +188,10 @@
 func (s *Site) AbsUrlify() {
 	for i, _ := range s.Pages {
 		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, " href='/", " href='"+s.c.BaseUrl+"/", -1)
-		content = strings.Replace(content, " href=\"/", " href=\""+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)
 		s.Pages[i].Content = template.HTML(content)
 	}
 }
@@ -276,7 +276,7 @@
 				// XML Feed
 				y := s.NewXMLBuffer()
 				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.WritePublic(plural, k+".xml", y.Bytes())
 			}
@@ -301,7 +301,7 @@
 		if a := s.Tmpl.Lookup("rss.xml"); a != nil {
 			// XML Feed
 			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()
 			s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
 			s.WritePublic(section, "index.xml", y.Bytes())
@@ -313,7 +313,7 @@
 	n := s.NewNode()
 	n.Title = n.Site.Title
 	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.Date = s.Pages[0].Date
 	if len(s.Pages) < 9 {
@@ -328,7 +328,7 @@
 		// XML Feed
 		n.Url = Urlize("index.xml")
         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()
 		s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
 		s.WritePublic("", "index.xml", y.Bytes())