summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-15 16:42:54 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-15 18:08:06 +0200
commit417c5e2b67b97fa80a0b6f77d259966f03b95344 (patch)
tree9012bff91acfd5656c68450556909d6f258cc236
parent94c8b29c39d0c485ee91d98c08fd615c28802496 (diff)
Make Page.Content a method that returns interface{}
To prepare for a `Resource.Content` method. See #4622
-rw-r--r--hugolib/embedded_shortcodes_test.go2
-rw-r--r--hugolib/hugo_sites_build_test.go10
-rw-r--r--hugolib/page.go14
-rw-r--r--hugolib/pageSort.go2
-rw-r--r--hugolib/pageSort_test.go4
-rw-r--r--hugolib/page_bundler_test.go8
-rw-r--r--hugolib/page_test.go10
-rw-r--r--hugolib/shortcode_test.go2
8 files changed, 28 insertions, 24 deletions
diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go
index 50da35c5b..fb663f1cb 100644
--- a/hugolib/embedded_shortcodes_test.go
+++ b/hugolib/embedded_shortcodes_test.go
@@ -69,7 +69,7 @@ func doTestShortcodeCrossrefs(t *testing.T, relative bool) {
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)
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go
index 1626fadcf..0515def4e 100644
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -378,9 +378,9 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
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 @@ func assertShouldNotBuild(t *testing.T, sites *HugoSites) {
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())
}
}
diff --git a/hugolib/page.go b/hugolib/page.go
index 195e68084..8595c1b35 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -128,7 +128,7 @@ type Page struct {
params map[string]interface{}
// Content sections
- Content template.HTML
+ content template.HTML
Summary template.HTML
TableOfContents template.HTML
@@ -263,6 +263,10 @@ type Page struct {
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) PlainWords() []string {
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 @@ func (p *Page) prepareForRender(cfg *BuildCfg) error {
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 @@ func (p *Page) prepareForRender(cfg *BuildCfg) error {
}
} else {
- p.Content = helpers.BytesToHTML(workContentCopy)
+ p.content = helpers.BytesToHTML(workContentCopy)
}
//analyze for raw stats
@@ -1720,7 +1724,7 @@ func (p *Page) prepareLayouts() error {
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
}
diff --git a/hugolib/pageSort.go b/hugolib/pageSort.go
index a9477059d..26682a3c8 100644
--- a/hugolib/pageSort.go
+++ b/hugolib/pageSort.go
@@ -237,7 +237,7 @@ func (p Pages) ByLength() Pages {
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)
diff --git a/hugolib/pageSort_test.go b/hugolib/pageSort_test.go
index d9c0d0761..2b0ceb367 100644
--- a/hugolib/pageSort_test.go
+++ b/hugolib/pageSort_test.go
@@ -80,7 +80,7 @@ func TestSortByN(t *testing.T) {
{(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 @@ func setSortVals(dates [4]time.Time, titles [4]string, weights [4]int, pages Pag
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
diff --git a/hugolib/page_bundler_test.go b/hugolib/page_bundler_test.go
index becf8c622..d6aac1774 100644
--- a/hugolib/page_bundler_test.go
+++ b/hugolib/page_bundler_test.go
@@ -87,7 +87,7 @@ func TestPageBundlerSiteRegular(t *testing.T) {
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 @@ func TestPageBundlerSiteRegular(t *testing.T) {
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 @@ HEADLESS {{< myShort >}}
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 @@ HEADLESS {{< myShort >}}
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}
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index 2b679c842..308bf31cb 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -481,7 +481,7 @@ func checkPageTitle(t *testing.T, page *Page, title string) {
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 @@ func testAllMarkdownEnginesForPages(t *testing.T,
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 @@ func TestPageWithDelimiterForMarkdownThatCrossesBorder(t *testing.T) {
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 @@ func TestPageSimpleMethods(t *testing.T) {
} {
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)
}
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
index 449d55abd..51f99830b 100644
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -87,7 +87,7 @@ title: "Title"
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>")