Explorar el Código

Support embedding video using `<video>`

This also prepares us for different providers, e.g. vimeo.
Lucas Stadler %!s(int64=9) %!d(string=hace) años
padre
commit
fad75c67c7
Se han modificado 2 ficheros con 21 adiciones y 5 borrados
  1. 19 5
      go/blog/blog.go
  2. 2 0
      go/blog/blog.yaml

+ 19 - 5
go/blog/blog.go

@ -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 }}

+ 2 - 0
go/blog/blog.yaml

@ -108,3 +108,5 @@
108 108
  date: 2016-09-26
109 109
  tags: [ideas, feature, "author:lu"]
110 110
  type: text
111
- url: file:///home/lu/m/video/films/Over The Garden Wall/OtGW-S01E01.mp4
112
  type: video