Trying to create an rss feed in astro for mixpod
I did;
- npm install @astrojs/rss
- I’ve configured a site in
// astro.config.mjs
export default defineConfig({
site: "https://mixpod.app/",
});
- Create a file in src/pages/ [playListID].xml.js
The file will create an RSS feed at https://mixpod.app//[playListID].xml.
- 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>`,
});
}
- I created a fake DB
const DB = {
playlist1: {
title: "A fabulous MixPod for my friend",
description: "A humble MixPod",
episodes: [],
},
};
-
I assign a hard coded "playlist1" string to a playlistID variable
-
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>`,
});
}