Skip to main content

Podcaster

Hosting a podcast and creating its website with Eleventy.

Podcaster Blog

Presenting an episode on your site

In my first post a few weeks ago, I showed you a simple way to create a home page for your podcast — by creating a template which loops through the podcastEpisode collection and renders some HTML containing the information for each episode.

Today, I’m going to show you an include file which presents more extensive detail about an episode. This include file can be used by itself on the episode’s dedicated page, but it can also be used as part of a list of episodes — like an index page or a tag page, for example.

An include file like this is sometimes called a partial.


Here’s the code for the partial. It’s a Nunjucks template.

{% if not post %}{% set post = collections.podcastEpisode | getCollectionItem %}{% endif %}
<article>
  {%- if linkInTitle -%}
  <h1><a href="{{ post.url }}">{{ post.data.title | safe }}</a></h1>
  {%- else -%}
  <h1>{{ post.data.title | safe }}</h1>
  {%- endif -%}
  <p class="post-metadata">Episode {{ post.data.episode.episodeNumber }} &middot; {{ post.data.topic | safe }} &middot; {{ post.date | readableDate }}</p>
  {% if excerptOnly %}
    {{ post.data.excerpt | safe }}
  {% else %}
    {{ post.content | safe }}
  {% endif %}
  <figure class="audio">
    <audio controls preload="metadata" src="{{ post.data.episode.url }}"></audio>
    <figcaption>
      Episode {{ post.data.episode.episodeNumber }}: {{ post.data.title }}
      &middot; Recorded on {{ post.data.episode.recordingDate | readableDate }}
      &middot; <a target="_blank" href="{{ post.data.episode.url }}">Download</a> ({{ post.data.episode.size | readableSize(1) }})
    </figcaption>
  </figure>
</article>

Let’s start with that cryptic first line.

{% if not post %}{% set post = collections.podcastEpisode | getCollectionItem %}{% endif %}

This line allows us to use this partial in two different contexts — as part of a list of episodes, or by itself on the episode’s page.

Let’s say we’re looping through some episodes to display a list.

{% for post in collections.podcastEpisode | reverse %}
{% include 'episode.njk' %}
{% endfor %}

When we’re looping through a collection of posts like that, each post is represented by a collection item. If our loop variable is post, we will refer to the post’s date or content as {{ post.date }} or {{ post.content }}, and to its front matter data as {{ post.data.title }} and {{ post.data.topic }}.

When we’re not looping through a collection, we can refer to all that data more simply, as {{ date }}, {{ content }}, {{ title }} and {{ topic }}.

To make this partial usable in both contexts, the partial assumes that it’s dealing with a collection item called post. The first line checks if there’s a post variable defined already. If there is, the partial assumes that we’re in a loop and that that’s the current collection item. If not, it fetches the collection item for the current page from the podcastEpisode collection and assigns that to post.

Note

This means that if you use this partial in a loop, the loop variable must be called post.


Let’s continue.

We put all of the episode’s information inside an <article> element — a single HTML element which we can give its own margins or backgrounds or borders.

Within that element, the first piece of information presented is the title.

{%- if linkInTitle -%}
<h1><a href="{{ post.url }}">{{ post.data.title | safe }}</a></h1>
{%- else -%}
<h1>{{ post.data.title | safe }}</h1>
{%- endif -%}

When this partial is used in a list, we probably want the title to link out to the episode’s dedicated page. To make this happen, we set the linkInTitle variable to true, like this:

----
linkInTitle: true
---
{% for post in collections.podcastEpisode | reverse %}
{% include 'episode.njk' %}
{% endfor %}

After the title, there’s a line of episode metadata: the episode number, the topic and the release date.

And then after that, there’s either the post content, which will contain the episode’s full show notes, or the post excerpt, which is shorter version of the show notes which might be used in a list. The variable excerptOnly determines which.

----
excerptOnly: true
---
{% for post in collections.podcastEpisode | reverse %}
{% include 'episode.njk' %}
{% endfor %}

Excerpts are an optional feature of Podcaster. They’re quite flexible: they have a sensible default, while allowing you to set them how you would like. Here’s how excerpts are explained in the documentation.

After that, there’s an audio player, accompanied by a caption containing the episode number and title, the recording date, and a link for downloading the episode (accompanied by the size of the episode, for the sake of politeness).


And that’s that. The partial presented here is a simplified version of the one I use on the Flight Through Entirety website, so go and take a look at the site’s home page if you want to see it in action.

Describing a podcast episode

Podcasts are an audio medium, of course, but your listeners’ podcast players describe each of your episodes using text — a title, a short description and a long description.

And so Podcaster lets you provide all three of those.

I’ve posted about titles already — so let’s talk about the short and long descriptions.

Short description

Podcaster lets you provide the short description for your episode in the front matter of that episode’s post as episode.description. This is plain text, and podcast players usually show it — or the start of it — in list views.

If you don’t provide episode.description, Podcaster will use the first 800 or so characters — about 150 words — of the long description instead.

Long description

Podcaster takes your episode’s long description from the content of the episode’s post. This is HTML, which means it can include styled text, headings and — most importantly — links, which are just the sort of things you need for an episode’s show notes.

Podcast players differ in how well they present these — but all of the common ones will at least show links and paragraphs correctly.

Customising these descriptions

If you want to customise how episode.description is calculated from the content of your post, or if you want to add additional information to your show notes, Podcaster lets you customise both of these descriptions.

If podcast.episodeDescriptionTemplate exists, it’s assumed to contain the name of a template in your includes directory; the same with podcast.episodeContentTemplate. If those templates exist, they are included in your podcast feed, specifying the short and long descriptions respectively.

Sample templates

Here’s a sample episode description template that reduces the length of the short description to 255 characters. Remember, the short description produced by this template needs to be plain text.

{{ post.content | safe | striptags(true) | truncate(255) }}

And here’s a sample episode content template based on the one from my Star Trek podcast site. It includes the stardate and first broadcast date of the Star Trek episode we discuss in a given podcast episode. The long description produced here is in HTML.

<p>
  <em>
    First broadcast on {{ post.data.starTrek.broadcast | readableDate }}.  
    Stardate: {{ post.data.starTrek.stardate }}.
  </em>
</p>
{{ post.content | safe }}

The episode description template and the episode content template both need to be Nunjucks templates, and both need to refer to the podcast episode’s post as post, using the collection item data structure.


Unnecessary technical detail

Podcaster includes the short description in the feed as the contents of the <itunes:summary> and <description> tags. It includes the long description in the feed as the content of the <content:encoded> tag, inside a CDATA section.

Creating a home page

You can put whatever you want on your podcast site’s home page, but the most obvious and straightforward approach might be to present a list of episodes in reverse chronological order.

Here’s how to do that.

Continue reading…