mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
Correct check of published boolean
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
311593bff0
commit
49fe04c0bd
@@ -514,7 +514,7 @@ func (p *Page) update(f interface{}) error {
|
|||||||
*draft = cast.ToBool(v)
|
*draft = cast.ToBool(v)
|
||||||
case "published": // Intentionally undocumented
|
case "published": // Intentionally undocumented
|
||||||
published = new(bool)
|
published = new(bool)
|
||||||
*published = !cast.ToBool(v)
|
*published = cast.ToBool(v)
|
||||||
case "layout":
|
case "layout":
|
||||||
p.layout = cast.ToString(v)
|
p.layout = cast.ToString(v)
|
||||||
case "markup":
|
case "markup":
|
||||||
|
@@ -869,6 +869,36 @@ func TestDraftAndPublishedFrontMatterError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var PAGE_WITH_PUBLISHED_FALSE = `---
|
||||||
|
title: okay
|
||||||
|
published: false
|
||||||
|
---
|
||||||
|
some content
|
||||||
|
`
|
||||||
|
var PAGE_WITH_PUBLISHED_TRUE = `---
|
||||||
|
title: okay
|
||||||
|
published: true
|
||||||
|
---
|
||||||
|
some content
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestPublishedFrontMatter(t *testing.T) {
|
||||||
|
p, err := NewPageFrom(strings.NewReader(PAGE_WITH_PUBLISHED_FALSE), "content/post/broken.md")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err during parse: %s", err)
|
||||||
|
}
|
||||||
|
if !p.Draft {
|
||||||
|
t.Errorf("expected true, got %t", p.Draft)
|
||||||
|
}
|
||||||
|
p, err = NewPageFrom(strings.NewReader(PAGE_WITH_PUBLISHED_TRUE), "content/post/broken.md")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err during parse: %s", err)
|
||||||
|
}
|
||||||
|
if p.Draft {
|
||||||
|
t.Errorf("expected false, got %t", p.Draft)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func listEqual(left, right []string) bool {
|
func listEqual(left, right []string) bool {
|
||||||
if len(left) != len(right) {
|
if len(left) != len(right) {
|
||||||
return false
|
return false
|
||||||
|
Reference in New Issue
Block a user