跳转至

播客节目栏

播客播放条是一个带封面、标题、播放按钮、进度条和倍速按钮的长条组件,模板是 layouts/_default/episode_bar.html。它出现在两类页面上:播客单集页(content/zh/podcast/ 下的每一期),以及在 front matter 中关联了某期播客的博客文章。播客内容目前只有中文。

在博客文章中关联播客

在文章 front matter 中加入 podcast_episode_url,值是该期播客的内容路径(不带 /zh/ 语言前缀):

---
title: 中国电动汽车的激进崛起:政策驱动、产业变革与全球竞争
podcast_episode_url: /podcast/ep-010-china-ev-rise/
---

layouts/_default/single.html 用这个路径查找同语言的播客页面并渲染播放条;找不到时构建日志会输出 Podcast episode page not found at URL 警告,页面上不显示播放条。

博客文章里的播放条目前不能播放

播放逻辑在 assets/js/audio-player.js 中,而 layouts/partials/js-bundle.html 只在 type 为 podcast 的页面,或 front matter 含 audio 字段的页面打包这个脚本。只设置了 podcast_episode_url 的博客文章会显示播放条,但播放、进度和倍速按钮没有响应;读者可以点击播放条上的标题进入单集页收听。

显示位置

页面 屏幕宽度 位置
播客单集页(layouts/podcast/single.html) 小于 1200px 正文顶部
播客单集页 1200px 及以上 右侧栏,目录上方
博客文章 小于 768px 正文顶部
博客文章 1200px 及以上 右侧栏,目录上方

博客文章在 768px 到 1199px 之间不显示播放条。

单集的 front matter

播放条从播客单集的 front matter 读取以下字段,新建单集时可参考 archetypes/podcast.md:

字段 用途
title(或 linktitle) 播放条标题,链接到单集页
episode_image_url 封面;缺省时用 static/images/banner/default.webp
categories 只取第一项,显示为分类链接
date 显示为发布日期
audio_url 音频地址;缺省时播放条只显示封面和信息,没有播放控件

audio_type、audio_length、duration 不影响播放条:音频类型在模板中固定为 audio/mpeg,时长在浏览器读到音频元数据后才显示。这三个字段供播客 RSS(layouts/podcast/rss.xml)使用。

示例见 content/zh/podcast/ep-001-beijing-car-lottery/index.md。

播放控件

assets/js/audio-player.js 提供的交互:

  • 播放和暂停;开始播放时自动暂停页面上其他正在播放的音频。
  • 点击进度条跳转到对应时间,右侧显示当前时间和总时长。
  • 点击倍速按钮循环切换:1x、1.25x、1.5x、1.75x、2x、0.75x。

样式在 assets/scss/templates/_podcast-episode-bar.scss,其中包含 768px 以下的紧凑布局、侧栏中的窄版布局(.podcast-episode-bar-sidebar)和深色模式。

Apple Podcasts 嵌入

另有一个独立的短代码 layouts/shortcodes/podcast.html,用 iframe 嵌入 Apple Podcasts 的官方播放器,与上面的播放条无关:

{{< podcast episode="1000710025033" >}}
参数 默认值 说明
episode 无 Apple Podcasts 的单集 ID
height 175 iframe 高度,单位 px
show config/_default/podcast.zh.toml 中的 show_id 节目 ID