Explorar el Código

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 %!s(int64=9) %!d(string=hace) años
padre
commit
3f46284dbe
Se han modificado 1 ficheros con 23 adiciones y 33 borrados
  1. 23 33
      go/blog/blog.go

+ 23 - 33
go/blog/blog.go

@ -192,7 +192,20 @@ var funcs = template.FuncMap{
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 209
	Funcs(funcs).Parse(`
197 210
<article id="{{ .Id }}" class="shell">
198 211
	<header>
@ -207,7 +220,7 @@ var shellTmpl = template.Must(template.New("shell").
207 220
</article>
208 221
`))
209 222
210
var linkTmpl = template.Must(template.New("link").
223
var linkTmpl = template.Must(baseTmpl.New("link").
211 224
	Funcs(funcs).Parse(`
212 225
<article id="{{ .Id }}" class="link">
213 226
	<header>
@ -222,16 +235,10 @@ var linkTmpl = template.Must(template.New("link").
222 235
</article>
223 236
`))
224 237
225
var imageTmpl = template.Must(template.New("image").
238
var imageTmpl = template.Must(baseTmpl.New("image").
226 239
	Funcs(funcs).Parse(`
227 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 242
	<img src="{{ safe_url .URL }}" />
236 243
	{{- if .Content }}
237 244
@ -240,16 +247,10 @@ var imageTmpl = template.Must(template.New("image").
240 247
</article>
241 248
`))
242 249
243
var songTmpl = template.Must(template.New("song").
250
var songTmpl = template.Must(baseTmpl.New("song").
244 251
	Funcs(funcs).Parse(`
245 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 254
	<audio src="{{ safe_url .URL }}" controls>
254 255
		Your browser can't play {{ .URL }}.
255 256
	</audio>
@ -260,14 +261,10 @@ var songTmpl = template.Must(template.New("song").
260 261
</article>
261 262
`))
262 263
263
var textTmpl = template.Must(template.New("text").
264
var textTmpl = template.Must(baseTmpl.New("text").
264 265
	Funcs(funcs).Parse(`
265 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 268
	{{- if .Content }}
272 269
273 270
	{{ markdown .Content }}
@ -275,16 +272,9 @@ var textTmpl = template.Must(template.New("text").
275 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 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 278
	<iframe width="560" height="315" src="https://www.youtube.com/embed/{{ .URL }}" frameborder="0" allowfullscreen></iframe>
289 279
	{{- if .Content }}
290 280