Skip to content

Commit

Permalink
module(youtube): various refactoring and fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Kollitsch <[email protected]>
  • Loading branch information
davidsneighbour committed Nov 22, 2024
1 parent e3384ea commit e9ecbaa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 0 additions & 2 deletions modules/youtube/layouts/partials/func/getYTPreviewUrl.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{{- $config := site.Params.dnb.youtube -}}

{{- $id := . -}}

{{- $url := "https://i.ytimg.com/vi" -}}
{{- if compare.Eq (collections.Index $config "thumbnail_source" | compare.Default 1) 1 -}}
{{- $url = "https://ytimg.googleusercontent.com/vi" -}}
Expand Down
6 changes: 3 additions & 3 deletions modules/youtube/layouts/partials/youtube.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{- $class := .class | compare.Default "" -}}
{{- $title := .title | compare.Default "" -}}
{{- $playlabel := .playlabel | compare.Default "Play video" -}}
{{- $params := .params | compare.Default (partialCached "func/prepareApiParams.html" .) -}}
{{- $params := .params | compare.Default (partials.IncludeCached "func/prepareApiParams.html" .) -}}
{{- $config := site.Params.dnb.youtube -}}
{{- $remoteThumbnail := "" -}}
{{- $thumbnailUrl := partials.IncludeCached "func/getYTPreviewUrl.html" $id $id -}}
Expand Down Expand Up @@ -54,8 +54,8 @@
videoid="{{- $id -}}"
{{ with $jsapi -}}jsapi{{- end }}
{{ with $title -}}
title="{{- . -}}"
{{- end -}}
title="{{- . -}}" {{ end -}}{{- with $playlabel -}}
playlabel="{{- . -}}" {{ end -}}
params="{{- $params -}}"
style="background-image: url('{{- $remoteThumbnail.Permalink -}}');"
>
Expand Down
13 changes: 7 additions & 6 deletions modules/youtube/layouts/shortcodes/youtube.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
- @todo config param for JS inline or via external file
- @todo documentation about $pc.Disable
- @todo fix `title` attribute - does not seem to be working
- @todo implement https://github.com/paulirish/lite-youtube-embed?tab=readme-ov-file#custom-player-parameters

Maybe do the whole implementation via partials.Include that can be reused by the youtube partials.Include and shortcode

Expand All @@ -22,16 +21,18 @@
{{- $id := .Get "id" | compare.Default (.Get 0) -}}
{{- $class := .Get "class" | compare.Default (.Get 1) -}}
{{- $title := .Get "title" | compare.Default (.Get 2) -}}
{{- $params := .Get "params" | compare.Default (partialCached "func/prepareApiParams.html" .) -}}
{{- $playlabel := .Get "playlabel" | compare.Default "Play video" -}}
{{- $params := .Get "params" | compare.Default (partials.IncludeCached "func/prepareApiParams.html" .) -}}
{{- $thumbnailUrl := partials.IncludeCached "func/getYTPreviewUrl.html" $id $id -}}
<div class="shortcode--youtube {{ with $class -}}{{- . -}}{{- end -}}">
<lite-youtube
videoid="{{- $id -}}" {{ with $title -}}
playlabel="{{- . -}}" title="{{- . -}}" {{ end -}}
videoid="{{- $id -}}" {{ with $playlabel -}}
playlabel="{{- . -}}" {{ end -}} {{ with $title -}}
title="{{- . -}}" {{ end -}}
params="{{- $params -}}"
style="background-image: url('{{- $thumbnailUrl.maxres -}}');">
<button type="button" class="lty-playbtn" aria-label="Play video">
{{- with $title -}}<span class="lyt-visually-hidden">{{- . -}}</span>{{- end -}}
<button type="button" class="lty-playbtn" aria-label="{{- $playlabel -}}">
{{- with $playlabel -}}<span class="lyt-visually-hidden">{{- . -}}</span>{{- end -}}
</button>
</lite-youtube>
</div>
Expand Down

0 comments on commit e9ecbaa

Please sign in to comment.