Lucas Stadler лет назад: 9
Родитель
Сommit
17cd1c9b1d
2 измененных файлов с 34 добавлено и 0 удалено
  1. 31 0
      go/blog/blog.go
  2. 3 0
      go/blog/blog.yaml

+ 31 - 0
go/blog/blog.go

33
var dataPath string = "blog.yaml"
33
var dataPath string = "blog.yaml"
34
34
35
var defaultStyle = `
35
var defaultStyle = `
36
article {
37
	margin-bottom: 1em;
38
}
39
36
article header {
40
article header {
37
	display: flex;
41
	display: flex;
38
	align-items: center;
42
	align-items: center;
46
article time {
50
article time {
47
	color: #666;
51
	color: #666;
48
}
52
}
53
54
article img {
55
	max-width: 80vw;
56
	max-height: 50vh;
57
}
49
`
58
`
50
59
51
func init() {
60
func init() {
110
			err = shellTmpl.Execute(os.Stdout, post)
119
			err = shellTmpl.Execute(os.Stdout, post)
111
		case "link":
120
		case "link":
112
			err = linkTmpl.Execute(os.Stdout, post)
121
			err = linkTmpl.Execute(os.Stdout, post)
122
		case "image":
123
			err = imageTmpl.Execute(os.Stdout, post)
113
		default:
124
		default:
114
			fmt.Fprintf(os.Stderr, "Error: no output for type '%s'\n", post.Type)
125
			fmt.Fprintf(os.Stderr, "Error: no output for type '%s'\n", post.Type)
115
			os.Exit(1)
126
			os.Exit(1)
134
	"markdown": func(markdown string) template.HTML {
145
	"markdown": func(markdown string) template.HTML {
135
		return template.HTML(blackfriday.MarkdownCommon([]byte(markdown)))
146
		return template.HTML(blackfriday.MarkdownCommon([]byte(markdown)))
136
	},
147
	},
148
	"safe_url": func(s string) template.URL {
149
		return template.URL(s)
150
	},
137
}
151
}
138
152
139
var shellTmpl = template.Must(template.New("shell").
153
var shellTmpl = template.Must(template.New("shell").
164
</article>
178
</article>
165
`))
179
`))
166
180
181
var imageTmpl = template.Must(template.New("image").
182
	Funcs(funcs).Parse(`
183
<article id="{{ .Id }}" class="image">
184
	{{- if .Title }}
185
	<header>
186
		<h1>{{ .Title }}</h1>
187
		{{- if .Date }}<time>{{ .Date }}</time>{{ end -}}
188
	</header>
189
	{{- end }}
190
	<img src="{{ safe_url .URL }}" />
191
	{{- if .Content }}
192
193
	{{ markdown .Content }}
194
	{{- end -}}
195
</article>
196
`))
197
167
func exit(err error) {
198
func exit(err error) {
168
	fmt.Fprintf(os.Stderr, "Error: %s\n", err)
199
	fmt.Fprintf(os.Stderr, "Error: %s\n", err)
169
	os.Exit(1)
200
	os.Exit(1)

+ 3 - 0
go/blog/blog.yaml

11
  content: Unfortunately, the ones for 2016 are missing.  I'm not sure if there will be video, I haven't found anything official so far.
11
  content: Unfortunately, the ones for 2016 are missing.  I'm not sure if there will be video, I haven't found anything official so far.
12
  date: "2016-09-24"
12
  date: "2016-09-24"
13
  type: link
13
  type: link
14
- url: file:///home/lu/m/pictures/inspiration/empartridge-anything.jpg
15
  content: By [@empartridge](http://empartridge.tumblr.com).
16
  type: image