This commit is contained in:
Adam Matthiesen 2024-01-26 05:43:21 -08:00
parent 110342bb96
commit 9a1b343398
3 changed files with 46 additions and 18 deletions

View File

@ -45,7 +45,13 @@ const IC = {
/** INTERNAL STRING */ /** INTERNAL STRING */
F0FR: "Inject `/404` Route", F0FR: "Inject `/404` Route",
/** INTERNAL STRING */ /** INTERNAL STRING */
RSS: "Injecting `/rss.xml` Route and `@astrojs/rss` Integration" RSS: "Injecting `/rss.xml` Route and `@astrojs/rss` Integration",
/** INTERNAL STRING */
NOURL: "No Ghost URL defined in User Config: Falling back to environment variables.",
/** INTERNAL STRING */
id404: "404 Injection Disabled",
/** INTERNAL STRING */
idRSS: "RSS Injection Disabled"
} }
/** CONTENT API ENVIRONMENT VARIABLES */ /** CONTENT API ENVIRONMENT VARIABLES */
@ -81,7 +87,9 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
dCO: GhostConfig.disableConsoleOutput, dCO: GhostConfig.disableConsoleOutput,
SM: GhostConfig.sitemap, SM: GhostConfig.sitemap,
RTXT: GhostConfig.robotstxt, RTXT: GhostConfig.robotstxt,
gSite: GhostConfig.ghostURL gSite: GhostConfig.ghostURL,
dRSS: GhostConfig.disableRSS,
d404: GhostConfig.disable404
} }
// Check For ENV Variables // Check For ENV Variables
@ -93,8 +101,9 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
throw IC.KEY_MISSING; throw IC.KEY_MISSING;
} }
// CHECK FOR API URL // CHECK FOR API URL
if(ENV.CONTENT_API_URL === undefined){
if(GCD.gSite === undefined){ if(GCD.gSite === undefined){
logger.warn(IC.NOURL)
if(ENV.CONTENT_API_URL === undefined){
logger.error(IC.URL_MISSING); logger.error(IC.URL_MISSING);
throw IC.URL_MISSING; throw IC.URL_MISSING;
} }
@ -114,17 +123,21 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
// DEFAULT PROGRAM ROUTES // DEFAULT PROGRAM ROUTES
if( !GCD.dCO ) { logger.info( IC.IDR )} if( !GCD.dCO ) { logger.info( IC.IDR )}
if( !GCD.d404 ){
if( !GCD.dCO ) { logger.info( IC.F0FR )} if( !GCD.dCO ) { logger.info( IC.F0FR )}
injectRoute({ injectRoute({
pattern: '/404', pattern: '/404',
entrypoint: `${IC.PKG}/404.astro` entrypoint: `${IC.PKG}/404.astro`
}); });
} else { if( !GCD.dCO ) { logger.info(IC.id404)}}
if( !GCD.dRSS ) {
if( !GCD.dCO ) { logger.info( IC.RSS )} if( !GCD.dCO ) { logger.info( IC.RSS )}
injectRoute({ injectRoute({
pattern: '/rss.xml', pattern: '/rss.xml',
entrypoint: `${IC.PKG}/rss.xml.ts` entrypoint: `${IC.PKG}/rss.xml.ts`
}); });
} else { if( !GCD.dCO ) { logger.info(IC.idRSS)}}
// THEME ROUTES // THEME ROUTES
if( !GCD.dCO ) { logger.info( IC.ITR )} if( !GCD.dCO ) { logger.info( IC.ITR )}

View File

@ -14,13 +14,26 @@ export const UserConfigSchema = z.object({
* ], * ],
* }); */ * }); */
ghostURL: z.string().url().optional(), ghostURL: z.string().url().optional(),
/** OPTIONAL - Allows the user to disable the `/rss.xml` injection */
disableRSS: z.boolean().default(false),
/** OPTIONAL - Allows the user to disable the `/404` injection */
disable404: z.boolean().default(false),
/** OPTIONAL - Disable Route Injector /** OPTIONAL - Disable Route Injector
* This option allows the user to disable the route injection system and utilize just the integraions other functions. Such as API, sitemap and robotstxt integrations. */ * This option allows the user to disable the route injection system and utilize just the integraions other functions. Such as API, sitemap and robotstxt integrations. */
disableRouteInjection: z.boolean().default(false), disableRouteInjection: z.boolean().default(false),
/** OPTIONAL - Allows the user to disable "info" console output */ /** OPTIONAL - (Default: true) Allows the user to disable "info" console output */
disableConsoleOutput: z.boolean().default(false), disableConsoleOutput: z.boolean().default(true),
/** OPTIONAL - Theme Selector /** OPTIONAL - Theme Selector
* This option allows the user to replace the included theme with an external npm module */ * This option allows the user to replace the included theme with an external npm module
* @example
* // https://astro.build/config
* export default defineConfig({
* integrations: [
* ghostcms({
* theme: "@matthiesenxyz/astro-ghostcms-theme-default"
* })
* ],
* }); */
theme: z.string().default('@matthiesenxyz/astro-ghostcms-theme-default'), theme: z.string().default('@matthiesenxyz/astro-ghostcms-theme-default'),
/** OPTIONAL - astrojs/sitemap /** OPTIONAL - astrojs/sitemap
* This option allows the user to configure the included integration * This option allows the user to configure the included integration

View File

@ -6,8 +6,10 @@ export default defineConfig({
site: "https://demo.astro-ghostcms.xyz/", site: "https://demo.astro-ghostcms.xyz/",
integrations: [ integrations: [
ghostcms({ ghostcms({
disableConsoleOutput: true, disable404: false,
disableRSS: false,
disableRouteInjection: false, disableRouteInjection: false,
disableConsoleOutput: false,
theme: "@matthiesenxyz/astro-ghostcms-theme-default", theme: "@matthiesenxyz/astro-ghostcms-theme-default",
ghostURL: "https://ghostdemo.matthiesen.xyz", ghostURL: "https://ghostdemo.matthiesen.xyz",
}) })