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 {
|
return {
|
||||||
name: '@matthiesenxyz/starlight-ghostcms-plugin',
|
name: '@matthiesenxyz/starlight-ghostcms-plugin',
|
||||||
hooks: {
|
hooks: {
|
||||||
setup({ addIntegration, config: starlightConfig, logger, updateConfig: updateStarlightConfig }) {
|
setup({ astroConfig, addIntegration, config: starlightConfig, logger, updateConfig: updateStarlightConfig }) {
|
||||||
updateStarlightConfig({
|
updateStarlightConfig({
|
||||||
|
social: {
|
||||||
|
...starlightConfig.social,
|
||||||
|
rss: `${astroConfig.site}/rss.xml`
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
...starlightConfig.components,
|
...starlightConfig.components,
|
||||||
...overrideStarlightComponent(starlightConfig.components, logger, 'MarkdownContent'),
|
...overrideStarlightComponent(starlightConfig.components, logger, 'MarkdownContent'),
|
||||||
|
@ -27,11 +31,17 @@ export default function starlightGhostCMS(userConfig?: StarlightGhostConfig): St
|
||||||
'astro:config:setup': ({ injectRoute, updateConfig }) => {
|
'astro:config:setup': ({ injectRoute, updateConfig }) => {
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/blog',
|
pattern: '/blog',
|
||||||
entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/index.astro'
|
entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/index.astro',
|
||||||
|
prerender: true,
|
||||||
})
|
})
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/blog/[slug]',
|
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({
|
updateConfig({
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
"./overrides/SiteTitle.astro": "./src/overrides/SiteTitle.astro",
|
"./overrides/SiteTitle.astro": "./src/overrides/SiteTitle.astro",
|
||||||
"./routes/index.astro": "./src/routes/index.astro",
|
"./routes/index.astro": "./src/routes/index.astro",
|
||||||
"./routes/[slug].astro": "./src/routes/[slug].astro",
|
"./routes/[slug].astro": "./src/routes/[slug].astro",
|
||||||
|
"./routes/rss.xml.ts": "./src/routes/rss.xml.ts",
|
||||||
"./schema": "./src/schemas/config.ts"
|
"./schema": "./src/schemas/config.ts"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
import rss from "@astrojs/rss";
|
import rss from "@astrojs/rss";
|
||||||
import type { APIContext } from "astro";
|
import type { APIContext } from "astro";
|
||||||
import { getAllPosts } from "../utils/api";
|
import { getAllPosts, getSettings, invariant } from "../utils/api";
|
||||||
|
|
||||||
const posts = await getAllPosts();
|
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) {
|
export async function GET({ site }: APIContext) {
|
||||||
|
invariant(settings,"Settings is not defined")
|
||||||
const title = config.title;
|
const title = config.title;
|
||||||
const description = config.rssDescription;
|
const description = config.rssDescription;
|
||||||
|
const ghostSite = settings.url
|
||||||
return rss({
|
return rss({
|
||||||
title: title,
|
title: title,
|
||||||
description: description,
|
description: description,
|
||||||
site: site,
|
site: site?site:ghostSite,
|
||||||
items: posts.map((post) => ({
|
items: posts.map((post) => ({
|
||||||
title: post.title,
|
title: post.title,
|
||||||
pubDate: new Date(
|
pubDate: new Date(
|
||||||
|
|
|
@ -18,7 +18,7 @@ const configSchema = z
|
||||||
/**
|
/**
|
||||||
* The description of the blog on the RSS Feed.
|
* 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"
|
* Turn on and off "Powered by Ghost"
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,10 +4,16 @@ import starlightGhostCMS from '@matthiesenxyz/starlight-ghostcms';
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
site: "http://localhost:4321",
|
||||||
integrations: [
|
integrations: [
|
||||||
starlight({
|
starlight({
|
||||||
title: 'My Docs',
|
title: 'My Docs',
|
||||||
plugins: [starlightGhostCMS()],
|
plugins: [
|
||||||
|
starlightGhostCMS({
|
||||||
|
title: "Demo Blog",
|
||||||
|
rssDescription: "Starlight Playground"
|
||||||
|
})
|
||||||
|
],
|
||||||
social: {
|
social: {
|
||||||
github: 'https://github.com/withastro/starlight',
|
github: 'https://github.com/withastro/starlight',
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue