some code cleanup and bumb astro-ghostcms version

This commit is contained in:
Adam Matthiesen 2024-02-06 01:59:36 -08:00
parent 1887d94524
commit 0bf8d9d963
3 changed files with 48 additions and 50 deletions

View File

@ -4,9 +4,13 @@
*Ghost is a trademark of [The Ghost Foundation](https://ghost.org/trademark/). This project is not directly related to or provided by The Ghost Foundation and is intended to help create a easier method to utilize their provided API to link a Headless GhostCMS install in to your Astro project.* *Ghost is a trademark of [The Ghost Foundation](https://ghost.org/trademark/). This project is not directly related to or provided by The Ghost Foundation and is intended to help create a easier method to utilize their provided API to link a Headless GhostCMS install in to your Astro project.*
- [Live Demo](https://demo.astro-ghostcms.xyz/) of the Astro-GhostCMS integration in action! Want to Chat? Join our [Discord](https://discord.gg/u7NZqUyeAR)
- [Live Demo - Unlighthouse Test](https://test.demo.astro-ghostcms.xyz) for a Automatically updated Lighthouse test from every deploy!
- [Live Demo's Repo](https://github.com/MatthiesenXYZ/astro-ghostcms-demo) for an example of how the setup looks. For a full always up to date documentation please checkout [Our Website](https://astro-ghostcms.xyz)
- [Default Theme Demo](https://demo.astro-ghostcms.xyz)
- [Catppuccin Dark Demo](https://catppuccindark-demo.astro-ghostcms.xyz/)
- [Astro-GhostCMS Website](https://astro-ghostcms.xyz) Check the website for the most up-to-date Documentation!
- [Ghost.org](https://ghost.org) Get your own Ghost[^1] Install - [Ghost.org](https://ghost.org) Get your own Ghost[^1] Install
*Need help but don't have Github? Email us at [issues@astro-ghostcms.xyz](mailto:issues@astroghostcms.xyz) to create an issue here on github!* *Need help but don't have Github? Email us at [issues@astro-ghostcms.xyz](mailto:issues@astroghostcms.xyz) to create an issue here on github!*

View File

@ -45,7 +45,7 @@ const IC = {
/** INTERNAL STRING */ /** INTERNAL STRING */
CF:"Checking for ", CF:"Checking for ",
/** INTERNAL STRING */ /** INTERNAL STRING */
CONFSETUPDONE:"GhostCMS Injection Complete. Integration is now ready.", CONFSETUPDONE:"Step Complete",
/** INTERNAL STRING */ /** INTERNAL STRING */
F0FR: "Inject `/404` Route", F0FR: "Inject `/404` Route",
/** INTERNAL STRING */ /** INTERNAL STRING */
@ -71,15 +71,9 @@ const ENV = loadEnv(IC.MODE, process.cwd(), IC.PREFIXES);
*/ */
export default function GhostCMS(options: UserConfig): AstroIntegration { export default function GhostCMS(options: UserConfig): AstroIntegration {
return { return {
name: IC.PKG, name: "astro-ghostcms",
hooks: { hooks: {
'astro:config:setup': async ({ 'astro:config:setup': async ({ injectRoute, config, updateConfig, logger, }) => {
injectRoute,
config,
updateConfig,
logger,
}) => {
// DEFINE LOGGERS // DEFINE LOGGERS
const logConfigCheck = logger.fork("astro-ghostcms/config:check") const logConfigCheck = logger.fork("astro-ghostcms/config:check")
const logConfigSetup = logger.fork("astro-ghostcms/config:setup") const logConfigSetup = logger.fork("astro-ghostcms/config:setup")
@ -107,35 +101,27 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
// Check For ENV Variables // Check For ENV Variables
if(!GCD.dCO) {logConfigCheck.info(IC.CHECK_ENV)} if(!GCD.dCO) {logConfigCheck.info(IC.CHECK_ENV)}
// CHECK FOR API KEY
if(ENV.CONTENT_API_KEY === undefined){ if(ENV.CONTENT_API_KEY === undefined){
logConfigCheck.error(IC.KEY_MISSING); logConfigCheck.error(IC.KEY_MISSING);
throw IC.KEY_MISSING; throw IC.KEY_MISSING;
} }
// CHECK FOR API URL
if(GCD.gSite === undefined){ if(GCD.gSite === undefined){
logConfigCheck.warn(IC.NOURL) logConfigCheck.warn(IC.NOURL)
if(ENV.CONTENT_API_URL === undefined){ if(ENV.CONTENT_API_URL === undefined){
logConfigCheck.error(IC.URL_MISSING); logConfigCheck.error(IC.URL_MISSING);
throw IC.URL_MISSING; throw IC.URL_MISSING; }
}
} }
if(!GCD.dRI){ if(!GCD.dRI){
// THEME SELECTOR // THEME SELECTOR
if ( GCD.theme === IC.DT ) { if ( GCD.theme === IC.DT ) {
if( !GCD.dCO ) { logConfigCheck.info( IC.IT + IC.DT )} if( !GCD.dCO ) { logConfigCheck.info( IC.IT + IC.DT )}
} else { } else {
if( !GCD.dCO ) { logConfigCheck.info( IC.IT + GCD.theme )} if( !GCD.dCO ) { logConfigCheck.info( IC.IT + GCD.theme )}
} }
// INJECT ROUTES // INJECT ROUTES
//// DEFAULT PROGRAM ROUTES
// DEFAULT PROGRAM ROUTES
if( !GCD.dCO ) { logConfigSetup.info( IC.IDR )} if( !GCD.dCO ) { logConfigSetup.info( IC.IDR )}
if( !GCD.d404 ){ if( !GCD.d404 ){
if( !GCD.dCO ) { logConfigSetup.info( IC.F0FR )} if( !GCD.dCO ) { logConfigSetup.info( IC.F0FR )}
injectRoute({ injectRoute({
@ -191,32 +177,26 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
pattern: '/', pattern: '/',
entrypoint: `${GCD.theme}/index.astro` entrypoint: `${GCD.theme}/index.astro`
}); });
injectRoute({ injectRoute({
pattern: '/[slug]', pattern: '/[slug]',
entrypoint: `${GCD.theme}/[slug].astro` entrypoint: `${GCD.theme}/[slug].astro`
}); });
injectRoute({ injectRoute({
pattern: '/tags', pattern: '/tags',
entrypoint: `${GCD.theme}/tags.astro` entrypoint: `${GCD.theme}/tags.astro`
}); });
injectRoute({ injectRoute({
pattern: '/authors', pattern: '/authors',
entrypoint: `${GCD.theme}/authors.astro` entrypoint: `${GCD.theme}/authors.astro`
}); })
injectRoute({ injectRoute({
pattern: '/tag/[slug]', pattern: '/tag/[slug]',
entrypoint: `${GCD.theme}/tag/[slug].astro` entrypoint: `${GCD.theme}/tag/[slug].astro`
}); });
injectRoute({ injectRoute({
pattern: '/author/[slug]', pattern: '/author/[slug]',
entrypoint: `${GCD.theme}/author/[slug].astro` entrypoint: `${GCD.theme}/author/[slug].astro`
}); });
injectRoute({ injectRoute({
pattern: '/archives/[...page]', pattern: '/archives/[...page]',
entrypoint: `${GCD.theme}/archives/[...page].astro` entrypoint: `${GCD.theme}/archives/[...page].astro`
@ -232,7 +212,6 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
if (!integrations.find(({ name }) => name === '@astrojs/sitemap' )) { if (!integrations.find(({ name }) => name === '@astrojs/sitemap' )) {
if( !GCD.dCO ) { logConfigSetup.info( `${IC.II}@astrojs/sitemap` )} if( !GCD.dCO ) { logConfigSetup.info( `${IC.II}@astrojs/sitemap` )}
integrations.push(ghostSitemap(GCD.SM)); integrations.push(ghostSitemap(GCD.SM));
} else { if( !GCD.dCO ) { logConfigSetup.info( `${IC.AIbU}@astrojs/sitemap` )} } else { if( !GCD.dCO ) { logConfigSetup.info( `${IC.AIbU}@astrojs/sitemap` )}
}; };
@ -253,11 +232,8 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
ghostRobots(GCD.RTXT) ghostRobots(GCD.RTXT)
], ],
vite: { vite: {
optimizeDeps: { optimizeDeps: { exclude: ["@resvg/resvg-js"] }
exclude: ["@resvg/resvg-js"],
}
} }
// LOAD VITE AND SETUP viteGhostCMS Configs
}) } catch ( e ) { }) } catch ( e ) {
logConfigSetup.error( e as string ); logConfigSetup.error( e as string );
throw e; throw e;
@ -270,29 +246,49 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
}) })
}, },
'astro:config:done': async ({ logger }) => { 'astro:config:done': async ({ logger }) => {
// DEFINE LOGGERS // Config Done
const logConfigDone = logger.fork("astro-ghostcms/config:done"); const logConfigDone = logger.fork("astro-ghostcms/config:done");
const pJSON = await fse.readJson(path.resolve(fileURLToPath(import.meta.url), "..", 'package.json'));
const pkgVer = pJSON.version;
logConfigDone.info(`Config Done. Current Version: v${pkgVer}`);
},
'astro:server:setup': async ({ logger }) => {
// Dev Server Start
const logServerSetup = logger.fork("astro-ghostcms/server:setup");
const logCurrentVersion = logger.fork("astro-ghostcms/current-version"); const logCurrentVersion = logger.fork("astro-ghostcms/current-version");
const logNpmVersion = logger.fork("astro-ghostcms/npm-pub-version"); const logNpmVersion = logger.fork("astro-ghostcms/npm-pub-version");
const logCheck = logger.fork("astro-ghostcms/check"); const logCheck = logger.fork("astro-ghostcms/check");
const pJSON = await fse.readJson(path.resolve(fileURLToPath(import.meta.url), "..", 'package.json'));
const pJSON = await fse.readJson(
path.resolve(
fileURLToPath(import.meta.url), "..", 'package.json')
);
const pkgVer = pJSON.version; const pkgVer = pJSON.version;
const npmVER = await latestVersion(IC.PKG); const npmVER = await latestVersion(IC.PKG);
if (pkgVer !== npmVER ) { if (pkgVer !== npmVER ) {
logCurrentVersion.warn(`Current Installed Version is v${pkgVer}`); logCurrentVersion.warn(`Current Installed Version is v${pkgVer}`);
logNpmVersion.warn(`Latest Published Version is v${npmVER}`); logNpmVersion.warn(`Latest Published Version is v${npmVER}`);
logCheck.warn("Please consider updating."); logCheck.warn("Please consider updating.");
} }
logServerSetup.info("Setting up Astro-GhostCMS server for Development!");
// CONFIG DONE },
logConfigDone.info(`${IC.CONFSETUPDONE} v${pkgVer}`); 'astro:server:start': async ({ logger }) => {
// Server Start
const logServerStart = logger.fork("astro-ghostcms/server:start");
logServerStart.info("Astro-GhostCMS Integration Ready!");
},
'astro:build:done': async ({ logger }) => {
// Build Done
const logBuildDone = logger.fork("astro-ghostcms/build:done");
const logCurrentVersion = logger.fork("astro-ghostcms/current-version");
const logNpmVersion = logger.fork("astro-ghostcms/npm-pub-version");
const logCheck = logger.fork("astro-ghostcms/check");
const pJSON = await fse.readJson(path.resolve(fileURLToPath(import.meta.url), "..", 'package.json'));
const pkgVer = pJSON.version;
const npmVER = await latestVersion(IC.PKG);
if (pkgVer !== npmVER ) {
logCurrentVersion.warn(`Current Installed Version is v${pkgVer}`);
logNpmVersion.warn(`Latest Published Version is v${npmVER}`);
logCheck.warn("Please consider updating.");
}
logBuildDone.info(`Build Complete, Integration Now ready for Production. Astro-GhostCMS v${pkgVer}`);
} }
} }
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "@matthiesenxyz/astro-ghostcms", "name": "@matthiesenxyz/astro-ghostcms",
"description": "Astro GhostCMS integration to allow easier importing of GhostCMS Content", "description": "Astro GhostCMS integration to allow easier importing of GhostCMS Content",
"version": "3.2.0", "version": "3.2.1",
"homepage": "https://astro-ghostcms.xyz/", "homepage": "https://astro-ghostcms.xyz/",
"type": "module", "type": "module",
"license": "MIT", "license": "MIT",
@ -71,9 +71,6 @@
"test:coverage": "vitest run --coverage", "test:coverage": "vitest run --coverage",
"test:ci": "vitest run --coverage.enabled --coverage.reporter='text-summary'" "test:ci": "vitest run --coverage.enabled --coverage.reporter='text-summary'"
}, },
"peerDependencies": {
"astro": "^4.3.2"
},
"devDependencies": { "devDependencies": {
"@astrojs/check": "^0.4.1", "@astrojs/check": "^0.4.1",
"@ts-ghost/core-api": "*", "@ts-ghost/core-api": "*",
@ -99,6 +96,7 @@
"@astrojs/sitemap": "^3.0.5", "@astrojs/sitemap": "^3.0.5",
"@resvg/resvg-js": "^2.6.0", "@resvg/resvg-js": "^2.6.0",
"@ts-ghost/core-api": "^5.1.2", "@ts-ghost/core-api": "^5.1.2",
"astro": "^4.3.2",
"astro-robots-txt": "^1.0.0", "astro-robots-txt": "^1.0.0",
"fs-extra": "^11.1.0", "fs-extra": "^11.1.0",
"package-json": "9.0.0", "package-json": "9.0.0",