|
|
@ -234,12 +234,22 @@ func main() {
|
|
234
|
234
|
if err != nil {
|
|
235
|
235
|
exit(fmt.Errorf("invalid video url '%s'", post.URL))
|
|
236
|
236
|
}
|
|
237
|
|
id := u.Query().Get("v")
|
|
238
|
|
if (u.Host != "youtube.com" && u.Host != "www.youtube.com") || id == "" {
|
|
|
237
|
|
|
|
238
|
var provider string
|
|
|
239
|
switch {
|
|
|
240
|
case strings.HasSuffix(u.Path, ".mp4") || strings.HasSuffix(u.Path, ".ogv"):
|
|
|
241
|
provider = "native"
|
|
|
242
|
case (u.Host == "youtube.com" || u.Host == "www.youtube.com") && u.Query().Get("v") != "":
|
|
|
243
|
provider = "youtube"
|
|
|
244
|
post.URL = fmt.Sprintf("https://www.youtube.com/embed/%s", u.Query().Get("v"))
|
|
|
245
|
default:
|
|
239
|
246
|
exit(fmt.Errorf("unsupported video url '%s'", post.URL))
|
|
240
|
247
|
}
|
|
241
|
|
post.URL = id
|
|
242
|
|
err = videoTmpl.Execute(out, post)
|
|
|
248
|
p := struct {
|
|
|
249
|
Post
|
|
|
250
|
Provider string
|
|
|
251
|
}{post, provider}
|
|
|
252
|
err = videoTmpl.Execute(out, p)
|
|
243
|
253
|
default:
|
|
244
|
254
|
fmt.Fprintf(os.Stderr, "Error: no output for type '%s'\n", post.Type)
|
|
245
|
255
|
os.Exit(1)
|
|
|
@ -537,7 +547,11 @@ var textTmpl = template.Must(baseTmpl.New("text").
|
|
537
|
547
|
var videoTmpl = template.Must(baseTmpl.New("video").Parse(`
|
|
538
|
548
|
<article id="{{ .Id }}" class="{{ .Type }}" {{- if .Tags }} data-tags="{{ json .Tags }}"{{ end }}>
|
|
539
|
549
|
{{- template "title" . }}
|
|
540
|
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/{{ .URL }}" frameborder="0" allowfullscreen></iframe>
|
|
|
550
|
{{ if (eq .Provider "youtube") -}}
|
|
|
551
|
<iframe width="560" height="315" src="{{ safe_url .URL }}" frameborder="0" allowfullscreen></iframe>
|
|
|
552
|
{{- else -}}
|
|
|
553
|
<video src="{{ safe_url .URL }}" controls></video>
|
|
|
554
|
{{- end }}
|
|
541
|
555
|
{{- if .Content }}
|
|
542
|
556
|
|
|
543
|
557
|
{{ markdown .Content }}
|