Piraty Ola WayOla and Lillian(8 🏴‍☠️👸)Log InGet started

How to REALLY create an rss feed in astro for mixpod

I did;

  1. npm install @astrojs/rss
  • I’ve configured a site in
// astro.config.mjs
export default defineConfig({
  site: "https://mixpod.app/",
});

  1. Create a file in src/pages/ [playListID].xml.js

The file will create an RSS feed at https://mixpod.app//[playListID].xml.

  1. I imported the rss() helper from the @astrojs/rss package into my [playListID].xml.js file and exported a function that returns it using the following parameters:


export function GET(context) {
  // get the ID for the playlist
  // const playListID = "playlist1";

    // const playList = DB[playListID];
    // get the ID for the playlist from the URL [playListID].xml.js?

  return rss({
    // `<title>` field in output xml
    title: playList.title,
    // `<description>` field in output xml
    description: playList.description,
    site: context.site,
    // Array of `<item>`s in output xml
    // See "Generating items" section for examples using content collections and glob imports
    items: playList.episodes,
    // (optional) inject custom xml
    customData: `<language>en-us</language>`,
  });
}

  1. I created a fake DB
const DB = {
  playlist1: {
    title: "A fabulous MixPod for my friend",
    description: "A humble MixPod",
    episodes: [],
  },
};
  1. I assign a hard coded "playlist1" string to a playlistID variable

  2. and then generate a XML for that playlist with data from the fake DB.

  const playListID = "playlist1";

  const playList = DB[playListID];

The whole file looks like this

// src / pages / [playListID].xml.js


import rss from "@astrojs/rss";

// fake a DB
const DB = {
  playlist1: {
    title: "A fabulous MixPod for my friend",
    description: "A humble MixPod",
    episodes: [],
  },
};

export function GET(context) {
  // get the ID for the playlist
  const playListID = "playlist1";

  const playList = DB[playListID];
  // get the ID for the playlist from the URL [playListID].xml.js?

  return rss({
    // `<title>` field in output xml
    title: playList.title,
    // `<description>` field in output xml
    description: playList.description,
    site: context.site,
    // Array of `<item>`s in output xml
    // See "Generating items" section for examples using content collections and glob imports
    items: playList.episodes,
    // (optional) inject custom xml
    customData: `<language>en-us</language>`,
  });
}


© Lillian (7 🏴‍☠️👸) and Cap'n Ola Vea (43 🏴‍☠️⛵) and their cheerful crew of skill-builder pirates 1554 - 2023