new theme feature
This commit is contained in:
parent
19385ec6e5
commit
913f9fa824
59
index.ts
59
index.ts
|
@ -1,6 +1,8 @@
|
||||||
import type { AstroIntegration } from "astro"
|
import type { AstroIntegration } from "astro"
|
||||||
|
import { SafeParseError, SafeParseSuccess, ZodError } from "astro/zod"
|
||||||
|
import { UserConfigSchema, type UserConfig } from "./src/utils/UserConfigSchema"
|
||||||
|
|
||||||
export default function GhostCMS(): AstroIntegration {
|
export default function GhostCMS(options: UserConfig): AstroIntegration {
|
||||||
return {
|
return {
|
||||||
name: '@matthiesenxyz/astro-ghostcms',
|
name: '@matthiesenxyz/astro-ghostcms',
|
||||||
hooks: {
|
hooks: {
|
||||||
|
@ -8,69 +10,68 @@ export default function GhostCMS(): AstroIntegration {
|
||||||
injectRoute,
|
injectRoute,
|
||||||
logger,
|
logger,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
|
const o = UserConfigSchema.safeParse(options || {}) as SafeParseSuccess<UserConfig>
|
||||||
|
|
||||||
|
if (!o.success) {
|
||||||
|
const validationError = fromZodError((o as unknown as SafeParseError<UserConfig>).error)
|
||||||
|
|
||||||
|
logger.error(`Config Error - ${ validationError }`)
|
||||||
|
|
||||||
|
throw validationError
|
||||||
|
}
|
||||||
|
|
||||||
|
const entry = o.data.theme
|
||||||
|
|
||||||
logger.info("Injecting Route: /")
|
logger.info("Injecting Route: /")
|
||||||
|
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/',
|
pattern: '/',
|
||||||
entrypoint: '@matthiesenxyz/astro-ghostcms/index.astro'
|
entrypoint: `${entry}/index.astro`
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.info("Injecting Route: /[slug]")
|
logger.info("Injecting Route: /[slug]")
|
||||||
|
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/[slug]',
|
pattern: '/[slug]',
|
||||||
entrypoint: '@matthiesenxyz/astro-ghostcms/[slug].astro'
|
entrypoint: `${entry}/[slug].astro`
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.info("Injecting Route: /tags")
|
logger.info("Injecting Route: /tags")
|
||||||
|
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/tags',
|
pattern: '/tags',
|
||||||
entrypoint: '@matthiesenxyz/astro-ghostcms/tags.astro'
|
entrypoint: `${entry}/tags.astro`
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.info("Injecting Route: /authors")
|
logger.info("Injecting Route: /authors")
|
||||||
|
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/authors',
|
pattern: '/authors',
|
||||||
entrypoint: '@matthiesenxyz/astro-ghostcms/authors.astro'
|
entrypoint: `${entry}/authors.astro`
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.info("Injecting Route: /tag/[slug]")
|
logger.info("Injecting Route: /tag/[slug]")
|
||||||
|
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/tag/[slug]',
|
pattern: '/tag/[slug]',
|
||||||
entrypoint: '@matthiesenxyz/astro-ghostcms/tag/[slug].astro'
|
entrypoint: `${entry}/tag/[slug].astro`
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.info("Injecting Route: /author/[slug]")
|
logger.info("Injecting Route: /author/[slug]")
|
||||||
|
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/author/[slug]',
|
pattern: '/author/[slug]',
|
||||||
entrypoint: '@matthiesenxyz/astro-ghostcms/author/[slug].astro'
|
entrypoint: `${entry}/author/[slug].astro`
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.info("Injecting Route: /archives/[...page]")
|
logger.info("Injecting Route: /archives/[...page]")
|
||||||
|
|
||||||
injectRoute({
|
injectRoute({
|
||||||
pattern: '/archives/[...page]',
|
pattern: '/archives/[...page]',
|
||||||
entrypoint: '@matthiesenxyz/astro-ghostcms/archives/[...page].astro'
|
entrypoint: `${entry}/archives/[...page].astro`
|
||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
'astro:config:done': async ({
|
'astro:config:done': async ({ logger }) => {
|
||||||
config,
|
logger.info('GhostCMS Routes Injected. Integration is now ready.')
|
||||||
logger,
|
|
||||||
}) => {
|
|
||||||
if (config.output === "server"){
|
|
||||||
logger.error("This integration is not yet ready to be used in 'output: server' mode, to prevent issues please switch to static.")
|
|
||||||
} else if (config.output === "hybrid"){
|
|
||||||
logger.error("This integration is not yet ready to be used in 'output: hybrid' mode, to prevent issues please switch to static.")
|
|
||||||
}else {
|
|
||||||
logger.info('GhostCMS Routes Injected. Integration is now ready.')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fromZodError(error: ZodError<{ theme: string }>) {
|
||||||
|
throw new Error("Function not implemented.")
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { z } from 'astro/zod';
|
||||||
|
|
||||||
|
export const UserConfigSchema = z.object({
|
||||||
|
theme: z.string().default('@matthiesenxyz/astro-ghostcms')
|
||||||
|
});
|
||||||
|
|
||||||
|
export type UserConfig = z.infer<typeof UserConfigSchema>
|
Loading…
Reference in New Issue