Просмотр исходного кода

Keep the default styles if not specified otherwise

Now `-css` will specify *additional* styles to use, except if the
`-no-default-style` flag is given.

In addition, `-print-default-style` prints the default stylesheet.
Lucas Stadler лет назад: 9
Родитель
Сommit
5e35be9832
1 измененных файлов с 20 добавлено и 7 удалено
  1. 20 7
      go/blog/blog.go

+ 20 - 7
go/blog/blog.go

31
}
31
}
32
32
33
var flags struct {
33
var flags struct {
34
	writeBack bool
35
	hashIds   bool
36
	reverse   bool
37
	css       string
38
	title     string
34
	writeBack         bool
35
	hashIds           bool
36
	reverse           bool
37
	css               string
38
	noDefaultStyle    bool
39
	printDefaultStyle bool
40
	title             string
39
}
41
}
40
var dataPath string = "blog.yaml"
42
var dataPath string = "blog.yaml"
41
43
130
	flag.BoolVar(&flags.writeBack, "write-back", false, "Rewrite the YAML file with the generated ids")
132
	flag.BoolVar(&flags.writeBack, "write-back", false, "Rewrite the YAML file with the generated ids")
131
	flag.BoolVar(&flags.hashIds, "hash-ids", false, "Use hash-based post ids")
133
	flag.BoolVar(&flags.hashIds, "hash-ids", false, "Use hash-based post ids")
132
	flag.BoolVar(&flags.reverse, "reverse", false, "Reverse the order of the articles in the file")
134
	flag.BoolVar(&flags.reverse, "reverse", false, "Reverse the order of the articles in the file")
133
	flag.StringVar(&flags.css, "css", defaultStyle, "Custom `css` styles to use")
135
	flag.StringVar(&flags.css, "css", "", "Use custom `css` styles")
136
	flag.BoolVar(&flags.noDefaultStyle, "no-default-style", false, "Don't use the default styles")
137
	flag.BoolVar(&flags.printDefaultStyle, "print-default-style", false, "Print the default styles")
134
	flag.StringVar(&flags.title, "title", "A blog", "Custom `title` to use")
138
	flag.StringVar(&flags.title, "title", "A blog", "Custom `title` to use")
135
139
136
	flag.Usage = func() {
140
	flag.Usage = func() {
142
func main() {
146
func main() {
143
	flag.Parse()
147
	flag.Parse()
144
148
149
	if flags.printDefaultStyle {
150
		fmt.Print(defaultStyle)
151
		os.Exit(0)
152
	}
153
145
	if flag.NArg() > 0 {
154
	if flag.NArg() > 0 {
146
		dataPath = flag.Arg(0)
155
		dataPath = flag.Arg(0)
147
	}
156
	}
170
		exit(err)
179
		exit(err)
171
	}
180
	}
172
181
182
	if flags.noDefaultStyle {
183
		defaultStyle = ""
184
	}
173
	fmt.Fprintf(out, `<!doctype html>
185
	fmt.Fprintf(out, `<!doctype html>
174
<html>
186
<html>
175
<head>
187
<head>
177
	<meta name="viewport" content="width=device-width, initial-scale=1" />
189
	<meta name="viewport" content="width=device-width, initial-scale=1" />
178
	<title>%s</title>
190
	<title>%s</title>
179
	<style>%s</style>
191
	<style>%s</style>
192
	<style>%s</style>
180
</head>
193
</head>
181
194
182
<body>
195
<body>
183
`, template.HTMLEscapeString(flags.title), flags.css)
196
`, template.HTMLEscapeString(flags.title), defaultStyle, flags.css)
184
197
185
	if flags.reverse {
198
	if flags.reverse {
186
		l := len(posts)
199
		l := len(posts)