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
	"crypto/md5"
4
	"crypto/md5"
5
	"crypto/rand"
5
	"crypto/rand"
6
	"encoding/hex"
6
	"encoding/hex"
7
	"flag"
7
	"fmt"
8
	"fmt"
8
	"html/template"
9
	"html/template"
9
	"io"
10
	"io"
22
	Type    string `yaml:"type"`
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
func main() {
34
func main() {
35
	flag.Parse()
36
26
	f, err := os.Open("blog.yaml")
37
	f, err := os.Open("blog.yaml")
27
	if err != nil {
38
	if err != nil {
28
		exit(err)
39
		exit(err)
72
	}
83
	}
73
84
74
	fmt.Printf("\n</body>\n</html>\n")
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
var funcs = template.FuncMap{
96
var funcs = template.FuncMap{