From: digitalcraftsman <digitalcraftsman@users.noreply.github.com>
Date: Sat, 16 Jan 2016 17:49:18 +0000 (+0100)
Subject: Add autostart option to YouTube shortcode
X-Git-Tag: v0.16~399
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=cd36d752a3e8e2b75965fe281e6466d7a274cd94;p=brevno-suite%2Fhugo

Add autostart option to YouTube shortcode
---

diff --git a/docs/content/extras/shortcodes.md b/docs/content/extras/shortcodes.md
index 4d1303ff..a09923dd 100644
--- a/docs/content/extras/shortcodes.md
+++ b/docs/content/extras/shortcodes.md
@@ -182,6 +182,11 @@ Copy the ID from behind `v=` and pass it the shortcode:
 
     {{</* youtube w7Ft2ymGmfc */>}} 
 
+Furthermore, you can autostart the embedded video by setting the `autostart` parameter to true. Remember that you can't mix named an unamed parameters. Assign the yet unamed video id to the parameter `id` like below too.
+
+     {{</* youtube id="w7Ft2ymGmfc" autoplay="true" */>}}
+
+
 ### Vimeo
 
 Adding a video from [Vimeo](https://vimeo.com/) is equivalent to the YouTube shortcode above. Extract the ID from the URL, e.g.:
diff --git a/tpl/template_embedded.go b/tpl/template_embedded.go
index 14364f6d..53f5c0f5 100644
--- a/tpl/template_embedded.go
+++ b/tpl/template_embedded.go
@@ -44,7 +44,8 @@ func (t *GoHTMLTemplate) EmbedShortcodes() {
 	t.AddInternalShortcode("speakerdeck.html", "<script async class='speakerdeck-embed' data-id='{{ index .Params 0 }}' data-ratio='1.33333333333333' src='//speakerdeck.com/assets/embed.js'></script>")
 	t.AddInternalShortcode("youtube.html", `{{ if .IsNamedParams }}
 <div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
-  <iframe src="//www.youtube.com/embed/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0"></iframe>
+  <iframe src="//www.youtube.com/embed/{{ .Get "id" }}?{{ with .Get "autoplay" }}{{ if eq . "true" }}autoplay=1{{ end }}{{ end }}" 
+  {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0"></iframe>
 </div>{{ else }}
 <div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
   <iframe src="//www.youtube.com/embed/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0"></iframe>