Correct check of published boolean
authorJeff Hodges <jeff@somethingsimilar.com>
Sun, 30 Aug 2015 22:51:25 +0000 (15:51 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 31 Aug 2015 03:26:46 +0000 (05:26 +0200)
hugolib/page.go
hugolib/page_test.go

index f281053a2af1502b1a85a7b5514ba56d6ee9877c..b80e92257eedfdfd84f393593439df85e8dd423f 100644 (file)
@@ -514,7 +514,7 @@ func (p *Page) update(f interface{}) error {
                        *draft = cast.ToBool(v)
                case "published": // Intentionally undocumented
                        published = new(bool)
-                       *published = !cast.ToBool(v)
+                       *published = cast.ToBool(v)
                case "layout":
                        p.layout = cast.ToString(v)
                case "markup":
index 7a9c12321decd8af8ae272fa6ce45828fcf9d9f1..9a1b67fa1a165af11721eb023f258948e8a1caae 100644 (file)
@@ -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 {
        if len(left) != len(right) {
                return false