Enables sitemap and robots

This commit is contained in:
Adam Matthiesen 2024-01-20 06:41:22 -08:00
parent 56334232c4
commit 0552334f91
2 changed files with 18 additions and 3 deletions

View File

@ -4,6 +4,8 @@ import { UserConfigSchema, type UserConfig } from "./src/utils/UserConfigSchema"
import { ghostSitemap, ghostRobots } from "./src/integrations"; import { ghostSitemap, ghostRobots } from "./src/integrations";
import { loadEnv } from 'vite'; import { loadEnv } from 'vite';
import { fromZodError } from "zod-validation-error"; import { fromZodError } from "zod-validation-error";
import sitemap from '@astrojs/sitemap';
import robotsTxt from "astro-robots-txt";
// LOAD ENVIRONMENT VARIABLES // LOAD ENVIRONMENT VARIABLES
const mode = 'all'; const mode = 'all';
@ -14,12 +16,16 @@ const env = loadEnv(mode, process.cwd(), prefixes);
const pkg = '@matthiesenxyz/astro-ghostcms'; const pkg = '@matthiesenxyz/astro-ghostcms';
export default function GhostCMS(options: UserConfig): AstroIntegration { export default function GhostCMS(options: UserConfig): AstroIntegration {
let UserConfig:UserConfig
return { return {
name: pkg, name: pkg,
hooks: { hooks: {
'astro:config:setup': async ({ 'astro:config:setup': async ({
command,
isRestart,
injectRoute, injectRoute,
config, config,
updateConfig,
logger, logger,
}) => { }) => {
// Check For ENV Variables // Check For ENV Variables
@ -103,7 +109,7 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
logger.info("Checking for @astrojs/sitemap"); logger.info("Checking for @astrojs/sitemap");
if (!int.find(({ name }) => name === '@astrojs/sitemap')) { if (!int.find(({ name }) => name === '@astrojs/sitemap')) {
logger.info("Injecting Integration: @astrojs/sitemap"); logger.info("Injecting Integration: @astrojs/sitemap");
int.push(ghostSitemap()); int.push(sitemap());
} else { } else {
logger.info("Already Imported by User: @astrojs/sitemap"); logger.info("Already Imported by User: @astrojs/sitemap");
} }
@ -112,11 +118,20 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
logger.info("Checking for astro-robots-txt"); logger.info("Checking for astro-robots-txt");
if (!int.find(({ name }) => name === 'astro-robots-txt')) { if (!int.find(({ name }) => name === 'astro-robots-txt')) {
logger.info("Injecting Integration: astro-robots-txt"); logger.info("Injecting Integration: astro-robots-txt");
int.push(ghostRobots()); int.push(robotsTxt());
} else { } else {
logger.info("Already Imported by User: astro-robots-txt"); logger.info("Already Imported by User: astro-robots-txt");
} }
try {
updateConfig({
integrations: [sitemap(),robotsTxt()]
})
} catch (e) {
logger.error(e as string)
throw e
}
}, },
'astro:config:done': async ({ logger }) => { 'astro:config:done': async ({ logger }) => {
logger.info('GhostCMS Injection Complete. Integration is now ready.'); logger.info('GhostCMS Injection Complete. Integration is now ready.');

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": "2.1.0", "version": "2.1.1",
"author": "MatthiesenXYZ (https://matthiesen.xyz)", "author": "MatthiesenXYZ (https://matthiesen.xyz)",
"type": "module", "type": "module",
"license": "MIT", "license": "MIT",