Browse Source

Support writing the ids back to the file

Lucas Stadler 9 years ago
parent
commit
1075290002
1 changed files with 19 additions and 0 deletions
  1. 19 0
      go/blog/blog.go

+ 19 - 0
go/blog/blog.go

@ -4,6 +4,7 @@ import (
4 4
	"crypto/md5"
5 5
	"crypto/rand"
6 6
	"encoding/hex"
7
	"flag"
7 8
	"fmt"
8 9
	"html/template"
9 10
	"io"
@ -22,7 +23,17 @@ type Post struct {
22 23
	Type    string `yaml:"type"`
23 24
}
24 25
26
var flags struct {
27
	writeBack bool
28
}
29
30
func init() {
31
	flag.BoolVar(&flags.writeBack, "write-back", false, "Rewrite the YAML file with the generated ids")
32
}
33
25 34
func main() {
35
	flag.Parse()
36
26 37
	f, err := os.Open("blog.yaml")
27 38
	if err != nil {
28 39
		exit(err)
@ -72,6 +83,14 @@ func main() {
72 83
	}
73 84
74 85
	fmt.Printf("\n</body>\n</html>\n")
86
87
	if flags.writeBack {
88
		out, err := yaml.Marshal(posts)
89
		if err != nil {
90
			exit(err)
91
		}
92
		ioutil.WriteFile("blog.yaml", out, 0664)
93
	}
75 94
}
76 95
77 96
var funcs = template.FuncMap{