From 9e62b637e8ddb65f5f274fd0154191212dda0590 Mon Sep 17 00:00:00 2001 From: Salman Hossain Saif Date: Fri, 17 Mar 2023 12:44:10 +0600 Subject: [PATCH] fix: sort rss feed from latest to oldest (#38) * Sorted the rss feed from latest to oldest. Which is crucial for RSS readers. * sorted rss using util func * refactor: remove redundant draft filter and update import positions --------- Co-authored-by: Saif71 <> Co-authored-by: Sat Naing --- src/pages/rss.xml.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index e9d77fb2d..368eb0ea8 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -1,19 +1,22 @@ import rss from "@astrojs/rss"; import { getCollection } from "astro:content"; -import { SITE } from "@config"; +import getSortedPosts from "@utils/getSortedPosts"; import slugify from "@utils/slugify"; +import { SITE } from "@config"; export async function get() { - const posts = await getCollection("blog", ({ data }) => !data.draft); + const posts = await getCollection("blog"); + const sortedPosts = getSortedPosts(posts); return rss({ title: SITE.title, description: SITE.desc, site: SITE.website, - items: posts.map(({ data }) => ({ - link: `posts/${slugify(data)}`, - title: data.title, - description: data.description, - pubDate: new Date(data.pubDatetime), - })), + items: sortedPosts + .map(({ data }) => ({ + link: `posts/${slugify(data)}`, + title: data.title, + description: data.description, + pubDate: new Date(data.pubDatetime), + })), }); }