import { z } from "zod";
import { defaultsDeep } from "lodash-es";
// Default attributes
export const pageAttributesSchema = z.object({
tags: z
.array(z.string().describe("A tag for the page. Should be url-safe."))
.max(8)
.default([])
.describe(
"Use tags to organize, group and filter pages in navigation elements and in the dashboard. By default, the navbar element display pages having the 'navbar' tag, while the sidebar displays the pages with the tag 'sidebar'.",
),
label: z.string().describe("A short internal label for the page"),
path: z
.string()
.regex(/^\/[a-zA-Z0-9\-_:\/]*$/)
.describe("The URL path of the page. Use placeholders like :id or :slug for dynamic paths."),
layout: z
.string()
.describe(
"The layout to use for this page. Ex: 'default', 'main', 'no-sidebar'. Must correspond to a layout defined in config/layouts.",
),
title: z
.string()
.nullable()
.describe(
"The title of the page. Appears in the browser tab and search results. Can be null if defined dynamically within page using
.",
),
description: z
.string()
.nullable()
.default(null)
.describe(
'A short description of the page. Used by search engines. Can be null if defined dynamically within page using .',
),
keywords: z
.string()
.nullable()
.default(null)
.describe(
'Keywords related to the page. Used by search engines. Can be null if defined dynamically within page using .',
),
robotsIndexing: z
.boolean()
.default(true)
.describe("Disabling this will prevent search engines from indexing this page"),
language: z
.string()
.optional()
.describe("Overrides the site language for this page. Leave blank to use the site default language."),
additionalTags: z
.object({
headTags: z
.string()
.optional()
.describe(
"Add custom tags to the of your site. Useful for analytics tags, custom scripts, etc.",
),
bodyTags: z
.string()
.optional()
.describe(
"Add custom tags to the of your site. Useful for analytics tags, custom scripts, etc.",
),
})
.optional()
.describe("Additional custom tags to be inserted in or of the page."),
custom: z
.looseObject({})
.optional()
.describe("A free-form object where you can add any custom attributes you need for your page."),
});
export const siteAttributesSchema = z.object({
label: z
.string()
.describe(
"A short, human-friendly internal label for the site, derived from its purpose (e.g. 'Acme Marketing Site', 'John's Portfolio'). Must never be left as the template placeholder 'My Site (REPLACE ME)'.",
),
supportedLanguages: z
.array(z.string().length(2).describe("2-letter code (e.g., 'en', 'fr', etc.)"))
.default([])
.describe("All languages supported by the site. Must include the default language."),
defaultLanguage: z
.string()
.length(2)
.nullable()
.describe("Site default language. 2-letter code. If null, it means it has not been defined yet."),
themes: z.object({
default: z.enum(["light", "dark"]).describe("The default theme to use ('light' or 'dark')."),
light: z.string().describe("The theme ID to use for light mode."),
dark: z
.string()
.nullable()
.optional()
.describe("The theme ID to use for dark mode. If not set, light mode theme will be used"),
}),
designSystem: z
.enum(["daisy-ui", "shadcn-ui"])
.default("daisy-ui")
.describe(
"The design system to use for the site. Either daisy-ui or shadcn-ui. Cannot be changed after being set.",
),
headTags: z
.string()
.optional()
.nullable()
.describe("Add custom tags to the of your site. Useful for analytics tags, custom scripts, etc."),
bodyTags: z
.string()
.optional()
.nullable()
.describe("Add custom tags to the of your site. Useful for analytics tags, custom scripts, etc."),
envVars: z
.array(
z.object({
name: z
.string()
.regex(/^[A-Z0-9_]+$/)
.describe(
"Variable name (e.g., API_KEY, DATABASE_URL, etc.). Note: Prefix with PUBLIC_ for variables that are used client-side (those won't be secret!).",
),
description: z.string().describe("A short description of the environment variable and its purpose."),
}),
)
.optional()
.nullable()
.describe("Environment variables name and description. NO VALUE SHOULD BE STORED HERE."),
custom: z
.looseObject({})
.optional()
.nullable()
.describe("A free-form object where you can add any custom attributes you need for your site."),
favicon: z
.string()
.nullable()
.optional()
.describe(
"Path to the image shown on the browser tab, relative to the site root (e.g. '/images/favicon.png'). Recommended size 32x32 or 48x48, .png, .svg or .ico. Leave empty to use /favicon.ico.",
),
socialImage: z
.string()
.nullable()
.optional()
.describe(
"Path to the image shown when a page of the site is shared on social networks or messaging apps (Open Graph), relative to the site root (e.g. '/images/social-preview.webp'). Recommended size 1200x630.",
),
});
export type PageAttributes = z.infer;
export type SiteAttributes = z.infer;
export function definePageAttributes(data: z.input): PageAttributes {
return pageAttributesSchema.parse(data);
}
export function resolvePageAttributes(data: Partial = {}) {
const defaults = pageAttributesSchema.safeParse({});
return defaultsDeep({}, defaults.data ?? {}, data) as PageAttributes;
}
export function resolveSiteAttributes(data: Partial = {}) {
const defaults = siteAttributesSchema.safeParse({});
return defaultsDeep({}, defaults.data ?? {}, data) as SiteAttributes;
}