Implement RSS feed

This commit is contained in:
Jorge Vargas 2024-08-27 21:10:39 -06:00
parent da702af0fe
commit 7152dba919
5 changed files with 199 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import icon from 'astro-icon'
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
site: 'https://beta.sittingonclouds.net',
i18n: { i18n: {
locales: languageTags, locales: languageTags,
defaultLocale: 'en', defaultLocale: 'en',

View file

@ -17,6 +17,7 @@
"@apollo/client": "^3.11.4", "@apollo/client": "^3.11.4",
"@astrojs/check": "^0.9.2", "@astrojs/check": "^0.9.2",
"@astrojs/node": "^8.3.2", "@astrojs/node": "^8.3.2",
"@astrojs/rss": "^4.0.7",
"@astrojs/tailwind": "^5.1.0", "@astrojs/tailwind": "^5.1.0",
"@auth/core": "^0.32.0", "@auth/core": "^0.32.0",
"@eddeee888/gcg-typescript-resolver-files": "^0.10.4", "@eddeee888/gcg-typescript-resolver-files": "^0.10.4",

File diff suppressed because one or more lines are too long

View file

@ -25,6 +25,13 @@ import '@/styles/global.css'
<meta property='og:image' content='/img/assets/clouds_thumb.png' /> <meta property='og:image' content='/img/assets/clouds_thumb.png' />
<meta name='generator' content={Astro.generator} /> <meta name='generator' content={Astro.generator} />
<meta charset='utf-8' /> <meta charset='utf-8' />
<link
rel='alternate'
type='application/rss+xml'
title='Sitting on Clouds'
href={new URL('rss.xml', Astro.site)}
/>
</head> </head>
<body class='flex flex-col min-h-full m-0 color-'> <body class='flex flex-col min-h-full m-0 color-'>
<Header /> <Header />

49
src/pages/rss.xml.ts Normal file
View file

@ -0,0 +1,49 @@
import rss, { type RSSFeedItem } from '@astrojs/rss';
import type { APIContext } from 'astro';
// @ts-ignore
import { Op } from 'sequelize'
import db from '@/sequelize';
export async function GET(context: APIContext) {
const date = new Date()
date.setDate(date.getDate() - 8)
const isoDate = date.toISOString()
const limitDate = `${isoDate.split('T')[0]}T00:00:00Z`
const commonArgs = { include: [db.models.artist], order: [['createdAt', 'DESC']] }
let albums = await db.models.album.findAll({ where: { createdAt: { [Op.gte]: limitDate } }, ...commonArgs })
if (albums.length < 15) albums = await db.models.album.findAll({ limit: 15, ...commonArgs })
const items: RSSFeedItem[] = albums.map((album: any) => {
const { dataValues } = album
const item: RSSFeedItem = {
title: dataValues.title,
pubDate: dataValues.createdAt,
description: dataValues.subTitle || dataValues.artists.map((a: { name: string }) => a.name).join(' - '),
link: `https://www.sittingonclouds.net/album/${dataValues.id}`,
customData: `<media:content
type="image/png"
width="100"
height="100"
medium="image"
url="https://cdn.sittingonclouds.net/album/${dataValues.id}.png" />
`,
}
return item
})
return rss({
xmlns: {
media: "http://search.yahoo.com/mrss/",
},
stylesheet: '/rss/pretty-feed-v3.xsl',
title: 'Sitting on Clouds',
description: 'High Quality soundtrack library',
site: context.site as unknown as string,
trailingSlash: false,
items,
});
}