hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 1039356edf747f044c989a5bc0e85d792341ed5d
parent ccdd08d57ab64441e93d6861ae126b5faacdb92f
Author: Victor Kropp <victor.kropp@gmail.com>
Date:   Tue, 14 Mar 2017 17:46:33 +0100

commands: Support human-readable YAML boolean values in undraft

Diffstat:
Mcommands/undraft.go | 8+++-----
Mcommands/undraft_test.go | 14++++++++------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/commands/undraft.go b/commands/undraft.go
@@ -25,8 +25,8 @@ import (
 
 var undraftCmd = &cobra.Command{
 	Use:   "undraft path/to/content",
-	Short: "Undraft changes the content's draft status from 'True' to 'False'",
-	Long: `Undraft changes the content's draft status from 'True' to 'False'
+	Short: "Undraft resets the content's draft status",
+	Long: `Undraft resets the content's draft status
 and updates the date to the current date and time.
 If the content's draft status is 'False', nothing is done.`,
 	RunE: Undraft,
@@ -138,14 +138,12 @@ L:
 	for _, v := range fmLines {
 		pos := bytes.Index(v, []byte("draft"))
 		if pos != -1 {
-			v = bytes.Replace(v, []byte("true"), []byte("false"), 1)
-			goto write
+			continue
 		}
 		pos = bytes.Index(v, []byte("date"))
 		if pos != -1 { // if date field wasn't found, add it
 			v = bytes.Replace(v, []byte(date), []byte(time.Now().Format(time.RFC3339)), 1)
 		}
-	write:
 		buff.Write(v)
 		buff.Write(lineEnding)
 	}
diff --git a/commands/undraft_test.go b/commands/undraft_test.go
@@ -25,12 +25,13 @@ import (
 )
 
 var (
-	jsonFM      = "{\n \"date\": \"12-04-06\",\n \"title\": \"test json\"\n}"
-	jsonDraftFM = "{\n \"draft\": true,\n \"date\": \"12-04-06\",\n \"title\":\"test json\"\n}"
-	tomlFM      = "+++\n date= \"12-04-06\"\n title= \"test toml\"\n+++"
-	tomlDraftFM = "+++\n draft= true\n date= \"12-04-06\"\n title=\"test toml\"\n+++"
-	yamlFM      = "---\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
-	yamlDraftFM = "---\n draft: true\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
+	jsonFM         = "{\n \"date\": \"12-04-06\",\n \"title\": \"test json\"\n}"
+	jsonDraftFM    = "{\n \"draft\": true,\n \"date\": \"12-04-06\",\n \"title\":\"test json\"\n}"
+	tomlFM         = "+++\n date= \"12-04-06\"\n title= \"test toml\"\n+++"
+	tomlDraftFM    = "+++\n draft= true\n date= \"12-04-06\"\n title=\"test toml\"\n+++"
+	yamlFM         = "---\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
+	yamlDraftFM    = "---\n draft: true\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
+	yamlYesDraftFM = "---\n draft: yes\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
 )
 
 func TestUndraftContent(t *testing.T) {
@@ -44,6 +45,7 @@ func TestUndraftContent(t *testing.T) {
 		{tomlDraftFM, ""},
 		{yamlFM, "not a Draft: nothing was done"},
 		{yamlDraftFM, ""},
+		{yamlYesDraftFM, ""},
 	}
 
 	for i, test := range tests {