diff --git a/.changeset/funny-sheep-care.md b/.changeset/funny-sheep-care.md new file mode 100644 index 00000000..96891708 --- /dev/null +++ b/.changeset/funny-sheep-care.md @@ -0,0 +1,5 @@ +--- +"@matthiesenxyz/starlight-ghostcms": patch +--- + +add rss feeds, also adds a link in the socials based on the astro `site` config option diff --git a/packages/starlight-ghostcms/index.ts b/packages/starlight-ghostcms/index.ts index 10d7d42a..ad9f00ae 100644 --- a/packages/starlight-ghostcms/index.ts +++ b/packages/starlight-ghostcms/index.ts @@ -11,8 +11,12 @@ export default function starlightGhostCMS(userConfig?: StarlightGhostConfig): St return { name: '@matthiesenxyz/starlight-ghostcms-plugin', hooks: { - setup({ addIntegration, config: starlightConfig, logger, updateConfig: updateStarlightConfig }) { + setup({ astroConfig, addIntegration, config: starlightConfig, logger, updateConfig: updateStarlightConfig }) { updateStarlightConfig({ + social: { + ...starlightConfig.social, + rss: `${astroConfig.site}/rss.xml` + }, components: { ...starlightConfig.components, ...overrideStarlightComponent(starlightConfig.components, logger, 'MarkdownContent'), @@ -27,11 +31,17 @@ export default function starlightGhostCMS(userConfig?: StarlightGhostConfig): St 'astro:config:setup': ({ injectRoute, updateConfig }) => { injectRoute({ pattern: '/blog', - entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/index.astro' + entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/index.astro', + prerender: true, }) injectRoute({ pattern: '/blog/[slug]', - entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/[slug].astro' + entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/[slug].astro', + prerender: true, + }) + injectRoute({ + pattern: '/rss.xml', + entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/rss.xml.ts' }) updateConfig({ diff --git a/packages/starlight-ghostcms/package.json b/packages/starlight-ghostcms/package.json index 9a2ac17e..81bad2eb 100644 --- a/packages/starlight-ghostcms/package.json +++ b/packages/starlight-ghostcms/package.json @@ -47,6 +47,7 @@ "./overrides/SiteTitle.astro": "./src/overrides/SiteTitle.astro", "./routes/index.astro": "./src/routes/index.astro", "./routes/[slug].astro": "./src/routes/[slug].astro", + "./routes/rss.xml.ts": "./src/routes/rss.xml.ts", "./schema": "./src/schemas/config.ts" }, "scripts": { diff --git a/packages/starlight-ghostcms/src/routes/rss.xml.ts b/packages/starlight-ghostcms/src/routes/rss.xml.ts index d82cb944..9f558ddb 100644 --- a/packages/starlight-ghostcms/src/routes/rss.xml.ts +++ b/packages/starlight-ghostcms/src/routes/rss.xml.ts @@ -1,17 +1,21 @@ import rss from "@astrojs/rss"; import type { APIContext } from "astro"; -import { getAllPosts } from "../utils/api"; +import { getAllPosts, getSettings, invariant } from "../utils/api"; const posts = await getAllPosts(); -import config from 'virtual:starlight-ghost-config' +const settings = await getSettings(); + +import config from 'virtual:starlight-ghost-config'; export async function GET({ site }: APIContext) { + invariant(settings,"Settings is not defined") const title = config.title; const description = config.rssDescription; + const ghostSite = settings.url return rss({ title: title, description: description, - site: site, + site: site?site:ghostSite, items: posts.map((post) => ({ title: post.title, pubDate: new Date( diff --git a/packages/starlight-ghostcms/src/schemas/config.ts b/packages/starlight-ghostcms/src/schemas/config.ts index 5b4b770c..435e794d 100644 --- a/packages/starlight-ghostcms/src/schemas/config.ts +++ b/packages/starlight-ghostcms/src/schemas/config.ts @@ -18,7 +18,7 @@ const configSchema = z /** * The description of the blog on the RSS Feed. */ - rssDescription: z.string(), + rssDescription: z.string().default('My Awesome Starlight-GhostCMS Blog'), /** * Turn on and off "Powered by Ghost" */ diff --git a/starlight-playground/astro.config.mjs b/starlight-playground/astro.config.mjs index ec11f355..30d5f7b5 100644 --- a/starlight-playground/astro.config.mjs +++ b/starlight-playground/astro.config.mjs @@ -4,10 +4,16 @@ import starlightGhostCMS from '@matthiesenxyz/starlight-ghostcms'; // https://astro.build/config export default defineConfig({ + site: "http://localhost:4321", integrations: [ starlight({ title: 'My Docs', - plugins: [starlightGhostCMS()], + plugins: [ + starlightGhostCMS({ + title: "Demo Blog", + rssDescription: "Starlight Playground" + }) + ], social: { github: 'https://github.com/withastro/starlight', },