diff --git a/packages/starlight-ghostcms/package.json b/packages/starlight-ghostcms/package.json index 889b77dd..7d7af059 100644 --- a/packages/starlight-ghostcms/package.json +++ b/packages/starlight-ghostcms/package.json @@ -63,6 +63,7 @@ "vitest-fetch-mock": "^0.2.2" }, "dependencies": { + "@astrojs/rss": "^4.0.5", "@ts-ghost/core-api": "^5.1.2", "vite": "^5.1.2", "vite-tsconfig-paths": "^4.2.2" diff --git a/packages/starlight-ghostcms/src/routes/rss.xml.ts b/packages/starlight-ghostcms/src/routes/rss.xml.ts new file mode 100644 index 00000000..d82cb944 --- /dev/null +++ b/packages/starlight-ghostcms/src/routes/rss.xml.ts @@ -0,0 +1,25 @@ +import rss from "@astrojs/rss"; +import type { APIContext } from "astro"; +import { getAllPosts } from "../utils/api"; + +const posts = await getAllPosts(); +import config from 'virtual:starlight-ghost-config' + +export async function GET({ site }: APIContext) { + const title = config.title; + const description = config.rssDescription; + return rss({ + title: title, + description: description, + site: site, + items: posts.map((post) => ({ + title: post.title, + pubDate: new Date( + post.published_at ? post.published_at : post.created_at, + ), + description: post.excerpt, + link: `/blog/${post.slug}/`, + author: post.primary_author?.name, + })), + }); +} diff --git a/packages/starlight-ghostcms/src/schemas/config.ts b/packages/starlight-ghostcms/src/schemas/config.ts index 0421a092..5b4b770c 100644 --- a/packages/starlight-ghostcms/src/schemas/config.ts +++ b/packages/starlight-ghostcms/src/schemas/config.ts @@ -15,6 +15,10 @@ const configSchema = z * The title of the blog. */ title: z.string().default('Blog'), + /** + * The description of the blog on the RSS Feed. + */ + rssDescription: z.string(), /** * Turn on and off "Powered by Ghost" */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d0c2ec52..6d3f2040 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -304,6 +304,9 @@ importers: packages/starlight-ghostcms: dependencies: + '@astrojs/rss': + specifier: ^4.0.5 + version: 4.0.5 '@ts-ghost/core-api': specifier: ^5.1.2 version: 5.1.2