add rss feature
This commit is contained in:
parent
32bab4e4c6
commit
40d6454fee
|
@ -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
|
|
@ -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({
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
*/
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue