hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 51e309854821a5e943e8e64eea218bc82c8f2dc6
parent e76c3feb52381efaf8add59857d6940aaec7c0a8
Author: spf13 <steve.francia@gmail.com>
Date:   Wed, 10 Jul 2013 00:14:02 -0400

Writing relative links to absolute so they work in feeds

Diffstat:
Mhugolib/site.go | 13+++++++++++++
Mmain.go | 4+++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/hugolib/site.go b/hugolib/site.go
@@ -83,6 +83,8 @@ func (site *Site) Render() {
 	site.timer.Step("render and write lists")
 	site.ProcessShortcodes()
 	site.timer.Step("render shortcodes")
+	site.AbsUrlify()
+	site.timer.Step("absolute URLify")
 	site.RenderPages()
 	site.timer.Step("render pages")
 	site.RenderHomePage()
@@ -182,6 +184,17 @@ func (s *Site) ProcessShortcodes() {
 	}
 }
 
+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)
+		s.Pages[i].Content = template.HTML(content)
+	}
+}
+
 func (s *Site) CreatePages() {
 	for _, fileName := range s.Files {
 		page := NewPage(fileName)
diff --git a/main.go b/main.go
@@ -64,7 +64,9 @@ func main() {
 
 	if *baseUrl != "" {
 		config.BaseUrl = *baseUrl
-	}
+	} else if *server {
+        config.BaseUrl = "http://localhost:" + *port
+    }
 
 	if *version {
 		fmt.Println("Hugo Static Site Generator v0.8")