mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
hubolib: Revert to .Type = "page" when empty
This was changed with good intentions in 0.63.0. This behaviour was not documented, but it was of course in use. This commit rolls back to how it behaved before: For `Page.Type` you will get: * `type` from front matter if set. * `.Section` * If none of the above returns anything, return "page" Fixes #6805
This commit is contained in:
parent
74b6c4e5ff
commit
e8831a056b
3 changed files with 24 additions and 4 deletions
|
@ -68,12 +68,13 @@ func TestCascade(t *testing.T) {
|
||||||
42|taxonomy|tags/blue|blue|home.png|tags|HTML-|
|
42|taxonomy|tags/blue|blue|home.png|tags|HTML-|
|
||||||
42|section|sect3|Cascade Home|home.png|sect3|HTML-|
|
42|section|sect3|Cascade Home|home.png|sect3|HTML-|
|
||||||
42|taxonomyTerm|tags|Cascade Home|home.png|tags|HTML-|
|
42|taxonomyTerm|tags|Cascade Home|home.png|tags|HTML-|
|
||||||
42|page|p2.md|Cascade Home|home.png||HTML-|
|
42|page|bundle1/index.md|Cascade Home|home.png|page|HTML-|
|
||||||
|
42|page|p2.md|Cascade Home|home.png|page|HTML-|
|
||||||
42|page|sect2/p2.md|Cascade Home|home.png|sect2|HTML-|
|
42|page|sect2/p2.md|Cascade Home|home.png|sect2|HTML-|
|
||||||
42|page|sect3/p1.md|Cascade Home|home.png|sect3|HTML-|
|
42|page|sect3/p1.md|Cascade Home|home.png|sect3|HTML-|
|
||||||
42|taxonomy|tags/green|green|home.png|tags|HTML-|
|
42|taxonomy|tags/green|green|home.png|tags|HTML-|
|
||||||
42|home|_index.md|Home|home.png||HTML-|
|
42|home|_index.md|Home|home.png|page|HTML-|
|
||||||
42|page|p1.md|p1|home.png||HTML-|
|
42|page|p1.md|p1|home.png|page|HTML-|
|
||||||
42|section|sect1/_index.md|Sect1|sect1.png|stype|HTML-|
|
42|section|sect1/_index.md|Sect1|sect1.png|stype|HTML-|
|
||||||
42|section|sect1/s1_2/_index.md|Sect1_2|sect1.png|stype|HTML-|
|
42|section|sect1/s1_2/_index.md|Sect1_2|sect1.png|stype|HTML-|
|
||||||
42|page|sect1/s1_2/p1.md|Sect1_2_p1|sect1.png|stype|HTML-|
|
42|page|sect1/s1_2/p1.md|Sect1_2_p1|sect1.png|stype|HTML-|
|
||||||
|
|
|
@ -291,12 +291,18 @@ func (p *pageMeta) Title() string {
|
||||||
return p.title
|
return p.title
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultContentType = "page"
|
||||||
|
|
||||||
func (p *pageMeta) Type() string {
|
func (p *pageMeta) Type() string {
|
||||||
if p.contentType != "" {
|
if p.contentType != "" {
|
||||||
return p.contentType
|
return p.contentType
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.Section()
|
if sect := p.Section(); sect != "" {
|
||||||
|
return sect
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pageMeta) Weight() int {
|
func (p *pageMeta) Weight() int {
|
||||||
|
|
|
@ -333,6 +333,12 @@ func checkPageSummary(t *testing.T, page page.Page, summary string, msg ...inter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkPageType(t *testing.T, page page.Page, pageType string) {
|
||||||
|
if page.Type() != pageType {
|
||||||
|
t.Fatalf("Page type is: %s. Expected: %s", page.Type(), pageType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func checkPageDate(t *testing.T, page page.Page, time time.Time) {
|
func checkPageDate(t *testing.T, page page.Page, time time.Time) {
|
||||||
if page.Date() != time {
|
if page.Date() != time {
|
||||||
t.Fatalf("Page date is: %s. Expected: %s", page.Date(), time)
|
t.Fatalf("Page date is: %s. Expected: %s", page.Date(), time)
|
||||||
|
@ -536,6 +542,7 @@ func TestCreateNewPage(t *testing.T) {
|
||||||
checkPageTitle(t, p, "Simple")
|
checkPageTitle(t, p, "Simple")
|
||||||
checkPageContent(t, p, normalizeExpected(ext, "<p>Simple Page</p>\n"))
|
checkPageContent(t, p, normalizeExpected(ext, "<p>Simple Page</p>\n"))
|
||||||
checkPageSummary(t, p, "Simple Page")
|
checkPageSummary(t, p, "Simple Page")
|
||||||
|
checkPageType(t, p, "page")
|
||||||
}
|
}
|
||||||
|
|
||||||
settings := map[string]interface{}{
|
settings := map[string]interface{}{
|
||||||
|
@ -555,6 +562,7 @@ func TestPageSummary(t *testing.T) {
|
||||||
checkPageContent(t, p, normalizeExpected(ext, "<p><a href=\"https://lipsum.com/\">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>\n\n<p>Additional text.</p>\n\n<p>Further text.</p>\n"), ext)
|
checkPageContent(t, p, normalizeExpected(ext, "<p><a href=\"https://lipsum.com/\">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>\n\n<p>Additional text.</p>\n\n<p>Further text.</p>\n"), ext)
|
||||||
checkPageSummary(t, p, normalizeExpected(ext, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Additional text."), ext)
|
checkPageSummary(t, p, normalizeExpected(ext, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Additional text."), ext)
|
||||||
}
|
}
|
||||||
|
checkPageType(t, p, "page")
|
||||||
}
|
}
|
||||||
|
|
||||||
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithoutSummaryDelimiter)
|
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithoutSummaryDelimiter)
|
||||||
|
@ -567,6 +575,7 @@ func TestPageWithDelimiter(t *testing.T) {
|
||||||
checkPageTitle(t, p, "Simple")
|
checkPageTitle(t, p, "Simple")
|
||||||
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line</p>\n\n<p>Some more text</p>\n"), ext)
|
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line</p>\n\n<p>Some more text</p>\n"), ext)
|
||||||
checkPageSummary(t, p, normalizeExpected(ext, "<p>Summary Next Line</p>"), ext)
|
checkPageSummary(t, p, normalizeExpected(ext, "<p>Summary Next Line</p>"), ext)
|
||||||
|
checkPageType(t, p, "page")
|
||||||
}
|
}
|
||||||
|
|
||||||
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiter)
|
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiter)
|
||||||
|
@ -582,6 +591,7 @@ func TestPageWithSummaryParameter(t *testing.T) {
|
||||||
if ext != "ad" && ext != "rst" {
|
if ext != "ad" && ext != "rst" {
|
||||||
checkPageSummary(t, p, normalizeExpected(ext, "Page with summary parameter and <a href=\"http://www.example.com/\">a link</a>"), ext)
|
checkPageSummary(t, p, normalizeExpected(ext, "Page with summary parameter and <a href=\"http://www.example.com/\">a link</a>"), ext)
|
||||||
}
|
}
|
||||||
|
checkPageType(t, p, "page")
|
||||||
}
|
}
|
||||||
|
|
||||||
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryParameter)
|
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryParameter)
|
||||||
|
@ -653,6 +663,7 @@ func TestPageWithShortCodeInSummary(t *testing.T) {
|
||||||
checkPageTitle(t, p, "Simple")
|
checkPageTitle(t, p, "Simple")
|
||||||
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line. <figure> <img src=\"/not/real\"/> </figure> . More text here.</p><p>Some more text</p>"))
|
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line. <figure> <img src=\"/not/real\"/> </figure> . More text here.</p><p>Some more text</p>"))
|
||||||
checkPageSummary(t, p, "Summary Next Line. . More text here. Some more text")
|
checkPageSummary(t, p, "Summary Next Line. . More text here. Some more text")
|
||||||
|
checkPageType(t, p, "page")
|
||||||
}
|
}
|
||||||
|
|
||||||
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithShortcodeInSummary)
|
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithShortcodeInSummary)
|
||||||
|
@ -702,6 +713,8 @@ func TestPageWithMoreTag(t *testing.T) {
|
||||||
checkPageTitle(t, p, "Simple")
|
checkPageTitle(t, p, "Simple")
|
||||||
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Same Line</p>\n\n<p>Some more text</p>\n"))
|
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Same Line</p>\n\n<p>Some more text</p>\n"))
|
||||||
checkPageSummary(t, p, normalizeExpected(ext, "<p>Summary Same Line</p>"))
|
checkPageSummary(t, p, normalizeExpected(ext, "<p>Summary Same Line</p>"))
|
||||||
|
checkPageType(t, p, "page")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiterSameLine)
|
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiterSameLine)
|
||||||
|
|
Loading…
Reference in a new issue