hugo

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

git clone git://git.shimmy1996.com/hugo.git
commit f432b187a0ec52629ad1b9d993a5c3203e3699d5
parent a45de56db1992d469dc9b4714bd839d6c3e9b092
Author: spf13 <steve.francia@gmail.com>
Date:   Fri,  6 Dec 2013 23:32:00 -0500

render shortcodes prior to converting to html

Diffstat:
Mhugolib/page.go | 13++++++++++---
Mhugolib/page_test.go | 7+++++++
Mhugolib/site.go | 12++++++++++--
Mhugolib/site_test.go | 7+++++--
4 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/hugolib/page.go b/hugolib/page.go
@@ -36,6 +36,7 @@ import (
 type Page struct {
 	Status      string
 	Images      []string
+	RawContent  []byte
 	Content     template.HTML
 	Summary     template.HTML
 	Truncated   bool
@@ -520,17 +521,23 @@ func (page *Page) parse(reader io.Reader) error {
 		if err = page.update(meta); err != nil {
 			return err
 		}
+
 	}
+	page.Content = template.HTML(p.Content())
+
+	return nil
+}
 
+func (page *Page) Convert() error {
 	switch page.guessMarkupType() {
 	case "md", "markdown", "mdown":
-		page.convertMarkdown(bytes.NewReader(p.Content()))
+		page.convertMarkdown(bytes.NewReader([]byte(page.Content)))
 	case "rst":
-		page.convertRestructuredText(bytes.NewReader(p.Content()))
+		page.convertRestructuredText(bytes.NewReader([]byte(page.Content)))
 	case "html":
 		fallthrough
 	default:
-		page.Content = template.HTML(p.Content())
+		page.Content = template.HTML(page.Content)
 	}
 	return nil
 }
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
@@ -227,6 +227,8 @@ func checkTruncation(t *testing.T, page *Page, shouldBe bool, msg string) {
 
 func TestCreateNewPage(t *testing.T) {
 	p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE), "simple.md")
+	p.Convert()
+
 	if err != nil {
 		t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
 	}
@@ -240,6 +242,7 @@ func TestCreateNewPage(t *testing.T) {
 
 func TestPageWithDelimiter(t *testing.T) {
 	p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER), "simple.md")
+	p.Convert()
 	if err != nil {
 		t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
 	}
@@ -253,6 +256,7 @@ func TestPageWithDelimiter(t *testing.T) {
 
 func TestPageWithShortCodeInSummary(t *testing.T) {
 	p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SHORTCODE_IN_SUMMARY), "simple.md")
+	p.Convert()
 	if err != nil {
 		t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
 	}
@@ -265,6 +269,7 @@ func TestPageWithShortCodeInSummary(t *testing.T) {
 
 func TestPageWithMoreTag(t *testing.T) {
 	p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE), "simple.md")
+	p.Convert()
 	if err != nil {
 		t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
 	}
@@ -277,6 +282,7 @@ func TestPageWithMoreTag(t *testing.T) {
 
 func TestPageWithDate(t *testing.T) {
 	p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_RFC3339_DATE), "simple")
+	p.Convert()
 	if err != nil {
 		t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
 	}
@@ -289,6 +295,7 @@ func TestPageWithDate(t *testing.T) {
 
 func TestWordCount(t *testing.T) {
 	p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_LONG_CONTENT), "simple.md")
+	p.Convert()
 	if err != nil {
 		t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
 	}
diff --git a/hugolib/site.go b/hugolib/site.go
@@ -170,8 +170,6 @@ func (s *Site) Render() (err error) {
 		return
 	}
 	s.timerStep("render and write aliases")
-	s.ProcessShortcodes()
-	s.timerStep("render shortcodes")
 	if err = s.RenderIndexes(); err != nil {
 		return
 	}
@@ -289,6 +287,16 @@ func (s *Site) CreatePages() (err error) {
 		page.Tmpl = s.Tmpl
 		page.Section = file.Section
 		page.Dir = file.Dir
+
+		// Handling short codes prior to Conversion to HTML
+		page.Content = template.HTML(ShortcodesHandle(string(page.Content), page, s.Tmpl))
+		page.Summary = template.HTML(ShortcodesHandle(string(page.Summary), page, s.Tmpl))
+
+		err = page.Convert()
+		if err != nil {
+			return err
+		}
+
 		if s.Config.BuildDrafts || !page.Draft {
 			s.Pages = append(s.Pages, page)
 		}
diff --git a/hugolib/site_test.go b/hugolib/site_test.go
@@ -23,8 +23,8 @@ content`
 	TEMPLATE_CONTENT             = "{{ .Content }}"
 	TEMPLATE_DATE                = "{{ .Date }}"
 	INVALID_TEMPLATE_FORMAT_DATE = "{{ .Date.Format time.RFC3339 }}"
-	TEMPLATE_WITH_URL_REL            = "<a href=\"foobar.jpg\">Going</a>"
-	TEMPLATE_WITH_URL_ABS            = "<a href=\"/foobar.jpg\">Going</a>"
+	TEMPLATE_WITH_URL_REL        = "<a href=\"foobar.jpg\">Going</a>"
+	TEMPLATE_WITH_URL_ABS        = "<a href=\"/foobar.jpg\">Going</a>"
 	PAGE_URL_SPECIFIED           = `---
 title: simple template
 url: "mycategory/my-whatever-content/"
@@ -50,6 +50,7 @@ func pageMust(p *Page, err error) *Page {
 
 func TestDegenerateRenderThingMissingTemplate(t *testing.T) {
 	p, _ := ReadFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
+	p.Convert()
 	s := new(Site)
 	s.prepTemplates()
 	err := s.renderThing(p, "foobar", nil)
@@ -106,6 +107,7 @@ func TestRenderThing(t *testing.T) {
 
 	for i, test := range tests {
 		p, err := ReadFrom(strings.NewReader(test.content), "content/a/file.md")
+		p.Convert()
 		if err != nil {
 			t.Fatalf("Error parsing buffer: %s", err)
 		}
@@ -234,6 +236,7 @@ func TestSkipRender(t *testing.T) {
 		Config: Config{Verbose: true, BaseUrl: "http://auth/bub"},
 		Source: &source.InMemorySource{sources},
 	}
+
 	s.initializeSiteInfo()
 	s.prepTemplates()