mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
Implement RSS feed
This commit is contained in:
parent
da702af0fe
commit
7152dba919
5 changed files with 199 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import icon from 'astro-icon'
|
|||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
site: 'https://beta.sittingonclouds.net',
|
||||
i18n: {
|
||||
locales: languageTags,
|
||||
defaultLocale: 'en',
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
"@apollo/client": "^3.11.4",
|
||||
"@astrojs/check": "^0.9.2",
|
||||
"@astrojs/node": "^8.3.2",
|
||||
"@astrojs/rss": "^4.0.7",
|
||||
"@astrojs/tailwind": "^5.1.0",
|
||||
"@auth/core": "^0.32.0",
|
||||
"@eddeee888/gcg-typescript-resolver-files": "^0.10.4",
|
||||
|
|
|
|||
141
public/rss/pretty-feed-v3.xsl
Normal file
141
public/rss/pretty-feed-v3.xsl
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -25,6 +25,13 @@ import '@/styles/global.css'
|
|||
<meta property='og:image' content='/img/assets/clouds_thumb.png' />
|
||||
<meta name='generator' content={Astro.generator} />
|
||||
<meta charset='utf-8' />
|
||||
|
||||
<link
|
||||
rel='alternate'
|
||||
type='application/rss+xml'
|
||||
title='Sitting on Clouds'
|
||||
href={new URL('rss.xml', Astro.site)}
|
||||
/>
|
||||
</head>
|
||||
<body class='flex flex-col min-h-full m-0 color-'>
|
||||
<Header />
|
||||
|
|
|
|||
49
src/pages/rss.xml.ts
Normal file
49
src/pages/rss.xml.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue