|
|
@ -242,6 +242,9 @@ func main() {
|
|
242
|
242
|
case (u.Host == "youtube.com" || u.Host == "www.youtube.com") && u.Query().Get("v") != "":
|
|
243
|
243
|
provider = "youtube"
|
|
244
|
244
|
post.URL = fmt.Sprintf("https://www.youtube.com/embed/%s", u.Query().Get("v"))
|
|
|
245
|
case u.Host == "vimeo.com" && getVimeoId(u.Path) != "":
|
|
|
246
|
provider = "vimeo"
|
|
|
247
|
post.URL = fmt.Sprintf("https://player.vimeo.com/video/%s", getVimeoId(u.Path))
|
|
245
|
248
|
default:
|
|
246
|
249
|
exit(fmt.Errorf("unsupported video url '%s'", post.URL))
|
|
247
|
250
|
}
|
|
|
@ -547,9 +550,9 @@ var textTmpl = template.Must(baseTmpl.New("text").
|
|
547
|
550
|
var videoTmpl = template.Must(baseTmpl.New("video").Parse(`
|
|
548
|
551
|
<article id="{{ .Id }}" class="{{ .Type }}" {{- if .Tags }} data-tags="{{ json .Tags }}"{{ end }}>
|
|
549
|
552
|
{{- template "title" . }}
|
|
550
|
|
{{ if (eq .Provider "youtube") -}}
|
|
|
553
|
{{ if (eq .Provider "youtube" "vimeo") -}}
|
|
551
|
554
|
<iframe width="560" height="315" src="{{ safe_url .URL }}" frameborder="0" allowfullscreen></iframe>
|
|
552
|
|
{{- else -}}
|
|
|
555
|
{{- else if (eq .Provider "native") -}}
|
|
553
|
556
|
<video src="{{ safe_url .URL }}" controls></video>
|
|
554
|
557
|
{{- end }}
|
|
555
|
558
|
{{- if .Content }}
|
|
|
@ -638,3 +641,12 @@ func toSlug(s string) string {
|
|
638
|
641
|
}, s)
|
|
639
|
642
|
return strings.Trim(s, "-")
|
|
640
|
643
|
}
|
|
|
644
|
|
|
|
645
|
func getVimeoId(p string) string {
|
|
|
646
|
i := strings.LastIndex(p, "/")
|
|
|
647
|
if i == -1 || len(p) == i+1 {
|
|
|
648
|
return ""
|
|
|
649
|
}
|
|
|
650
|
|
|
|
651
|
return p[i+1:]
|
|
|
652
|
}
|