Bladeren bron

Add permalinks to all articles

They're not pretty (enough) yet, but kinda neat.  Maybe they should be
at the end of the article, though.  Or more to the side, so that media
posts without titles look better.
Lucas Stadler 9 jaren geleden
bovenliggende
commit
3f46284dbe
1 gewijzigde bestanden met toevoegingen van 23 en 33 verwijderingen
  1. 23 33
      go/blog/blog.go

+ 23 - 33
go/blog/blog.go

192
	},
192
	},
193
}
193
}
194
194
195
var shellTmpl = template.Must(template.New("shell").
195
var baseTmpl = template.Must(template.New("base").
196
	Funcs(funcs).Parse(`
197
{{ define "title" }}
198
	<header>
199
		{{- if .Title }}
200
		<h1>{{ .Title }}</h1>{{ end }}
201
		<a class="permalink" href="#{{ .Id }}">∞</a>
202
		{{- if .Date }}
203
		<time>{{ .Date }}</time>{{ end }}
204
	</header>
205
{{ end }}
206
`))
207
208
var shellTmpl = template.Must(baseTmpl.New("shell").
196
	Funcs(funcs).Parse(`
209
	Funcs(funcs).Parse(`
197
<article id="{{ .Id }}" class="shell">
210
<article id="{{ .Id }}" class="shell">
198
	<header>
211
	<header>
207
</article>
220
</article>
208
`))
221
`))
209
222
210
var linkTmpl = template.Must(template.New("link").
223
var linkTmpl = template.Must(baseTmpl.New("link").
211
	Funcs(funcs).Parse(`
224
	Funcs(funcs).Parse(`
212
<article id="{{ .Id }}" class="link">
225
<article id="{{ .Id }}" class="link">
213
	<header>
226
	<header>
222
</article>
235
</article>
223
`))
236
`))
224
237
225
var imageTmpl = template.Must(template.New("image").
238
var imageTmpl = template.Must(baseTmpl.New("image").
226
	Funcs(funcs).Parse(`
239
	Funcs(funcs).Parse(`
227
<article id="{{ .Id }}" class="image">
240
<article id="{{ .Id }}" class="image">
228
	{{- if .Title }}
229
	<header>
230
		<h1>{{ .Title }}</h1>
231
		<a class="permalink" href="#{{ .Id }}">∞</a>
232
		{{- if .Date }}<time>{{ .Date }}</time>{{ end -}}
233
	</header>
234
	{{- end }}
241
	{{- template "title" . }}
235
	<img src="{{ safe_url .URL }}" />
242
	<img src="{{ safe_url .URL }}" />
236
	{{- if .Content }}
243
	{{- if .Content }}
237
244
240
</article>
247
</article>
241
`))
248
`))
242
249
243
var songTmpl = template.Must(template.New("song").
250
var songTmpl = template.Must(baseTmpl.New("song").
244
	Funcs(funcs).Parse(`
251
	Funcs(funcs).Parse(`
245
<article id="{{ .Id }}" class="song">
252
<article id="{{ .Id }}" class="song">
246
	{{- if .Title }}
247
	<header>
248
		<h1>{{ .Title }}</h1>
249
		<a class="permalink" href="#{{ .Id }}">∞</a>
250
		{{- if .Date }}<time>{{ .Date }}</time>{{ end -}}
251
	</header>
252
	{{- end }}
253
	{{- template "title" . }}
253
	<audio src="{{ safe_url .URL }}" controls>
254
	<audio src="{{ safe_url .URL }}" controls>
254
		Your browser can't play {{ .URL }}.
255
		Your browser can't play {{ .URL }}.
255
	</audio>
256
	</audio>
260
</article>
261
</article>
261
`))
262
`))
262
263
263
var textTmpl = template.Must(template.New("text").
264
var textTmpl = template.Must(baseTmpl.New("text").
264
	Funcs(funcs).Parse(`
265
	Funcs(funcs).Parse(`
265
<article id="{{ .Id }}" class="text">
266
<article id="{{ .Id }}" class="text">
266
	<header>
267
		<h1>{{ .Title }}</h1>
268
		<a class="permalink" href="#{{ .Id }}">∞</a>
269
		{{- if .Date }}<time>{{ .Date }}</time>{{ end -}}
270
	</header>
267
	{{- template "title" . }}
271
	{{- if .Content }}
268
	{{- if .Content }}
272
269
273
	{{ markdown .Content }}
270
	{{ markdown .Content }}
275
</article>
272
</article>
276
`))
273
`))
277
274
278
var videoTmpl = template.Must(template.New("video").
279
	Funcs(funcs).Parse(`
275
var videoTmpl = template.Must(baseTmpl.Parse(`
280
<article id="{{ .Id }}" class="video">
276
<article id="{{ .Id }}" class="video">
281
	{{- if .Title }}
282
	<header>
283
		<h1>{{ .Title }}</h1>
284
		<a class="permalink" href="#{{ .Id }}">∞</a>
285
		{{- if .Date }}<time>{{ .Date }}</time>{{ end -}}
286
	</header>
287
	{{- end }}
277
	{{- template "title" . }}
288
	<iframe width="560" height="315" src="https://www.youtube.com/embed/{{ .URL }}" frameborder="0" allowfullscreen></iframe>
278
	<iframe width="560" height="315" src="https://www.youtube.com/embed/{{ .URL }}" frameborder="0" allowfullscreen></iframe>
289
	{{- if .Content }}
279
	{{- if .Content }}
290
280