From aea8305ac031964317a6e6c4c4ea0c9e947999ad Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Mon, 4 Mar 2024 11:11:15 -0800 Subject: [PATCH] add checkIntegration helper for sitemap and astro-robots-txt --- packages/astro-ghostcms/src/astro-ghostcms.ts | 33 +++++++++++-------- playgrounds/astro-playground/astro.config.mjs | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/packages/astro-ghostcms/src/astro-ghostcms.ts b/packages/astro-ghostcms/src/astro-ghostcms.ts index 74d68892..65de8314 100644 --- a/packages/astro-ghostcms/src/astro-ghostcms.ts +++ b/packages/astro-ghostcms/src/astro-ghostcms.ts @@ -15,8 +15,8 @@ import latestVersion from "./utils/latestVersion"; import sitemap from "@astrojs/sitemap"; import robotsTxt from "astro-robots-txt"; -import ghostRSS from "./integrations/rssfeed"; // Internal Integrations +import ghostRSS from "./integrations/rssfeed"; import ghostOGImages from "./integrations/satoriog"; import ghostThemeProvider from "./integrations/themeprovider"; @@ -25,6 +25,7 @@ const ENV = loadEnv("all", process.cwd(), "CONTENT_API"); // Import User Configuration Zod Schema import { GhostUserConfigSchema } from "./schemas/userconfig"; +import type { AstroIntegration } from "astro"; /** Astro-GhostCMS Integration * @description This integration allows you to use GhostCMS as a headless CMS for your Astro project @@ -168,21 +169,25 @@ export default defineIntegration({ intLogInfo(c.gray("RSS Feed is disabled")); } - // @ASTROJS/SITEMAP - if (!hasIntegration("@astrojs/sitemap")) { - intLogInfo(c.bold(c.magenta(`Adding ${c.blue("@astrojs/sitemap")} integration`))); - addIntegration(sitemap(options.Integrations?.sitemap)); - } else { - intLogInfo(c.gray("@astrojs/sitemap integration already exists, skipping...")); - } - // ASTRO-ROBOTS-TXT - if (!hasIntegration("astro-robots-txt")) { - intLogInfo(c.bold(c.magenta(`Adding ${c.blue("astro-robots-txt")} integration`))); - addIntegration(robotsTxt(options.Integrations?.robotsTxt)); - } else { - intLogInfo(c.gray("astro-robots-txt integration already exists, skipping...")); + const checkIntegration = (name: string, integration: AstroIntegration) => { + if (!hasIntegration(name)) { + intLogInfo(c.bold(c.magenta(`Adding ${c.blue(name)} integration`))); + addIntegration(integration); + } else { + intLogInfo(c.gray(`${name} integration already exists, skipping...`)); + } } + checkIntegration( + "@astrojs/sitemap", + sitemap(options.Integrations?.sitemap) + ); + checkIntegration( + "astro-robots-txt", + robotsTxt(options.Integrations?.robotsTxt) + ); + + // Set up default 404 page if (!options.disableDefault404) { routeLogInfo(c.bold(c.cyan("Setting up default 404 page"))); diff --git a/playgrounds/astro-playground/astro.config.mjs b/playgrounds/astro-playground/astro.config.mjs index a24919e3..56707f73 100644 --- a/playgrounds/astro-playground/astro.config.mjs +++ b/playgrounds/astro-playground/astro.config.mjs @@ -14,7 +14,7 @@ export default defineConfig({ ThemeProvider: { theme: "@matthiesenxyz/astro-ghostcms-brutalbyelian", }, - verbose: false, + verbose: true, }), ], });