Skip to content

Commit

Permalink
feat: add playlist RSS
Browse files Browse the repository at this point in the history
  • Loading branch information
alangumer committed Dec 20, 2024
1 parent cffbed5 commit 0fa72f6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
16 changes: 9 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/containers/library/playlist/detail.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ query getPlaylistPageData($id: ID!) {
}
}
}

query getPlaylistFeedData($id: ID!) {
playlist(id: $id) {
id
title
summary
recordings(offset: 0, first: 1500) {
nodes {
...generateFeed
}
}
}
}
6 changes: 5 additions & 1 deletion src/containers/library/playlist/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ function PlaylistDetail({ playlist }: Must<IPlaylistDetailProps>): JSX.Element {
/>
) : (
<ButtonShare
shareUrl={`https://audioverse.org/${languageRoute}/playlists/${id}`}
shareUrl={root.lang(languageRoute).playlists.playlist(id).get()}
rssUrl={root
.lang(languageRoute)
.playlists.playlist(id)
.feed.get()}
backgroundColor={BaseColors.CREAM}
light={true}
contentType="PLAYLIST"
Expand Down
1 change: 1 addition & 0 deletions src/lib/routes/playlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import node from './primatives/node';
const playlists = (r: string) => ({
playlist: (playlistId: string | number) =>
node(`${r}/${playlistId}`, (r) => ({
feed: node(`${r}/feed.xml`),
items: (canonicalPath: string) =>
node(`${r}/items/${canonicalPath.split('/').slice(3).join('/')}`),
})),
Expand Down
50 changes: 50 additions & 0 deletions src/pages/[language]/playlists/[playlist]/feed.xml/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';

import { generateFeed, sendRSSHeaders } from '~lib/generateFeed';
import { getPlaylistFeedData } from '~src/containers/library/playlist/__generated__/detail';
import root from '~src/lib/routes';

export default (): void => void 0;

export async function getServerSideProps({
params,
res,
}: GetServerSidePropsContext<{ language: string; playlist: string }>): Promise<
GetServerSidePropsResult<Record<string, unknown>>
> {
const id = params?.playlist as string;
const languageRoute = params?.language as string;

const { playlist } = await getPlaylistFeedData({
id,
}).catch(() => ({
playlist: null,
}));

if (!playlist) {
return {
notFound: true,
};
}

if (res) {
sendRSSHeaders(res);

const feed = await generateFeed(
languageRoute,
{
link: root.lang(languageRoute).playlists.playlist(id).get(),
title: playlist.title,
description: playlist.summary,
},
playlist.recordings.nodes || [],
);
res.write(feed);

res.end();
}

return {
props: {},
};
}

0 comments on commit 0fa72f6

Please sign in to comment.