Canada has become my second home. Some of the best people that I have met while travelling have been from Canada. That includes my wife!

So for fun, we decided to take a look at the differences between Canada and the United States and try to find out what makes us all American.

However, this project is mostly about integrating audio files with a Gatsby project.

I also designed the log with Inkscape. Pretty proud of that work also.

The audio files are hosted in an AWS bucket, and the RSS feed is generated from the YAML markdown for each episode.

With Gatsby there is a great plugin that takes care of this RSS generation for you. It takes some research into the requirements of which fields are needed to qualify for the various feeds and hosts and blah blah blah…

Here is the setup we went with:

{
  resolve: `gatsby-plugin-feed`,
  options: {
    query: `{
      site {
        siteMetadata {
          title
          description
          siteUrl
          site_url: siteUrl
        }
      }
    }`,
    setup: ({
      query: {
        site: { siteMetadata },
        ...rest
      },
    }) => {
      return {
        ...siteMetadata,
        ...rest,
        custom_namespaces: {
          itunes: 'http://www.itunes.com/dtds/podcast-1.0.dtd',
        },
        custom_elements: [
          {
            'atom:link': {
              _attr: {
                href: siteMetadata.siteUrl + '/rss.xml',
                rel: 'self',
                type: 'application/rss+xml',
              },
            },
          },
          { 'itunes:subtitle': siteMetadata.description },
          {
            'itunes:summary':
              'Ryan is Canadian. Jordan is American. Together, they investigate strange and interesting bits of Canadian culture.',
          },
          {
            image: [
              {
                url:
                  'https://s3-us-west-2.amazonaws.com/canadianborderpatrol.com/data/cpb_logo_1400.png',
              },
              { title: siteMetadata.title },
              { link: siteMetadata.siteUrl },
            ],
          },
          {
            'itunes:image': {
              _attr: {
                href:
                  'https://s3-us-west-2.amazonaws.com/canadianborderpatrol.com/data/cpb_logo_1400.png',
              },
            },
          },
          { 'itunes:author': 'Jordan Rhea; Ryan Oldford' },
          {
            'itunes:category': {
              _attr: {
                text: 'Society & Culture',
              },
            },
          },
          { 'itunes:explicit': 'yes' },
          { language: 'en-us' },
          { copyright: '© 2019 Canadian Border Patrol' },
          {
            'itunes:owner': [
              { 'itunes:name': 'Ryan Oldford' },
              { 'itunes:email': 'ryan.oldford@gmail.com' },
            ],
          },
        ],
      };
    },
    feeds: [
      {
        serialize: ({ query: { site, allMarkdownRemark } }) => {
          return allMarkdownRemark.edges.map(edge => {
            const fullUrl =
              site.siteMetadata.siteUrl + edge.node.fields.slug;
            const shownotesLinkText = `Go to ${fullUrl} for show notes.`;
            const themeSongText =
              'Thanks to The Motorleague(https://www.themotorleague.ca/) for our theme song "North America"!';
            return Object.assign({}, edge.node.frontmatter, {
              title: edge.node.frontmatter.title,
              description: edge.node.html,
              date: edge.node.frontmatter.date,
              url: fullUrl,
              guid: fullUrl,
              enclosure: {
                url: edge.node.frontmatter.url,
                type: 'audio/mpeg',
              },
              custom_elements: [
                { 'content:encoded': {_cdata: edge.node.html }},
                { 'itunes:duration': edge.node.frontmatter.episodeDuration },
                { 'itunes:subtitle': edge.node.excerpt },
                {
                  'itunes:summary':
                    edge.node.excerpt +
                    '\n' +
                    shownotesLinkText +
                    '\n' +
                    themeSongText,
                },
              ],
            });
          });
        },
        query: `
        {
          allMarkdownRemark(
            limit: 1000,
            sort: { order: DESC, fields: [frontmatter___date] }
          ) {
            edges {
              node {
                excerpt
                html
                fields { slug }
                frontmatter {
                  title
                  date
                  url
                  episodeDuration
                }
              }
            }
          }
        }
      `,
        output: '/rss.xml',
        title: 'Canadian Border Patrol',
      },
    ],
  },
}

Check out the code on Github