From: Andrew Zenk Date: Wed, 2 Dec 2020 11:53:53 +0000 (-0600) Subject: tpl: Add title parameter to YouTube shortcode X-Git-Tag: v0.80.0~28 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=4fc918e02cfc7f260d6312248ff9d33e95b27943;p=brevno-suite%2Fhugo tpl: Add title parameter to YouTube shortcode --- diff --git a/docs/content/en/content-management/shortcodes.md b/docs/content/en/content-management/shortcodes.md index a298bc42..2b4d0d63 100644 --- a/docs/content/en/content-management/shortcodes.md +++ b/docs/content/en/content-management/shortcodes.md @@ -398,6 +398,13 @@ Furthermore, you can automatically start playback of the embedded video by setti {{}} {{< /code >}} +For [accessibility reasons](https://dequeuniversity.com/tips/provide-iframe-titles), it's best to provide a title for your YouTube video. You can do this using the shortcode by providing a `title` parameter. If no title is provided, a default of "YouTube Video" will be used. + +{{< code file="example-youtube-input-with-title.md" >}} +{{}} +{{< /code >}} + + #### Example `youtube` Output Using the preceding `youtube` example, the following HTML will be added to your rendered website's markup: diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go index a998b85b..b8acb2d8 100644 --- a/hugolib/embedded_shortcodes_test.go +++ b/hugolib/embedded_shortcodes_test.go @@ -184,6 +184,11 @@ func TestShortcodeYoutube(t *testing.T) { `{{< youtube id="w7Ft2ymGmfc" class="video" autoplay="true" >}}`, "(?s)\n
.*?.*?
", }, + // set custom title for accessability) + { + `{{< youtube id="w7Ft2ymGmfc" title="A New Hugo Site in Under Two Minutes" >}}`, + "(?s)\n
.*?.*?
", + }, } { var ( cfg, fs = newTestCfg() diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index 1bed5142..3af86cb6 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -531,12 +531,12 @@ if (!doNotTrack) { {{- if not $pc.Disable -}} {{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} {{- $id := .Get "id" | default (.Get 0) -}} -{{- $class := .Get "class" | default (.Get 1) }} +{{- $class := .Get "class" | default (.Get 1) -}} +{{- $title := .Get "title" | default "YouTube Video" }}
- +
-{{ end -}} -`}, +{{ end -}}`}, {`twitter_cards.html`, `{{- with $.Params.images -}} diff --git a/tpl/tplimpl/embedded/templates/shortcodes/youtube.html b/tpl/tplimpl/embedded/templates/shortcodes/youtube.html index 9e847765..93fed232 100644 --- a/tpl/tplimpl/embedded/templates/shortcodes/youtube.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/youtube.html @@ -2,8 +2,9 @@ {{- if not $pc.Disable -}} {{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} {{- $id := .Get "id" | default (.Get 0) -}} -{{- $class := .Get "class" | default (.Get 1) }} +{{- $class := .Get "class" | default (.Get 1) -}} +{{- $title := .Get "title" | default "YouTube Video" }}
- +
{{ end -}}