add rss feature

This commit is contained in:
Adam Matthiesen 2024-02-21 05:36:27 -08:00
parent 32bab4e4c6
commit 40d6454fee
6 changed files with 34 additions and 8 deletions

View File

@ -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

View File

@ -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({

View File

@ -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": {

View File

@ -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(

View File

@ -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"
*/

View File

@ -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',
},