diff --git a/data/structures/youtube.yml b/data/structures/youtube.yml index 7493826e..327788e5 100644 --- a/data/structures/youtube.yml +++ b/data/structures/youtube.yml @@ -23,4 +23,12 @@ arguments: type: bool optional: true default: false - comment: Flag indicating the video should start playing immediately when loaded. + comment: >- + Flag indicating the video should start playing immediately when loaded, if + supported by the browser. The audio will be muted. + autotitle: + type: bool + optional: true + default: false + comment: >- + Trigger to retrieve the title from the video metadata. diff --git a/exampleSite/content/en/blog/bootstrap-elements.md b/exampleSite/content/en/blog/bootstrap-elements.md index 5335df37..7cd17ac5 100644 --- a/exampleSite/content/en/blog/bootstrap-elements.md +++ b/exampleSite/content/en/blog/bootstrap-elements.md @@ -466,3 +466,13 @@ As an example, the following shortcode displays a tooltip for a colored hyperlin {{}}Tooltip{{}} demonstration {{< /example >}} + +## Youtube + +As an example, the following shortcode displays a Hugo quickstart guide. + + +{{< example lang="hugo" >}} +{{}} +{{< /example >}} + diff --git a/layouts/shortcodes/youtube.html b/layouts/shortcodes/youtube.html index a873c1c5..86e6fab8 100644 --- a/layouts/shortcodes/youtube.html +++ b/layouts/shortcodes/youtube.html @@ -7,6 +7,8 @@ following modifications: - Isolated the styles to comply with the Content Security Policy - Added validation of shortcode arguments + - Added support to retrieve the title from the video metadata + - Adjusted autoplay configuration - Modified the layout The original source code is available on: @@ -16,26 +18,53 @@ {{- $pc := .Page.Site.Config.Privacy.YouTube -}} {{- if not $pc.Disable -}} - {{ $error := false }} + {{ $error := false }} - - {{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "youtube" "args" .Params) }} - {{ errorf "Invalid arguments: %s" .Position -}} - {{ $error = true }} - {{ end }} + + {{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "youtube" "args" .Params) }} + {{ errorf "Invalid arguments: %s" .Position -}} + {{ $error = true }} + {{ end }} + + + {{- $id := "" -}} + {{- $class := "" -}} + {{- $title := "YouTube Video" }} + {{- $autoplay := false }} + {{- $autotitle := false }} + {{- $host := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} + + {{- if .IsNamedParams }} + {{ with .Get "id" }}{{ $id = . }}{{ end }} + {{ with .Get "class" }}{{ $class = . }}{{ end }} + {{ with .Get "title" }}{{ $title = . }}{{ end }} + {{ if isset .Params "autoplay" }}{{ $autoplay = partial "utilities/CastBool.html" (.Get "autoplay") }}{{ end -}} + {{ if isset .Params "autotitle" }}{{ $autotitle = partial "utilities/CastBool.html" (.Get "autotitle") }}{{ end -}} + {{ else }} + {{- $id = .Get 0 -}} + {{- $class = .Get 1 -}} + {{ end }} - - {{- $id := .Get "id" | default (.Get 0) -}} - {{- $class := .Get "class" | default (.Get 1) -}} - {{- $title := .Get "title" | default "YouTube Video" }} - {{- $autoplay := false }} - {{ with .Get "autoplay" }}{{ $autoplay = partial "utilities/CastBool.html" . }}{{ end -}} - {{- $host := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} - - -
- -
+ {{ end -}} \ No newline at end of file