File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ import (
2525
2626var undraftCmd = & cobra.Command {
2727 Use : "undraft path/to/content" ,
28- Short : "Undraft changes the content's draft status from 'True' to 'False' " ,
29- Long : `Undraft changes the content's draft status from 'True' to 'False'
28+ Short : "Undraft resets the content's draft status" ,
29+ Long : `Undraft resets the content's draft status
3030and updates the date to the current date and time.
3131If the content's draft status is 'False', nothing is done.` ,
3232 RunE : Undraft ,
138138 for _ , v := range fmLines {
139139 pos := bytes .Index (v , []byte ("draft" ))
140140 if pos != - 1 {
141- v = bytes .Replace (v , []byte ("true" ), []byte ("false" ), 1 )
142- goto write
141+ continue
143142 }
144143 pos = bytes .Index (v , []byte ("date" ))
145144 if pos != - 1 { // if date field wasn't found, add it
146145 v = bytes .Replace (v , []byte (date ), []byte (time .Now ().Format (time .RFC3339 )), 1 )
147146 }
148- write:
149147 buff .Write (v )
150148 buff .Write (lineEnding )
151149 }
Original file line number Diff line number Diff line change @@ -25,12 +25,13 @@ import (
2525)
2626
2727var (
28- jsonFM = "{\n \" date\" : \" 12-04-06\" ,\n \" title\" : \" test json\" \n }"
29- jsonDraftFM = "{\n \" draft\" : true,\n \" date\" : \" 12-04-06\" ,\n \" title\" :\" test json\" \n }"
30- tomlFM = "+++\n date= \" 12-04-06\" \n title= \" test toml\" \n +++"
31- tomlDraftFM = "+++\n draft= true\n date= \" 12-04-06\" \n title=\" test toml\" \n +++"
32- yamlFM = "---\n date: \" 12-04-06\" \n title: \" test yaml\" \n ---"
33- yamlDraftFM = "---\n draft: true\n date: \" 12-04-06\" \n title: \" test yaml\" \n ---"
28+ jsonFM = "{\n \" date\" : \" 12-04-06\" ,\n \" title\" : \" test json\" \n }"
29+ jsonDraftFM = "{\n \" draft\" : true,\n \" date\" : \" 12-04-06\" ,\n \" title\" :\" test json\" \n }"
30+ tomlFM = "+++\n date= \" 12-04-06\" \n title= \" test toml\" \n +++"
31+ tomlDraftFM = "+++\n draft= true\n date= \" 12-04-06\" \n title=\" test toml\" \n +++"
32+ yamlFM = "---\n date: \" 12-04-06\" \n title: \" test yaml\" \n ---"
33+ yamlDraftFM = "---\n draft: true\n date: \" 12-04-06\" \n title: \" test yaml\" \n ---"
34+ yamlYesDraftFM = "---\n draft: yes\n date: \" 12-04-06\" \n title: \" test yaml\" \n ---"
3435)
3536
3637func TestUndraftContent (t * testing.T ) {
@@ -44,6 +45,7 @@ func TestUndraftContent(t *testing.T) {
4445 {tomlDraftFM , "" },
4546 {yamlFM , "not a Draft: nothing was done" },
4647 {yamlDraftFM , "" },
48+ {yamlYesDraftFM , "" },
4749 }
4850
4951 for i , test := range tests {
You can’t perform that action at this time.
0 commit comments