From bc116abb51744257704ea23afbb0d624f2f759fa Mon Sep 17 00:00:00 2001 From: Sat Naing Date: Wed, 14 Sep 2022 01:46:20 +0630 Subject: [PATCH] Generate rss items with rss feed object --- src/pages/rss.xml.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/pages/rss.xml.ts diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts new file mode 100644 index 0000000..ac7465b --- /dev/null +++ b/src/pages/rss.xml.ts @@ -0,0 +1,24 @@ +import rss from "@astrojs/rss"; +import type { Frontmatter } from "@utils/types"; +import type { MarkdownInstance } from "astro"; + +const postImportResult = import.meta.glob>( + "../contents/*.md", + { + eager: true, + } +); +const posts = Object.values(postImportResult); + +export const get = () => + rss({ + title: import.meta.env.PUBLIC_SITE_TITLE, + description: import.meta.env.PUBLIC_SITE_DESC, + site: import.meta.env.SITE, + items: posts.map(({ frontmatter }) => ({ + link: frontmatter.slug, + title: frontmatter.title, + description: frontmatter.description, + pubDate: new Date(frontmatter.datetime), + })), + });