From 9aa9adb168d0e18849ba38b0a5eace254f6e412b Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Mon, 19 Feb 2024 23:57:58 -0800 Subject: [PATCH] Wow... test is working --- packages/starlight-ghostcms/index.ts | 22 ++++++------------- packages/starlight-ghostcms/package.json | 5 ++--- .../src/overrides/Sidebar.astro | 9 ++++++-- pnpm-lock.yaml | 2 +- starlight-playground/astro.config.mjs | 5 +++++ starlight-playground/package.json | 5 ++++- .../src/pages/testslug/index.astro | 4 ++++ 7 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 starlight-playground/src/pages/testslug/index.astro diff --git a/packages/starlight-ghostcms/index.ts b/packages/starlight-ghostcms/index.ts index cc1c9e20..d96ad064 100644 --- a/packages/starlight-ghostcms/index.ts +++ b/packages/starlight-ghostcms/index.ts @@ -9,34 +9,26 @@ export default function starlightGhostCMS(userConfig?: StarlightGhostConfig): St const config: StarlightGhostConfig = validateConfig(userConfig) return { - name: 'starlight-ghostcms-plugin', + name: '@matthiesenxyz/starlight-ghostcms-plugin', hooks: { setup({ addIntegration, config: starlightConfig, logger, updateConfig: updateStarlightConfig }) { updateStarlightConfig({ components: { ...starlightConfig.components, - ...overrideStarlightComponent(starlightConfig.components, logger, 'MarkdownContent'), - ...overrideStarlightComponent(starlightConfig.components, logger, 'Sidebar'), - ...overrideStarlightComponent(starlightConfig.components, logger, "SiteTitle"), + //...overrideStarlightComponent(starlightConfig.components, logger, 'MarkdownContent'), + //...overrideStarlightComponent(starlightConfig.components, logger, 'Sidebar'), + //...overrideStarlightComponent(starlightConfig.components, logger, "SiteTitle"), } }) addIntegration({ - name: 'starlight-ghostcms', + name: '@matthiesenxyz/starlight-ghostcms', hooks: { 'astro:config:setup': ({ injectRoute, updateConfig }) => { injectRoute({ - pattern: '@matthiesenxyz/starlight-ghostcms/routes/index.astro', - entrypoint: '/blog', - prerender: true, + pattern: '/blog', + entrypoint: '@matthiesenxyz/starlight-ghostcms/routes/index.astro' }) - /** THIS IS NOT READY - * injectRoute({ - * pattern: '@matthiesenxyz/starlight-ghostcms/routes/[slug].astro', - * entrypoint: '/blog/[slug]', - * prerender: true, - * }) - */ updateConfig({ vite: { diff --git a/packages/starlight-ghostcms/package.json b/packages/starlight-ghostcms/package.json index 42086fa8..cbd59096 100644 --- a/packages/starlight-ghostcms/package.json +++ b/packages/starlight-ghostcms/package.json @@ -43,11 +43,10 @@ "exports": { ".": "./index.ts", "./overrides/MarkdownContent.astro": "./src/overrides/MarkdownContent.astro", - "./overrides/Sidebar.astro": "./src/overrides/SideBar.astro", + "./overrides/Sidebar.astro": "./src/overrides/Sidebar.astro", "./overrides/SiteTitle.astro": "./src/overrides/SiteTitle.astro", "./routes/index.astro": "./src/routes/index.astro", - "./schema": "./src/schemas/config.ts", - "./package.json": "./package.json" + "./schema": "./src/schemas/config.ts" }, "scripts": { "test": "vitest run", diff --git a/packages/starlight-ghostcms/src/overrides/Sidebar.astro b/packages/starlight-ghostcms/src/overrides/Sidebar.astro index 884add21..206f2115 100644 --- a/packages/starlight-ghostcms/src/overrides/Sidebar.astro +++ b/packages/starlight-ghostcms/src/overrides/Sidebar.astro @@ -2,7 +2,7 @@ import StarlightSidebar from '@astrojs/starlight/components/Sidebar.astro' import type { Props } from '@astrojs/starlight/props' import config from 'virtual:starlight-ghost-config' -import { isAnyBlogPage, isBlogPostPage, isBlogRoot } from '../utils/page' +import { isBlogPostPage, isBlogRoot } from '../utils/page' import { getAllPosts } from '../utils/api' export async function getRecentBlogEntries(){ @@ -10,7 +10,12 @@ export async function getRecentBlogEntries(){ return entries.slice(0, config.recentPostCount) } -const isBlog = isAnyBlogPage(Astro.props.slug) +export function checkpath(path: string){ + if ( path.slice(0, 5) === "/blog" ){ + return true + } else { return false } +} +const isBlog = checkpath(Astro.url.pathname) const recentEntries = isBlog ? await getRecentBlogEntries() : [] const blogSidebar: Props['sidebar'] = isBlog diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c1f17996..60507622 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -374,7 +374,7 @@ importers: specifier: ^0.19.0 version: 0.19.0(astro@4.3.7) '@matthiesenxyz/starlight-ghostcms': - specifier: workspace:* + specifier: 0.0.1-dev01 version: link:../packages/starlight-ghostcms astro: specifier: ^4.3.7 diff --git a/starlight-playground/astro.config.mjs b/starlight-playground/astro.config.mjs index ec11f355..83f18dcd 100644 --- a/starlight-playground/astro.config.mjs +++ b/starlight-playground/astro.config.mjs @@ -8,6 +8,11 @@ export default defineConfig({ starlight({ title: 'My Docs', plugins: [starlightGhostCMS()], + components: { + Sidebar: '@matthiesenxyz/starlight-ghostcms/overrides/Sidebar.astro', + MarkdownContent: '@matthiesenxyz/starlight-ghostcms/overrides/MarkdownContent.astro', + SiteTitle: '@matthiesenxyz/starlight-ghostcms/overrides/SiteTitle.astro' + }, social: { github: 'https://github.com/withastro/starlight', }, diff --git a/starlight-playground/package.json b/starlight-playground/package.json index 5135021f..f738eb82 100644 --- a/starlight-playground/package.json +++ b/starlight-playground/package.json @@ -11,9 +11,12 @@ "preview": "astro preview", "astro": "astro" }, + "devDependencies": { + "@matthiesenxyz/starlight-ghostcms": "workspace:*" + }, "dependencies": { "@astrojs/starlight": "^0.19.0", - "@matthiesenxyz/starlight-ghostcms": "workspace:*", + "@matthiesenxyz/starlight-ghostcms": "0.0.1-dev01", "astro": "^4.3.7", "sharp": "^0.32.5" } diff --git a/starlight-playground/src/pages/testslug/index.astro b/starlight-playground/src/pages/testslug/index.astro new file mode 100644 index 00000000..55752a14 --- /dev/null +++ b/starlight-playground/src/pages/testslug/index.astro @@ -0,0 +1,4 @@ +--- +console.log(Astro.url.pathname) +--- +hi \ No newline at end of file