From 017e641afdf2a5fe27d9ed1689fb139d4f753a25 Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Sun, 3 Mar 2024 09:51:00 -0800 Subject: [PATCH] Woo Better config options! --- packages/astro-ghostcms/README.md | 10 ++++- packages/astro-ghostcms/src/astro-ghostcms.ts | 8 ++-- packages/astro-ghostcms/src/schemas/robots.ts | 37 ------------------ .../astro-ghostcms/src/schemas/sitemap.ts | 38 ------------------- .../astro-ghostcms/src/schemas/userconfig.ts | 36 +++++++++--------- playgrounds/astro-playground/astro.config.mjs | 1 + 6 files changed, 32 insertions(+), 98 deletions(-) delete mode 100644 packages/astro-ghostcms/src/schemas/robots.ts delete mode 100644 packages/astro-ghostcms/src/schemas/sitemap.ts diff --git a/packages/astro-ghostcms/README.md b/packages/astro-ghostcms/README.md index 2d9f2644..f38c63e3 100644 --- a/packages/astro-ghostcms/README.md +++ b/packages/astro-ghostcms/README.md @@ -63,14 +63,22 @@ export default defineConfig({ GhostCMS({ // Config Options ghostURL: "http://example.com"; // Recommended to set here, Can also set in .env as CONTENT_API_URL - disableThemeProvider: false; // OPTIONAL - Default False ThemeProvider: { // Allows you to pass config options to our ThemeProvider if enabled. + disableThemeProvider: false; // OPTIONAL - Default False theme: "@matthiesenxyz/astro-ghostcms-theme-default"; // OPTIONAL - Default Theme shown. }; disableDefault404: false; // Allows the user to disable the default `/404 page, to be able to create their own under `/src/pages/404.astro`. enableRSSFeed: true; // Allows the user to Enable or disable RSS Feed Generation. Default: true enableOGImages: true; // Allows the user to Enable or disable OG Image Generation. Default: true fullConsoleLogs: false; // Show the full Log output from All parts of Astro-GhostCMS + robotsTxt: { + // OPTIONAL + // ADVANCED USAGE - https://www.npmjs.com/package/astro-robots-txt#configuration + } + sitemap: { + // OPTIONAL + // ADVANCED USAGE - https://docs.astro.build/en/guides/integrations-guide/sitemap + } }) ], }); diff --git a/packages/astro-ghostcms/src/astro-ghostcms.ts b/packages/astro-ghostcms/src/astro-ghostcms.ts index c976ca1f..0579439c 100644 --- a/packages/astro-ghostcms/src/astro-ghostcms.ts +++ b/packages/astro-ghostcms/src/astro-ghostcms.ts @@ -120,7 +120,7 @@ export default defineIntegration({ ); // Theme Provider - if (!options.disableThemeProvider) { + if (!options.ThemeProvider?.disableThemeProvider) { addIntegration( ghostThemeProvider({ theme: options.ThemeProvider?.theme, @@ -162,7 +162,7 @@ export default defineIntegration({ ), ); } - addIntegration(sitemap()); + addIntegration(sitemap(options.sitemap)); } else { if (verbose) { GhostIntegrationLogger.info( @@ -173,7 +173,7 @@ export default defineIntegration({ } } // ASTRO-ROBOTS-TXT - if (!hasIntegration("@astro-robots-txt")) { + if (!hasIntegration("astro-robots-txt")) { if (verbose) { GhostIntegrationLogger.info( c.bold( @@ -181,7 +181,7 @@ export default defineIntegration({ ), ); } - addIntegration(robotsTxt()); + addIntegration(robotsTxt(options.robotsTxt)); } else { if (verbose) { GhostIntegrationLogger.info( diff --git a/packages/astro-ghostcms/src/schemas/robots.ts b/packages/astro-ghostcms/src/schemas/robots.ts deleted file mode 100644 index dd3c2da1..00000000 --- a/packages/astro-ghostcms/src/schemas/robots.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { z } from "astro/zod"; - -const RobotsPolicySchema = z.object({ - /** You must provide a name of the automatic client (search engine crawler). - * Wildcards are allowed. - */ - userAgent: z.string(), - /** Allowed paths for crawling */ - allow: z.string().optional(), - /** Disallowed paths for crawling */ - disallow: z.string().optional(), - /** Indicates that the page's URL contains parameters that should be ignored during crawling. - * Maximum string length is limited to 500. - */ - cleanParam: z.string().optional(), - /** Minimum interval (in secs) for the crawler to wait after loading one page, before starting other */ - crawlDelay: z.number().optional(), -}); - -export const RobotsTxtSchema = z.object({ - /** @example host: true - * // Automatically resolve using the site option from Astro config - * @example host: 'example.com' - */ - host: z.string().optional(), - /** @example sitemap: "https://example.com/sitemap-0.xml" - * @example sitemap: ['https://example.com/sitemap-0.xml','https://example.com/sitemap-1.xml'] - * @example sitemap: false - If you want to get the robots.txt file without the Sitemap: ... entry, set the sitemap parameter to false. - */ - sitemap: z.union([z.string(), z.string().array(), z.boolean()]).optional(), - /** astrojs/sitemap and astro-robots-txt integrations have the sitemap-index.xml as their primary output. That is why the default value of sitemapBaseFileName is set to sitemap-index. - * @example sitemapBaseFileName: 'custom-sitemap' - */ - sitemapBaseFileName: z.string().optional(), - /** SET POLICY RULES */ - policy: RobotsPolicySchema.array().optional(), -}); diff --git a/packages/astro-ghostcms/src/schemas/sitemap.ts b/packages/astro-ghostcms/src/schemas/sitemap.ts deleted file mode 100644 index f94789e9..00000000 --- a/packages/astro-ghostcms/src/schemas/sitemap.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { z } from "astro/zod"; - -const localeKeySchema = z.string().min(1); -enum EnumChangefreq { - DAILY = "daily", - MONTHLY = "monthly", - ALWAYS = "always", - HOURLY = "hourly", - WEEKLY = "weekly", - YEARLY = "yearly", - NEVER = "never", -} -export const SitemapSchema = z.object({ - filter: z.function().args(z.string()).returns(z.boolean()).optional(), - customPages: z.string().url().array().optional(), - i18n: z - .object({ - defaultLocale: localeKeySchema, - locales: z.record( - localeKeySchema, - z - .string() - .min(2) - .regex(/^[a-zA-Z\-]+$/gm, { - message: "Only English alphabet symbols and hyphen allowed", - }), - ), - }) - .refine((val) => !val || val.locales[val.defaultLocale], { - message: "`defaultLocale` must exist in `locales` keys", - }) - .optional(), - entryLimit: z.number().nonnegative().optional(), - serialize: z.function().args(z.any()).returns(z.any()).optional(), - changefreq: z.nativeEnum(EnumChangefreq).optional(), - lastmod: z.date().optional(), - priority: z.number().min(0).max(1).optional(), -}); diff --git a/packages/astro-ghostcms/src/schemas/userconfig.ts b/packages/astro-ghostcms/src/schemas/userconfig.ts index ea5f5a9d..c501cbd2 100644 --- a/packages/astro-ghostcms/src/schemas/userconfig.ts +++ b/packages/astro-ghostcms/src/schemas/userconfig.ts @@ -1,6 +1,6 @@ import { z } from "astro/zod"; -import { RobotsTxtSchema } from "./robots.ts"; -import { SitemapSchema } from "./sitemap.ts"; +import type { RobotsTxtOptions } from "astro-robots-txt"; +import type { SitemapOptions } from "@astrojs/sitemap"; export const GhostUserConfigSchema = z.object({ /** OPTIONAL - Either set the URL in your .env or put it here @@ -14,12 +14,12 @@ export const GhostUserConfigSchema = z.object({ * ], * }); */ ghostURL: z.string().url().optional(), - /** OPTIONAL - Disable the theme provider - * @default false - */ - disableThemeProvider: z.boolean().optional().default(false), ThemeProvider: z .object({ + /** OPTIONAL - Disable the theme provider + * @default false + */ + disableThemeProvider: z.boolean().optional().default(false), /** OPTIONAL - Set the theme you want to use * @default "@matthiesenxyz/astro-ghostcms-theme-default" */ @@ -37,22 +37,22 @@ export const GhostUserConfigSchema = z.object({ * @default true */ enableOGImages: z.boolean().optional().default(true), - /** OPTIONAL - astrojs/sitemap - * This option allows the user to configure the included integration - * Options shown are the availble options - * REFERENCE https://docs.astro.build/en/guides/integrations-guide/sitemap - */ - sitemap: SitemapSchema.optional(), - /** OPTIONAL - astro-robots-txt - * This option allows the user to configure the included integration - * Options shown are the availble options - * REFERENCE https://www.npmjs.com/package/astro-robots-txt#configuration - */ - robotstxt: RobotsTxtSchema.optional(), /** Allows the user to turn on/off Full Console Logs * @default true */ fullConsoleLogs: z.boolean().optional().default(false), + /** Optional - astro-robots-txt + * This option allows the user to configure the included integration + * Options shown are the availble options + * @see https://www.npmjs.com/package/astro-robots-txt#configuration + */ + robotsTxt: z.custom().optional(), + /** OPTIONAL - astrojs/sitemap + * This option allows the user to configure the included integration + * Options shown are the availble options + * @see https://docs.astro.build/en/guides/integrations-guide/sitemap + */ + sitemap: z.custom().optional(), }); /** USER CONFIGURATION SCHEMA */ diff --git a/playgrounds/astro-playground/astro.config.mjs b/playgrounds/astro-playground/astro.config.mjs index 7e2bd462..f889c932 100644 --- a/playgrounds/astro-playground/astro.config.mjs +++ b/playgrounds/astro-playground/astro.config.mjs @@ -14,6 +14,7 @@ export default defineConfig({ ThemeProvider: { theme: "@matthiesenxyz/astro-ghostcms-brutalbyelian", }, + fullConsoleLogs: true, }), ], });