Skip to content

Commit

Permalink
fix: sort rss feed from latest to oldest (#38)
Browse files Browse the repository at this point in the history
* 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 <satnaingdev@gmail.com>
  • Loading branch information
saif71 and satnaing committed Mar 17, 2023
1 parent 69b39fe commit 9e62b63
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/pages/rss.xml.ts
Original file line number Diff line number Diff line change
@@ -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),
})),
});
}

0 comments on commit 9e62b63

Please sign in to comment.