Sfoglia il codice sorgente

Add a flag to reverse the order of the posts

Lucas Stadler 9 anni fa
parent
commit
62cb860145
1 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. 11 0
      go/blog/blog.go

+ 11 - 0
go/blog/blog.go

25
25
26
var flags struct {
26
var flags struct {
27
	writeBack bool
27
	writeBack bool
28
	reverse   bool
28
}
29
}
29
var dataPath string = "blog.yaml"
30
var dataPath string = "blog.yaml"
30
31
31
func init() {
32
func init() {
32
	flag.BoolVar(&flags.writeBack, "write-back", false, "Rewrite the YAML file with the generated ids")
33
	flag.BoolVar(&flags.writeBack, "write-back", false, "Rewrite the YAML file with the generated ids")
34
	flag.BoolVar(&flags.reverse, "reverse", false, "Reverse the order of the articles in the file")
33
}
35
}
34
36
35
func main() {
37
func main() {
65
<body>
67
<body>
66
`)
68
`)
67
69
70
	if flags.reverse {
71
		l := len(posts)
72
		reversePosts := make([]Post, l)
73
		for i := 0; i < l; i++ {
74
			reversePosts[i] = posts[l-i-1]
75
		}
76
		posts = reversePosts
77
	}
78
68
	for i, post := range posts {
79
	for i, post := range posts {
69
		if post.Id == "" {
80
		if post.Id == "" {
70
			posts[i].Id = generateId(post)
81
			posts[i].Id = generateId(post)