diff --git a/hugolib/page.go b/hugolib/page.go index d9f4ad6ca..f09c6c1bf 100644 --- 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 index a85cb7ada..a308ecefc 100644 --- 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 index 75ba6bfa8..c50d9bd77 100644 --- 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 index 2ef184415..838445463 100644 --- 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 = "Going" - TEMPLATE_WITH_URL_ABS = "Going" + TEMPLATE_WITH_URL_REL = "Going" + TEMPLATE_WITH_URL_ABS = "Going" 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()