shithub: hugo

Download patch

ref: 3ecc698f5e109610288b48b49c5ac2ee442a5ed0
parent: a591a1062645718be3e2b7bbf2ad389a50b861e3
author: Noah Campbell <[email protected]>
date: Tue Sep 3 08:41:13 EDT 2013

Remove hugolib.HTML and hugolib.URL types

These types were not be rendered correctly by the html/template package.
Removing them gets the correct behavior.

Fixes #74

--- a/hugolib/helpers.go
+++ b/hugolib/helpers.go
@@ -15,6 +15,7 @@
 
 import (
 	"bytes"
+	"html/template"
 	"errors"
 	"fmt"
 	"github.com/kr/pretty"
@@ -164,11 +165,11 @@
 	return Sanitize(strings.ToLower(strings.Replace(strings.TrimSpace(url), " ", "-", -1)))
 }
 
-func AbsUrl(url string, base string) HTML {
+func AbsUrl(url string, base string) template.HTML {
 	if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
-		return HTML(url)
+		return template.HTML(url)
 	}
-	return HTML(MakePermalink(base, url))
+	return template.HTML(MakePermalink(base, url))
 }
 
 func Gt(a interface{}, b interface{}) bool {
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -15,10 +15,11 @@
 
 import (
 	"time"
+	"html/template"
 )
 
 type Node struct {
-	RSSlink     HTML
+	RSSlink     template.HTML
 	Site        SiteInfo
 	layout      string
 	Data        map[string]interface{}
@@ -31,7 +32,7 @@
 
 type UrlPath struct {
 	Url       string
-	Permalink HTML
+	Permalink template.HTML
 	Slug      string
 	Section   string
 	Path      string
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -22,6 +22,7 @@
 	"github.com/BurntSushi/toml"
 	"github.com/theplant/blackfriday"
 	"io"
+	"html/template"
 	"io/ioutil"
 	"launchpad.net/goyaml"
 	"os"
@@ -37,8 +38,8 @@
 type Page struct {
 	Status          string
 	Images          []string
-	Content         HTML
-	Summary         HTML
+	Content         template.HTML
+	Summary         template.HTML
 	RawMarkdown     string // TODO should be []byte
 	Params          map[string]interface{}
 	RenderedContent *bytes.Buffer
@@ -184,7 +185,7 @@
 	return datum, lines
 }
 
-func (p *Page) Permalink() HTML {
+func (p *Page) Permalink() template.HTML {
 	baseUrl := string(p.Site.BaseUrl)
 	section := strings.TrimSpace(p.Section)
 	pSlug := strings.TrimSpace(p.Slug)
@@ -208,7 +209,7 @@
 			path = section + "/" + file
 		}
 	}
-	return HTML(MakePermalink(baseUrl, path))
+	return template.HTML(MakePermalink(baseUrl, path))
 }
 
 func (page *Page) handleTomlMetaData(datum []byte) (interface{}, error) {
@@ -426,7 +427,7 @@
 	}
 }
 
-func (p *Page) Render(layout ...string) HTML {
+func (p *Page) Render(layout ...string) template.HTML {
 	curLayout := ""
 
 	if len(layout) > 0 {
@@ -433,7 +434,7 @@
 		curLayout = layout[0]
 	}
 
-	return HTML(string(p.ExecuteTemplate(curLayout).Bytes()))
+	return template.HTML(string(p.ExecuteTemplate(curLayout).Bytes()))
 }
 
 func (p *Page) ExecuteTemplate(layout string) *bytes.Buffer {
@@ -480,12 +481,12 @@
 	b := new(bytes.Buffer)
 	b.ReadFrom(lines)
 	content := b.Bytes()
-	page.Content = HTML(string(blackfriday.MarkdownCommon(RemoveSummaryDivider(content))))
+	page.Content = template.HTML(string(blackfriday.MarkdownCommon(RemoveSummaryDivider(content))))
 	summary, plain := getSummaryString(content)
 	if plain {
-		page.Summary = HTML(string(summary))
+		page.Summary = template.HTML(string(summary))
 	} else {
-		page.Summary = HTML(string(blackfriday.MarkdownCommon(summary)))
+		page.Summary = template.HTML(string(blackfriday.MarkdownCommon(summary)))
 	}
 }
 
@@ -493,11 +494,11 @@
 	b := new(bytes.Buffer)
 	b.ReadFrom(lines)
 	content := b.Bytes()
-	page.Content = HTML(getRstContent(content))
+	page.Content = template.HTML(getRstContent(content))
 	summary, plain := getSummaryString(content)
 	if plain {
-		page.Summary = HTML(string(summary))
+		page.Summary = template.HTML(string(summary))
 	} else {
-		page.Summary = HTML(getRstContent(summary))
+		page.Summary = template.HTML(getRstContent(summary))
 	}
 }
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -4,6 +4,7 @@
 	"path/filepath"
 	"strings"
 	"testing"
+	"html/template"
 )
 
 var EMPTY_PAGE = ""
