From f7816e69a6ffd40ee4dc939bdf157e901cbdcae5 Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Tue, 5 Mar 2024 20:24:59 -0800 Subject: [PATCH] cleanup starlight-ghostcms code --- packages/starlight-ghostcms/README.md | 4 +- packages/starlight-ghostcms/index.ts | 46 ++++------ packages/starlight-ghostcms/package.json | 4 +- .../src/integrations/vite.ts | 4 +- .../src/overrides/Sidebar.astro | 2 +- .../src/routes/[slug].astro | 2 +- .../starlight-ghostcms/src/routes/about.astro | 2 +- .../src/routes/authors.astro | 2 +- .../starlight-ghostcms/src/routes/index.astro | 2 +- .../starlight-ghostcms/src/routes/rss.xml.ts | 2 +- .../starlight-ghostcms/src/schemas/config.ts | 15 ++++ .../src/utils/api/ghostAPI.ts | 4 + packages/starlight-ghostcms/tsconfig.json | 30 +------ packages/starlight-ghostcms/virtual.d.ts | 4 +- .../starlight-playground/astro.config.mjs | 1 + pnpm-lock.yaml | 90 +++++++++++++++++-- 16 files changed, 138 insertions(+), 76 deletions(-) diff --git a/packages/starlight-ghostcms/README.md b/packages/starlight-ghostcms/README.md index bcd4ada5..a756b101 100644 --- a/packages/starlight-ghostcms/README.md +++ b/packages/starlight-ghostcms/README.md @@ -48,7 +48,9 @@ import starlightGhostCMS from '@matthiesenxyz/starlight-ghostcms'; export default defineConfig({ integrations: [ starlight({ - plugins: [starlightGhostCMS()], + plugins: [ + starlightGhostCMS() + ], title: 'My Docs', }), ], diff --git a/packages/starlight-ghostcms/index.ts b/packages/starlight-ghostcms/index.ts index 66d719f2..ff69284b 100644 --- a/packages/starlight-ghostcms/index.ts +++ b/packages/starlight-ghostcms/index.ts @@ -30,6 +30,7 @@ export default function starlightGhostCMS( logger, updateConfig: updateStarlightConfig, }) { + // Update the Starlight config with the GhostCMS config updateStarlightConfig({ social: { ...starlightConfig.social, @@ -57,47 +58,36 @@ export default function starlightGhostCMS( }, }); + // Add the Starlight-GhostCMS integration addIntegration({ name: "@matthiesenxyz/starlight-ghostcms", hooks: { "astro:config:setup": ({ injectRoute, updateConfig }) => { - injectRoute({ - pattern: "/blog", - entrypoint: - "@matthiesenxyz/starlight-ghostcms/routes/index.astro", - prerender: true, - }); - injectRoute({ - pattern: "/blog/[slug]", - entrypoint: - "@matthiesenxyz/starlight-ghostcms/routes/[slug].astro", - prerender: true, - }); - injectRoute({ - pattern: "/blog/about", - entrypoint: - "@matthiesenxyz/starlight-ghostcms/routes/about.astro", - prerender: true, - }); - injectRoute({ - pattern: "/blog/authors", - entrypoint: - "@matthiesenxyz/starlight-ghostcms/routes/authors.astro", - }); - injectRoute({ - pattern: "/rss.xml", - entrypoint: - "@matthiesenxyz/starlight-ghostcms/routes/rss.xml.ts", - }); updateConfig({ vite: { plugins: [vitePluginStarlightGhostConfig(config)], }, }); + + const makeRoute = (endpoint: string, entrypoint: string) => { + injectRoute({ + pattern: `/${endpoint}`, + entrypoint: `@matthiesenxyz/starlight-ghostcms/routes/${entrypoint}`, + prerender: true, + }); + }; + + makeRoute("blog", "index.astro"); + makeRoute("blog/[slug]", "[slug].astro"); + makeRoute("blog/about", "about.astro"); + makeRoute("blog/authors", "authors.astro"); + makeRoute("rss.xml", "rss.xml.ts"); + }, }, }); + }, }, }; diff --git a/packages/starlight-ghostcms/package.json b/packages/starlight-ghostcms/package.json index 58820694..b72f5d63 100644 --- a/packages/starlight-ghostcms/package.json +++ b/packages/starlight-ghostcms/package.json @@ -60,7 +60,7 @@ }, "devDependencies": { "@astrojs/starlight": "^0.19.0", - "astro": "^4.4.0", + "astro": "^4.4.1", "vitest": "^1.3.1", "vitest-fetch-mock": "^0.2.2" }, @@ -73,6 +73,6 @@ }, "peerDependencies": { "@astrojs/starlight": ">=0.19.0", - "astro": ">=4.4.0" + "astro": ">=4.4.1" } } diff --git a/packages/starlight-ghostcms/src/integrations/vite.ts b/packages/starlight-ghostcms/src/integrations/vite.ts index eff6ca08..c48797a6 100644 --- a/packages/starlight-ghostcms/src/integrations/vite.ts +++ b/packages/starlight-ghostcms/src/integrations/vite.ts @@ -6,12 +6,12 @@ import type { StarlightGhostConfig } from "../schemas/config.ts"; export function vitePluginStarlightGhostConfig( config: StarlightGhostConfig, ): VitePlugin { - const moduleId = "virtual:starlight-ghost-config"; + const moduleId = 'virtual:starlight-ghostcms/config'; const resolvedModuleId = `\0${moduleId}`; const moduleContent = `export default ${JSON.stringify(config)}`; return { - name: "vite-plugin-starlight-ghost-config", + name: "vite-plugin-starlight-ghostcms-config", load(id) { return id === resolvedModuleId ? moduleContent : undefined; }, diff --git a/packages/starlight-ghostcms/src/overrides/Sidebar.astro b/packages/starlight-ghostcms/src/overrides/Sidebar.astro index 5319d41a..ffc8f358 100644 --- a/packages/starlight-ghostcms/src/overrides/Sidebar.astro +++ b/packages/starlight-ghostcms/src/overrides/Sidebar.astro @@ -1,7 +1,7 @@ --- import StarlightSidebar from '@astrojs/starlight/components/Sidebar.astro' import type { Props } from '@astrojs/starlight/props' -import config from 'virtual:starlight-ghost-config' +import config from 'virtual:starlight-ghostcms/config' import { isBlogPostPage, isBlogRoot } from '../utils/page' import { getAllPages, getAllPosts, getSluggedPage } from '../utils/api' import type { SidebarEntry } from './sidebartypes' diff --git a/packages/starlight-ghostcms/src/routes/[slug].astro b/packages/starlight-ghostcms/src/routes/[slug].astro index 6ae03dd2..c7ce65e2 100644 --- a/packages/starlight-ghostcms/src/routes/[slug].astro +++ b/packages/starlight-ghostcms/src/routes/[slug].astro @@ -1,5 +1,5 @@ --- -import config from 'virtual:starlight-ghost-config' +import config from 'virtual:starlight-ghostcms/config' import { Image } from "astro:assets"; import Page from '../components/Page.astro' import { getPageProps } from '../utils/page' diff --git a/packages/starlight-ghostcms/src/routes/about.astro b/packages/starlight-ghostcms/src/routes/about.astro index c4a2b1fa..0eabf65d 100644 --- a/packages/starlight-ghostcms/src/routes/about.astro +++ b/packages/starlight-ghostcms/src/routes/about.astro @@ -1,5 +1,5 @@ --- -import config from 'virtual:starlight-ghost-config' +import config from 'virtual:starlight-ghostcms/config' import Metadata from '../components/Metadata.astro' import Page from '../components/Page.astro' //import PrevNextLinks from '../components/PrevNextLinks.astro' diff --git a/packages/starlight-ghostcms/src/routes/authors.astro b/packages/starlight-ghostcms/src/routes/authors.astro index f446ef52..d8c88103 100644 --- a/packages/starlight-ghostcms/src/routes/authors.astro +++ b/packages/starlight-ghostcms/src/routes/authors.astro @@ -1,5 +1,5 @@ --- -import config from 'virtual:starlight-ghost-config' +import config from 'virtual:starlight-ghostcms/config' import Page from '../components/Page.astro' //import PrevNextLinks from '../components/PrevNextLinks.astro' import { getAllAuthors } from '../utils/api' diff --git a/packages/starlight-ghostcms/src/routes/index.astro b/packages/starlight-ghostcms/src/routes/index.astro index dea5b647..56d89342 100644 --- a/packages/starlight-ghostcms/src/routes/index.astro +++ b/packages/starlight-ghostcms/src/routes/index.astro @@ -1,6 +1,6 @@ --- //import type { InferGetStaticPropsType } from 'astro' -import config from 'virtual:starlight-ghost-config' +import config from 'virtual:starlight-ghostcms/config' import Page from '../components/Page.astro' import Posts from '../components/Posts.astro' diff --git a/packages/starlight-ghostcms/src/routes/rss.xml.ts b/packages/starlight-ghostcms/src/routes/rss.xml.ts index 6781f1ae..1955fb73 100644 --- a/packages/starlight-ghostcms/src/routes/rss.xml.ts +++ b/packages/starlight-ghostcms/src/routes/rss.xml.ts @@ -5,7 +5,7 @@ import { getAllPosts, getSettings, invariant } from "../utils/api"; const posts = await getAllPosts(); const settings = await getSettings(); -import config from "virtual:starlight-ghost-config"; +import config from "virtual:starlight-ghostcms/config"; export async function GET({ site }: APIContext) { invariant(settings, "Settings is not defined"); diff --git a/packages/starlight-ghostcms/src/schemas/config.ts b/packages/starlight-ghostcms/src/schemas/config.ts index b2f617df..19c55fd8 100644 --- a/packages/starlight-ghostcms/src/schemas/config.ts +++ b/packages/starlight-ghostcms/src/schemas/config.ts @@ -3,6 +3,21 @@ import { z } from "astro/zod"; const configSchema = z .object({ + /** OPTIONAL - Either set the URL in your .env or put it here + * @example + * // https://astro.build/config + * export default defineConfig({ + * integrations: [ + * starlight({ + * plugins: [ + * starlightGhost({ + * ghostURL: "https://ghostdemo.matthiesen.xyz" + * }) + * ], + * }) + * ], + * }); */ + ghostURL: z.string().url("Must be a URL").optional(), /** * The number of blog posts to display per page in the blog post list. */ diff --git a/packages/starlight-ghostcms/src/utils/api/ghostAPI.ts b/packages/starlight-ghostcms/src/utils/api/ghostAPI.ts index 784f2f6a..db629d25 100644 --- a/packages/starlight-ghostcms/src/utils/api/ghostAPI.ts +++ b/packages/starlight-ghostcms/src/utils/api/ghostAPI.ts @@ -3,6 +3,7 @@ import type { Page, Post } from "./schemas"; // LOAD ENVIRONMENT VARIABLES import { loadEnv } from "vite"; +//import StarlightGhostConfig from "virtual:starlight-ghostcms/config"; const { CONTENT_API_KEY, CONTENT_API_URL } = loadEnv( "all", @@ -10,6 +11,9 @@ const { CONTENT_API_KEY, CONTENT_API_URL } = loadEnv( "CONTENT_", ); + +//const ConfURL = StarlightGhostConfig.ghostURL || ""; + // SETUP GHOST API const ghostApiKey = CONTENT_API_KEY || ""; const ghostUrl = CONTENT_API_URL || ""; diff --git a/packages/starlight-ghostcms/tsconfig.json b/packages/starlight-ghostcms/tsconfig.json index 73727041..77da9dd0 100644 --- a/packages/starlight-ghostcms/tsconfig.json +++ b/packages/starlight-ghostcms/tsconfig.json @@ -1,29 +1,3 @@ { - "$schema": "https://json.schemastore.org/tsconfig", - "compilerOptions": { - "allowSyntheticDefaultImports": true, - "allowUnreachableCode": false, - "allowUnusedLabels": false, - "esModuleInterop": true, - "exactOptionalPropertyTypes": true, - "forceConsistentCasingInFileNames": true, - "incremental": true, - "jsx": "react-jsx", - "lib": ["DOM", "DOM.Iterable", "ESNext"], - "module": "ESNext", - "moduleResolution": "bundler", - "noFallthroughCasesInSwitch": true, - "noImplicitOverride": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "strict": true, - "target": "ESNext", - "useDefineForClassFields": true, - "verbatimModuleSyntax": true - } - } \ No newline at end of file + "extends": "astro/tsconfigs/strict" +} \ No newline at end of file diff --git a/packages/starlight-ghostcms/virtual.d.ts b/packages/starlight-ghostcms/virtual.d.ts index 5f5ef663..1667ac7b 100644 --- a/packages/starlight-ghostcms/virtual.d.ts +++ b/packages/starlight-ghostcms/virtual.d.ts @@ -1,5 +1,5 @@ -declare module "virtual:starlight-ghost-config" { - const StarlightGhostConfig: import("./src/schemas/config").StarlightGhostConfig; +declare module "virtual:starlight-ghostcms/config" { + const StarlightGhostConfig: import("./src/schemas/config.ts").StarlightGhostConfig; export default StarlightGhostConfig; } diff --git a/playgrounds/starlight-playground/astro.config.mjs b/playgrounds/starlight-playground/astro.config.mjs index 391a2f20..b5c80711 100644 --- a/playgrounds/starlight-playground/astro.config.mjs +++ b/playgrounds/starlight-playground/astro.config.mjs @@ -10,6 +10,7 @@ export default defineConfig({ title: "My Docs", plugins: [ starlightGhostCMS({ + ghostURL: 'https://ghostdemo.matthiesen.xyz', title: "Demo Blog", rssDescription: "Starlight Playground", }), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a119f2f..ca719988 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -262,10 +262,10 @@ importers: devDependencies: '@astrojs/starlight': specifier: ^0.19.0 - version: 0.19.0(astro@4.4.0) + version: 0.19.0(astro@4.4.9) astro: - specifier: ^4.4.0 - version: 4.4.0(typescript@5.3.3) + specifier: ^4.4.1 + version: 4.4.9(@types/node@20.11.24) vitest: specifier: ^1.3.1 version: 1.3.1(@vitest/ui@1.3.1) @@ -453,6 +453,33 @@ packages: vfile: 6.0.1 transitivePeerDependencies: - supports-color + dev: false + + /@astrojs/mdx@2.1.1(astro@4.4.9): + resolution: {integrity: sha512-AgGFdE7HOGmoFooGvMSatkA9FiSKwyVW7ImHot/bXJ6uAbFfu6iG2ht18Cf1pT22Hda/6iSCGWusFvBv0/EnKQ==} + engines: {node: '>=18.14.1'} + peerDependencies: + astro: ^4.0.0 + dependencies: + '@astrojs/markdown-remark': 4.2.1 + '@mdx-js/mdx': 3.0.1 + acorn: 8.11.3 + astro: 4.4.9(@types/node@20.11.24) + es-module-lexer: 1.4.1 + estree-util-visit: 2.0.0 + github-slugger: 2.0.0 + gray-matter: 4.0.3 + hast-util-to-html: 9.0.0 + kleur: 4.1.5 + rehype-raw: 7.0.0 + remark-gfm: 4.0.0 + remark-smartypants: 2.1.0 + source-map: 0.7.4 + unist-util-visit: 5.0.0 + vfile: 6.0.1 + transitivePeerDependencies: + - supports-color + dev: true /@astrojs/prism@3.0.0: resolution: {integrity: sha512-g61lZupWq1bYbcBnYZqdjndShr/J3l/oFobBKPA3+qMat146zce3nz2kdO4giGbhYDt4gYdhmoBz0vZJ4sIurQ==} @@ -499,6 +526,35 @@ packages: vfile: 6.0.1 transitivePeerDependencies: - supports-color + dev: false + + /@astrojs/starlight@0.19.0(astro@4.4.9): + resolution: {integrity: sha512-izNZLs99d4AAoN5eV6Ek71SVKEAs8N/GjT+n9J0Q8q1Zgtk/qcv3KzuPXBZmiAbPl/9E2+BG8f4dpdoc+F4U3g==} + peerDependencies: + astro: ^4.2.7 + dependencies: + '@astrojs/mdx': 2.1.1(astro@4.4.9) + '@astrojs/sitemap': 3.1.1 + '@pagefind/default-ui': 1.0.4 + '@types/hast': 3.0.4 + '@types/mdast': 4.0.3 + astro: 4.4.9(@types/node@20.11.24) + astro-expressive-code: 0.32.4(astro@4.4.9) + bcp-47: 2.1.0 + hast-util-select: 6.0.2 + hastscript: 8.0.0 + mdast-util-directive: 3.0.0 + mdast-util-to-markdown: 2.1.0 + pagefind: 1.0.4 + rehype: 13.0.1 + remark-directive: 3.0.0 + unified: 11.0.4 + unist-util-remove: 4.0.0 + unist-util-visit: 5.0.0 + vfile: 6.0.1 + transitivePeerDependencies: + - supports-color + dev: true /@astrojs/tailwind@5.1.0(astro@4.3.7)(tailwindcss@3.4.1): resolution: {integrity: sha512-BJoCDKuWhU9FT2qYg+fr6Nfb3qP4ShtyjXGHKA/4mHN94z7BGcmauQK23iy+YH5qWvTnhqkd6mQPQ1yTZTe9Ig==} @@ -2642,6 +2698,17 @@ packages: astro: 4.4.0(typescript@5.3.3) hast-util-to-html: 8.0.4 remark-expressive-code: 0.32.4 + dev: false + + /astro-expressive-code@0.32.4(astro@4.4.9): + resolution: {integrity: sha512-/Kq8wLMz0X2gbLWGmPryqEdFV/om/GROsoLtPFqLrLCRD5CpwxXAW185BIGZKf4iYsyJim1vvcpQm5Y9hV5B1g==} + peerDependencies: + astro: ^3.3.0 || ^4.0.0-beta + dependencies: + astro: 4.4.9(@types/node@20.11.24) + hast-util-to-html: 8.0.4 + remark-expressive-code: 0.32.4 + dev: true /astro-font@0.0.77: resolution: {integrity: sha512-dh5TX2uxwqdFq15DF9cbRZgEdE9o8q522MP6xZYs+rnd3dexfDsIJMeEIDNVO7rkRxwJ7sphhCqTmdWvUJaiDg==} @@ -2928,8 +2995,8 @@ packages: tsconfck: 3.0.2(typescript@5.3.3) unist-util-visit: 5.0.0 vfile: 6.0.1 - vite: 5.1.4(@types/node@20.11.24) - vitefu: 0.2.5(vite@5.1.4) + vite: 5.1.5(@types/node@20.11.24) + vitefu: 0.2.5(vite@5.1.5) which-pm: 2.1.1 yargs-parser: 21.1.1 zod: 3.22.4 @@ -2945,7 +3012,6 @@ packages: - supports-color - terser - typescript - dev: false /astrojs-compiler-sync@0.3.5(@astrojs/compiler@2.5.3): resolution: {integrity: sha512-y420rhIIJ2HHDkYeqKArBHSdJNIIGMztLH90KGIX3zjcJyt/cr9Z2wYA8CP5J1w6KE7xqMh0DAkhfjhNDpQb2Q==} @@ -8009,7 +8075,17 @@ packages: vite: optional: true dependencies: - vite: 5.1.4(@types/node@20.11.24) + vite: 5.1.4(sass@1.71.0) + + /vitefu@0.2.5(vite@5.1.5): + resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==} + peerDependencies: + vite: ^3.0.0 || ^4.0.0 || ^5.0.0 + peerDependenciesMeta: + vite: + optional: true + dependencies: + vite: 5.1.5(@types/node@20.11.24) /vitest-fetch-mock@0.2.2(vitest@1.3.1): resolution: {integrity: sha512-XmH6QgTSjCWrqXoPREIdbj40T7i1xnGmAsTAgfckoO75W1IEHKR8hcPCQ7SO16RsdW1t85oUm6pcQRLeBgjVYQ==}