This commit is contained in:
Adam Matthiesen 2024-01-24 21:13:14 -08:00
parent b7566e5625
commit 54e3b3fe76
1 changed files with 56 additions and 70 deletions

View File

@ -10,7 +10,7 @@ import { viteGhostCMS } from "./src/virtual";
const IC = { const IC = {
/** INTERNAL PACKAGE NAME */ /** INTERNAL PACKAGE NAME */
PKG:'@matthiesenxyz/astro-ghostcms', PKG:'@matthiesenxyz/astro-ghostcms',
/** INTERNAL PACKAGE NAME */ /** INTERNAL PACKAGE NAME (THEME) */
DT:'@matthiesenxyz/astro-ghostcms-theme-default', DT:'@matthiesenxyz/astro-ghostcms-theme-default',
/** INTERNAL STRING */ /** INTERNAL STRING */
CHECK_ENV:"Checking for Environment Variables...", CHECK_ENV:"Checking for Environment Variables...",
@ -25,7 +25,9 @@ const IC = {
/** INTERNAL STRING */ /** INTERNAL STRING */
IT:"Injecting Theme: ", IT:"Injecting Theme: ",
/** INTERNAL STRING */ /** INTERNAL STRING */
IR:"Injecting Routes...", IDR:"Injecting Default Routes...",
/** INTERNAL STRING */
IR:"Injecting Default Theme Routes...",
/** INTERNAL STRING */ /** INTERNAL STRING */
IRD:"Route Injection Disabled - Skipping...", IRD:"Route Injection Disabled - Skipping...",
/** INTERNAL STRING */ /** INTERNAL STRING */
@ -38,6 +40,10 @@ const IC = {
CF:"Checking for ", CF:"Checking for ",
/** INTERNAL STRING */ /** INTERNAL STRING */
CONFSETUPDONE:"GhostCMS Injection Complete. Integration is now ready.", CONFSETUPDONE:"GhostCMS Injection Complete. Integration is now ready.",
/** INTERNAL STRING */
F0FR: "Inject `/404` Route",
/** INTERNAL STRING */
RSS: "Injecting `/rss.xml` Route and `@astrojs/rss` Integration"
} }
/** CONTENT API ENVIRONMENT VARIABLES */ /** CONTENT API ENVIRONMENT VARIABLES */
@ -57,6 +63,7 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
updateConfig, updateConfig,
logger, logger,
}) => { }) => {
// CHECK USER CONFIG AND MAKE AVAILBLE TO INTEGRATIONS // CHECK USER CONFIG AND MAKE AVAILBLE TO INTEGRATIONS
logger.info("Checking Config...") logger.info("Checking Config...")
const o = UserConfigSchema.safeParse(options || {}) as SafeParseSuccess<UserConfig>; const o = UserConfigSchema.safeParse(options || {}) as SafeParseSuccess<UserConfig>;
@ -65,6 +72,7 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
logger.error(`Config Error - ${ validationError }`); logger.error(`Config Error - ${ validationError }`);
throw validationError; throw validationError;
} }
/** INTERNAL USERCONFIG ALIAS */ /** INTERNAL USERCONFIG ALIAS */
const uconf = o.data; const uconf = o.data;
/** CONFIG OPTION: ROUTE INJECTION */ /** CONFIG OPTION: ROUTE INJECTION */
@ -89,6 +97,7 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
} }
if(!injection){ if(!injection){
// THEME SELECTOR // THEME SELECTOR
if ( entry === IC.DT ) { if ( entry === IC.DT ) {
if( !logs ) { logger.info( IC.IT + IC.DT )} if( !logs ) { logger.info( IC.IT + IC.DT )}
@ -97,68 +106,44 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
} }
// INJECT ROUTES // INJECT ROUTES
if(!logs) {logger.info(IC.IR)}
injectRoute({ // DEFAULT PROGRAM ROUTES
pattern: '/', if( !logs ) { logger.info( IC.IDR )}
entrypoint: `${entry}/index.astro`
});
injectRoute({ if( !logs ) { logger.info( IC.F0FR )}
pattern: '/404', injectRoute({ pattern: '/404', entrypoint: IC.PKG+'/404.astro' });
entrypoint: IC.PKG+'/404.astro'
});
injectRoute({ if( !logs ) { logger.info( IC.RSS )}
pattern: '/[slug]', injectRoute({ pattern: '/rss.xml', entrypoint: IC.PKG+'/rss.xml.ts' });
entrypoint: `${entry}/[slug].astro`
});
injectRoute({ // THEME ROUTES
pattern: '/tags', if( !logs ) { logger.info( IC.ITR )}
entrypoint: `${entry}/tags.astro`
});
injectRoute({ injectRoute({ pattern: '/', entrypoint: `${entry}/index.astro` });
pattern: '/authors',
entrypoint: `${entry}/authors.astro`
});
injectRoute({ injectRoute({ pattern: '/[slug]', entrypoint: `${entry}/[slug].astro` });
pattern: '/tag/[slug]',
entrypoint: `${entry}/tag/[slug].astro`
});
injectRoute({ injectRoute({ pattern: '/tags', entrypoint: `${entry}/tags.astro` });
pattern: '/author/[slug]',
entrypoint: `${entry}/author/[slug].astro`
});
injectRoute({ injectRoute({ pattern: '/authors', entrypoint: `${entry}/authors.astro` });
pattern: '/archives/[...page]',
entrypoint: `${entry}/archives/[...page].astro` injectRoute({ pattern: '/tag/[slug]', entrypoint: `${entry}/tag/[slug].astro` });
});
} else { injectRoute({ pattern: '/author/[slug]', entrypoint: `${entry}/author/[slug].astro` });
if(!logs) {logger.info(IC.IRD)}
} injectRoute({ pattern: '/archives/[...page]', entrypoint: `${entry}/archives/[...page].astro` });
} else { if( !logs ) { logger.info( IC.IRD )} }
// IMPORT INTEGRATIONS & INTEGRATION ROUTES // IMPORT INTEGRATIONS & INTEGRATION ROUTES
const int = [...config.integrations]; const int = [...config.integrations];
// IMPORT INTEGRATION: @ASTROJS/RSS
if(!logs) {logger.info(IC.IIR + "@astrojs/rss")}
injectRoute({
pattern: '/rss.xml',
entrypoint: IC.PKG+'/rss.xml.ts'
});
// IMPORT INTEGRATION: @ASTROJS/SITEMAP // IMPORT INTEGRATION: @ASTROJS/SITEMAP
if( !logs ) { logger.info( IC.CF + "@astrojs/sitemap" )} if( !logs ) { logger.info( IC.CF + "@astrojs/sitemap" )}
if ( !int.find( ({ name }) => name === '@astrojs/sitemap' )) { if ( !int.find( ({ name }) => name === '@astrojs/sitemap' )) {
if( !logs ) { logger.info( IC.II + "@astrojs/sitemap" )} if( !logs ) { logger.info( IC.II + "@astrojs/sitemap" )}
int.push( ghostSitemap( uconf )); int.push( ghostSitemap( uconf ));
} else { } else { if( !logs ) { logger.info( IC.AIbU + "@astrojs/sitemap" )}
if(!logs) {logger.info(IC.AIbU + "@astrojs/sitemap")}
}; };
// IMPORT INTEGRATION: ASTRO-ROBOTS-TXT // IMPORT INTEGRATION: ASTRO-ROBOTS-TXT
@ -169,11 +154,12 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
} else { } else {
if( !logs ) { logger.info( IC.AIbU + "astro-robots-txt" )} if( !logs ) { logger.info( IC.AIbU + "astro-robots-txt" )}
}; };
// FINAL STEP TO KEEP INTEGRATION LIVE
try { updateConfig( { try { updateConfig( {
integrations: [ // UPDATE ASTRO CONFIG WITH INTEGRATED INTEGRATIONS
ghostSitemap(uconf), integrations: [ ghostSitemap( uconf ), ghostRobots( uconf ) ],
ghostRobots(uconf), // LOAD VITE AND SETUP viteGhostCMS Configs
],
vite: { plugins: [ viteGhostCMS( uconf, config ) ]}, vite: { plugins: [ viteGhostCMS( uconf, config ) ]},
}) } catch ( e ) { }) } catch ( e ) {
logger.error( e as string ); logger.error( e as string );