@@ -141,13 +142,13 @@
 }
 
 func checkPageContent(t *testing.T, page *Page, content string) {
-	if page.Content != HTML(content) {
+	if page.Content != template.HTML(content) {
 		t.Fatalf("Page content is: %s.  Expected %s", page.Content, content)
 	}
 }
 
 func checkPageSummary(t *testing.T, page *Page, summary string) {
-	if page.Summary != HTML(summary) {
+	if page.Summary != template.HTML(summary) {
 		t.Fatalf("Page summary is: `%s`.  Expected `%s`", page.Summary, summary)
 	}
 }
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -15,6 +15,7 @@
 
 import (
 	"bitbucket.org/pkg/inflect"
+	"html/template"
 	"bytes"
 	"fmt"
 	"github.com/spf13/hugo/target"
@@ -41,7 +42,7 @@
 }
 
 type SiteInfo struct {
-	BaseUrl    URL
+	BaseUrl    template.URL
 	Indexes    OrderedIndexList
 	Recent     *Pages
 	LastChange time.Time
@@ -169,7 +170,7 @@
 
 	filepath.Walk(s.absContentDir(), walker)
 	s.Info = SiteInfo{
-		BaseUrl: URL(s.Config.BaseUrl),
+		BaseUrl: template.URL(s.Config.BaseUrl),
 		Title:   s.Config.Title,
 		Recent:  &s.Pages,
 		Config:  &s.Config,
@@ -206,7 +207,7 @@
 
 func (s *Site) ProcessShortcodes() {
 	for _, page := range s.Pages {
-		page.Content = HTML(ShortcodesHandle(string(page.Content), page, s.Tmpl))
+		page.Content = template.HTML(ShortcodesHandle(string(page.Content), page, s.Tmpl))
 	}
 }
 
@@ -220,7 +221,7 @@
 		content = strings.Replace(content, " href='/", " href='"+baseWithSlash, -1)
 		content = strings.Replace(content, " href=\"/", " href=\""+baseWithSlash, -1)
 		content = strings.Replace(content, baseWithoutTrailingSlash+"//", baseWithSlash, -1)
-		page.Content = HTML(content)
+		page.Content = template.HTML(content)
 	}
 }
 
@@ -525,7 +526,7 @@
 			} else {
 				n.Url = Urlize(section + "/" + "index.xml")
 			}
-			n.Permalink = HTML(string(n.Site.BaseUrl) + n.Url)
+			n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url)
 			y := s.NewXMLBuffer()
 			s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
 			err = s.WritePublic(section+"/index.xml", y.Bytes())
@@ -591,8 +592,8 @@
 	}
 }
 
-func permalink(s *Site, plink string) HTML {
-	return HTML(MakePermalink(string(s.Info.BaseUrl), plink))
+func permalink(s *Site, plink string) template.HTML {
+	return template.HTML(MakePermalink(string(s.Info.BaseUrl), plink))
 }
 
 func (s *Site) NewNode() *Node {
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -5,6 +5,7 @@
 	"fmt"
 	"strings"
 	"testing"
+	"html/template"
 )
 
 var TEMPLATE_TITLE = "{{ .Title }}"
@@ -104,7 +105,7 @@
 	}{
 		{PAGE_SIMPLE_TITLE, TEMPLATE_TITLE, "simple template"},
 		{PAGE_SIMPLE_TITLE, TEMPLATE_FUNC, "simple-template"},
-		{PAGE_WITH_MD, TEMPLATE_CONTENT, "<h1>heading 1</h1>\n<p>text</p>\n<h2>heading 2</h2>\n<p>more text</p>\n"},
+		{PAGE_WITH_MD, TEMPLATE_CONTENT, "<h1>heading 1</h1>\n\n<p>text</p>\n\n<h2>heading 2</h2>\n\n<p>more text</p>\n"},
 	}
 
 	s := new(Site)
@@ -121,6 +122,7 @@
 			t.Fatalf("Unable to add template")
 		}
 
+		p.Content = template.HTML(p.Content)
 		html, err2 := s.RenderThing(p, templateName)
 		if err2 != nil {
 			t.Errorf("Unable to render html: %s", err)
--- a/hugolib/template.go
+++ b/hugolib/template.go
@@ -14,7 +14,6 @@
 // It should not be used for HTML from a third-party, or HTML with
 // unclosed tags or comments. The outputs of a sound HTML sanitizer
 // and a template escaped by this package are fine for use with HTML.
-type HTML template.HTML
 
 type Template interface {
 	ExecuteTemplate(wr io.Writer, name string, data interface{}) error
@@ -24,8 +23,6 @@
 	LoadTemplates(absPath string)
 	AddTemplate(name, tpl string) error
 }
-
-type URL template.URL
 
 type templateErr struct {
 	name string