From 0552334f9175e85907db4d1a3a6376faf1b85d24 Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Sat, 20 Jan 2024 06:41:22 -0800 Subject: [PATCH] Enables sitemap and robots --- index.ts | 19 +++++++++++++++++-- package.json | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index ac73f797..4147a53b 100644 --- a/index.ts +++ b/index.ts @@ -4,6 +4,8 @@ import { UserConfigSchema, type UserConfig } from "./src/utils/UserConfigSchema" import { ghostSitemap, ghostRobots } from "./src/integrations"; import { loadEnv } from 'vite'; import { fromZodError } from "zod-validation-error"; +import sitemap from '@astrojs/sitemap'; +import robotsTxt from "astro-robots-txt"; // LOAD ENVIRONMENT VARIABLES const mode = 'all'; @@ -14,12 +16,16 @@ const env = loadEnv(mode, process.cwd(), prefixes); const pkg = '@matthiesenxyz/astro-ghostcms'; export default function GhostCMS(options: UserConfig): AstroIntegration { + let UserConfig:UserConfig return { name: pkg, hooks: { 'astro:config:setup': async ({ + command, + isRestart, injectRoute, config, + updateConfig, logger, }) => { // Check For ENV Variables @@ -103,7 +109,7 @@ export default function GhostCMS(options: UserConfig): AstroIntegration { logger.info("Checking for @astrojs/sitemap"); if (!int.find(({ name }) => name === '@astrojs/sitemap')) { logger.info("Injecting Integration: @astrojs/sitemap"); - int.push(ghostSitemap()); + int.push(sitemap()); } else { logger.info("Already Imported by User: @astrojs/sitemap"); } @@ -112,10 +118,19 @@ export default function GhostCMS(options: UserConfig): AstroIntegration { logger.info("Checking for astro-robots-txt"); if (!int.find(({ name }) => name === 'astro-robots-txt')) { logger.info("Injecting Integration: astro-robots-txt"); - int.push(ghostRobots()); + int.push(robotsTxt()); } else { 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 }) => { diff --git a/package.json b/package.json index 96d6b7a1..02385a2d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@matthiesenxyz/astro-ghostcms", "description": "Astro GhostCMS integration to allow easier importing of GhostCMS Content", - "version": "2.1.0", + "version": "2.1.1", "author": "MatthiesenXYZ (https://matthiesen.xyz)", "type": "module", "license": "MIT",