如何在hugo网站中嵌入YouTube播放列表

Nar*_*sia 3 hugo hugo-shortcode

我可以使用以下代码,{{< youtube hvWSg6NblSU >}}将 YouTube 视频嵌入hugo 网站,其中 hvWSg6NblSU 是以下网址中的值:https://www.youtube.com/watch ?v=hvWSg6NblSU

我不想嵌入单个视频,而是嵌入以下播放列表:https://www.youtube.com/playlist? list=PLDe3_HhjV1foHQbtGpdo0FSmsMrVykuKJ

问题:有没有办法可以嵌入上述播放列表。基本上我正在尝试使用 Hugo 制作一个页面,它将在 YouTube 上显示播放列表。

在以下链接中:https://naresh-chaurasia.github.io/talk2naresh/course/python-kids/,我有一个 YouTube 视频,但想使用 Hugo 添加到整个播放列表的链接。是否可以。

虽然我可以创建播放列表的超链接,但我想显示 YouTube 播放列表。

谢谢。

小智 5

内置的 YouTube 短代码不支持它。

您可以做的是为播放列表创建一个新的 YouTube 短代码。

脚步

  1. 创造:/layouts/shortcodes/youtubepl.html
  2. 在该文件中放置以下内容:(基于内置的 YouTube 简码
{{- $pc := .Page.Site.Config.Privacy.YouTube -}}
{{- 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) -}}
{{- $title := .Get "title" | default "YouTube Video" }}
<div {{ with $class }}class="{{ . }}"{{ else }}style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"{{ end }}>
  <iframe src="https://{{ $ytHost }}/embed/videoseries?list={{ $id }}{{ with .Get "autoplay" }}{{ if eq . "true" }}&autoplay=1{{ end }}{{ end }}" {{ if not $class }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" {{ end }}allowfullscreen title="{{ $title }}"></iframe>
</div>
{{ end -}}
Run Code Online (Sandbox Code Playgroud)

(旁白:如果您喜欢使用不同的短代码名称,只需更改文件名即可。例如,如果您喜欢使用,{{< ytplaylist >}}请将短代码文件名更改为ytplaylist.html。)

用法

  • 用法与内置{{< youtube >}}简码相同,只需使用新的简码名称,如下所示:{{< youtubepl id="ID-HERE" >}}{{< youtubepl ID-HERE >}}
  • 您将使用播放列表 ID,而不是视频 ID。