Woo Better config options!

This commit is contained in:
Adam Matthiesen 2024-03-03 09:51:00 -08:00
parent 657cfe7568
commit 017e641afd
6 changed files with 32 additions and 98 deletions

View File

@ -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
}
})
],
});

View File

@ -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(

View File

@ -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(),
});

View File

@ -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(),
});

View File

@ -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<RobotsTxtOptions>().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<SitemapOptions>().optional(),
});
/** USER CONFIGURATION SCHEMA */

View File

@ -14,6 +14,7 @@ export default defineConfig({
ThemeProvider: {
theme: "@matthiesenxyz/astro-ghostcms-brutalbyelian",
},
fullConsoleLogs: true,
}),
],
});