shithub: hugo

Download patch

ref: 417c5e2b67b97fa80a0b6f77d259966f03b95344
parent: 94c8b29c39d0c485ee91d98c08fd615c28802496
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Apr 15 12:42:54 EDT 2018

Make Page.Content a method that returns interface{}

To prepare for a `Resource.Content` method.

See #4622

--- a/hugolib/embedded_shortcodes_test.go
+++ b/hugolib/embedded_shortcodes_test.go
@@ -69,7 +69,7 @@
 
 	require.Len(t, s.RegularPages, 1)
 
-	output := string(s.RegularPages[0].Content)
+	output := string(s.RegularPages[0].content)
 
 	if !strings.Contains(output, expected) {
 		t.Errorf("Got\n%q\nExpected\n%q", output, expected)
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -378,9 +378,9 @@
 	b.AssertFileContent("public/en/tags/tag1/index.html", "Tag1|Hello|http://example.com/blog/en/tags/tag1/")
 
 	// Check Blackfriday config
-	require.True(t, strings.Contains(string(doc1fr.Content), "&laquo;"), string(doc1fr.Content))
-	require.False(t, strings.Contains(string(doc1en.Content), "&laquo;"), string(doc1en.Content))
-	require.True(t, strings.Contains(string(doc1en.Content), "&ldquo;"), string(doc1en.Content))
+	require.True(t, strings.Contains(string(doc1fr.content), "&laquo;"), string(doc1fr.content))
+	require.False(t, strings.Contains(string(doc1en.content), "&laquo;"), string(doc1en.content))
+	require.True(t, strings.Contains(string(doc1en.content), "&ldquo;"), string(doc1en.content))
 
 	// Check that the drafts etc. are not built/processed/rendered.
 	assertShouldNotBuild(t, b.H)
@@ -630,9 +630,9 @@
 	for _, p := range s.rawAllPages {
 		// No HTML when not processed
 		require.Equal(t, p.shouldBuild(), bytes.Contains(p.workContent, []byte("</")), p.BaseFileName()+": "+string(p.workContent))
-		require.Equal(t, p.shouldBuild(), p.Content != "", p.BaseFileName())
+		require.Equal(t, p.shouldBuild(), p.content != "", p.BaseFileName())
 
-		require.Equal(t, p.shouldBuild(), p.Content != "", p.BaseFileName())
+		require.Equal(t, p.shouldBuild(), p.content != "", p.BaseFileName())
 
 	}
 }
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -128,7 +128,7 @@
 	params map[string]interface{}
 
 	// Content sections
-	Content         template.HTML
+	content         template.HTML
 	Summary         template.HTML
 	TableOfContents template.HTML
 
@@ -263,6 +263,10 @@
 	targetPathDescriptorPrototype *targetPathDescriptor
 }
 
+func (p *Page) Content() (interface{}, error) {
+	return p.content, nil
+}
+
 // Sites is a convenience method to get all the Hugo sites/languages configured.
 func (p *Page) Sites() SiteInfos {
 	infos := make(SiteInfos, len(p.s.owner.Sites))
@@ -462,7 +466,7 @@
 
 func (p *Page) initPlain() {
 	p.plainInit.Do(func() {
-		p.plain = helpers.StripHTML(string(p.Content))
+		p.plain = helpers.StripHTML(string(p.content))
 		return
 	})
 }
@@ -1098,7 +1102,7 @@
 			workContentCopy = summaryContent.content
 		}
 
-		p.Content = helpers.BytesToHTML(workContentCopy)
+		p.content = helpers.BytesToHTML(workContentCopy)
 
 		if summaryContent == nil {
 			if err := p.setAutoSummary(); err != nil {
@@ -1107,7 +1111,7 @@
 		}
 
 	} else {
-		p.Content = helpers.BytesToHTML(workContentCopy)
+		p.content = helpers.BytesToHTML(workContentCopy)
 	}
 
 	//analyze for raw stats
