From 20f4167cff7a460ed36a3443791c508a05786446 Mon Sep 17 00:00:00 2001 From: DaInfLoop Date: Sun, 30 Jun 2024 19:22:41 +0100 Subject: [PATCH] add rss feed for news --- index.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/index.ts b/index.ts index e9283d9..dc3270b 100644 --- a/index.ts +++ b/index.ts @@ -638,6 +638,42 @@ app.action(/change-leaderboard\|.+/, async (ctx) => { }) }) +receiver.router.get('/osu/news.rss', async (req, res) => { + const news = await fetch('https://osu.ppy.sh/api/v2/news').then(res => res.json()); + + const posts = news.news_posts; + + const out = ` + + + osu!news + https://osu.haroon.hackclub.app/home/news + + Latest news on osu! + en-us + 60 + + https://raw.githubusercontent.com/ppy/osu-web/master/public/images/favicon/favicon-32x32.png + osu!news + https://osu.haroon.hackclub.app/home/news + + + ${posts.map((post: any) => +` + ${post.title} + https://osu.haroon.hackclub.app/home/news/${post.slug} + ${post.id} + ${new Date(post.published_at).toLocaleString('en-GB', {timeZone: 'UTC',hour12: false,weekday: 'short',year: 'numeric',month: 'short',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit',}).replace(/(?:(\d),)/, '$1') + ' GMT'} + ${post.preview} + ` + ).join('\n ')} + +`; + + res.contentType("application/rss+xml") + res.send(out) +}) + receiver.router.get('*', (req, res) => { res.redirect(`https://osu.ppy.sh${req.path}`) })