@@ -1720,7 +1724,7 @@
 	if p.Kind == KindPage {
 		if !p.IsRenderable() {
 			self := "__" + p.UniqueID()
-			err := p.s.TemplateHandler().AddLateTemplate(self, string(p.Content))
+			err := p.s.TemplateHandler().AddLateTemplate(self, string(p.content))
 			if err != nil {
 				return err
 			}
--- a/hugolib/pageSort.go
+++ b/hugolib/pageSort.go
@@ -237,7 +237,7 @@
 	key := "pageSort.ByLength"
 
 	length := func(p1, p2 *Page) bool {
-		return len(p1.Content) < len(p2.Content)
+		return len(p1.content) < len(p2.content)
 	}
 
 	pages, _ := spc.get(key, pageBy(length).Sort, p)
--- a/hugolib/pageSort_test.go
+++ b/hugolib/pageSort_test.go
@@ -80,7 +80,7 @@
 		{(Pages).ByPublishDate, func(p Pages) bool { return p[0].PublishDate == d4 }},
 		{(Pages).ByExpiryDate, func(p Pages) bool { return p[0].ExpiryDate == d4 }},
 		{(Pages).ByLastmod, func(p Pages) bool { return p[1].Lastmod == d3 }},
-		{(Pages).ByLength, func(p Pages) bool { return p[0].Content == "b_content" }},
+		{(Pages).ByLength, func(p Pages) bool { return p[0].content == "b_content" }},
 	} {
 		setSortVals([4]time.Time{d1, d2, d3, d4}, [4]string{"b", "ab", "cde", "fg"}, [4]int{0, 3, 2, 1}, p)
 
@@ -168,7 +168,7 @@
 		pages[len(dates)-1-i].linkTitle = pages[i].title + "l"
 		pages[len(dates)-1-i].PublishDate = dates[i]
 		pages[len(dates)-1-i].ExpiryDate = dates[i]
-		pages[len(dates)-1-i].Content = template.HTML(titles[i] + "_content")
+		pages[len(dates)-1-i].content = template.HTML(titles[i] + "_content")
 	}
 	lastLastMod := pages[2].Lastmod
 	pages[2].Lastmod = pages[1].Lastmod
--- a/hugolib/page_bundler_test.go
+++ b/hugolib/page_bundler_test.go
@@ -87,7 +87,7 @@
 				assert.Equal(singlePage, s.getPage("page", "a/1"))
 				assert.Equal(singlePage, s.getPage("page", "1"))
 
-				assert.Contains(singlePage.Content, "TheContent")
+				assert.Contains(singlePage.content, "TheContent")
 
 				if ugly {
 					assert.Equal("/a/1.html", singlePage.RelPermalink())
@@ -129,7 +129,7 @@
 				firstPage := pageResources[0].(*Page)
 				secondPage := pageResources[1].(*Page)
 				assert.Equal(filepath.FromSlash("b/my-bundle/1.md"), firstPage.pathOrTitle(), secondPage.pathOrTitle())
-				assert.Contains(firstPage.Content, "TheContent")
+				assert.Contains(firstPage.content, "TheContent")
 				assert.Equal(6, len(leafBundle1.Resources))
 
 				// https://github.com/gohugoio/hugo/issues/4582
@@ -395,7 +395,7 @@
 	assert.Equal("Headless Bundle in Topless Bar", headless.Title())
 	assert.Equal("", headless.RelPermalink())
 	assert.Equal("", headless.Permalink())
-	assert.Contains(headless.Content, "HEADLESS SHORTCODE")
+	assert.Contains(headless.content, "HEADLESS SHORTCODE")
 
 	headlessResources := headless.Resources
 	assert.Equal(3, len(headlessResources))
@@ -404,7 +404,7 @@
 	assert.NotNil(pageResource)
 	assert.IsType(&Page{}, pageResource)
 	p := pageResource.(*Page)
-	assert.Contains(p.Content, "SHORTCODE")
+	assert.Contains(p.content, "SHORTCODE")
 	assert.Equal("p1.md", p.Name())
 
 	th := testHelper{s.Cfg, s.Fs, t}
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -481,7 +481,7 @@
 
 func checkPageContent(t *testing.T, page *Page, content string, msg ...interface{}) {
 	a := normalizeContent(content)
-	b := normalizeContent(string(page.Content))
+	b := normalizeContent(string(page.content))
 	if a != b {
 		t.Fatalf("Page content is:\n%q\nExpected:\n%q (%q)", b, a, msg)
 	}
@@ -616,7 +616,7 @@
 		require.NoError(t, err)
 		require.NotNil(t, home)
 		require.Equal(t, homePath, home.Path())
-		require.Contains(t, home.Content, "Home Page Content")
+		require.Contains(t, home.content, "Home Page Content")
 
 	}
 
@@ -726,8 +726,8 @@
 		t.Fatalf("Got summary:\n%q", p.Summary)
 	}
 
-	if p.Content != template.HTML("<p>The <a href=\"http://gohugo.io/\">best static site generator</a>.<sup class=\"footnote-ref\" id=\"fnref:1\"><a href=\"#fn:1\">1</a></sup>\n</p>\n<div class=\"footnotes\">\n\n<hr />\n\n<ol>\n<li id=\"fn:1\">Many people say so.\n <a class=\"footnote-return\" href=\"#fnref:1\"><sup>[return]</sup></a></li>\n</ol>\n</div>") {
-		t.Fatalf("Got content:\n%q", p.Content)
+	if p.content != template.HTML("<p>The <a href=\"http://gohugo.io/\">best static site generator</a>.<sup class=\"footnote-ref\" id=\"fnref:1\"><a href=\"#fn:1\">1</a></sup>\n</p>\n<div class=\"footnotes\">\n\n<hr />\n\n<ol>\n<li id=\"fn:1\">Many people say so.\n <a class=\"footnote-return\" href=\"#fnref:1\"><sup>[return]</sup></a></li>\n</ol>\n</div>") {
+		t.Fatalf("Got content:\n%q", p.content)
 	}
 }
 
@@ -1511,7 +1511,7 @@
 	} {
 
 		p, _ := s.NewPage("Test")
-		p.Content = "<h1>Do Be Do Be Do</h1>"
+		p.content = "<h1>Do Be Do Be Do</h1>"
 		if !this.assertFunc(p) {
 			t.Errorf("[%d] Page method error", i)
 		}
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -87,7 +87,7 @@
 
 	require.Len(t, h.Sites[0].RegularPages, 1)
 
-	output := strings.TrimSpace(string(h.Sites[0].RegularPages[0].Content))
+	output := strings.TrimSpace(string(h.Sites[0].RegularPages[0].content))
 	output = strings.TrimPrefix(output, "<p>")
 	output = strings.TrimSuffix(output, "</p>")