import { createClient } from '@sanity/client'; import imageUrlBuilder from '@sanity/image-url'; import type { SanityImageSource } from '@sanity/image-url/lib/types/types'; export const sanityClient = createClient({ projectId: import.meta.env.PUBLIC_SANITY_PROJECT_ID || 'your-project-id', dataset: import.meta.env.PUBLIC_SANITY_DATASET || 'production', apiVersion: '2024-01-01', useCdn: true, }); const builder = imageUrlBuilder(sanityClient); export function urlFor(source: SanityImageSource) { return builder.image(source); } // --- Types --- export interface Project { _id: string; title: string; slug: { current: string }; category: 'perenne' | 'event'; client: string; date: string; location?: string; description: string; heroImage: SanityImageSource & { alt?: string }; gallery: Array; tags?: string[]; featured?: boolean; order?: number; } export interface ProcessStep { _id: string; title: string; stepNumber: number; subtitle: string; description: any; // Block content icon?: SanityImageSource; gallery?: Array; duration?: string; } // --- Queries --- export async function getProjects(category?: 'perenne' | 'event'): Promise { const filter = category ? `*[_type == "project" && category == "${category}"]` : `*[_type == "project"]`; return sanityClient.fetch(`${filter} | order(order asc, date desc) { _id, title, slug, category, client, date, location, description, heroImage { ..., alt }, gallery[] { ..., alt, size }, tags, featured, order }`); } export async function getProjectBySlug(slug: string): Promise { return sanityClient.fetch( `*[_type == "project" && slug.current == $slug][0] { _id, title, slug, category, client, date, location, description, heroImage { ..., alt }, gallery[] { ..., alt, size }, tags, featured, order }`, { slug } ); } export async function getProcessSteps(): Promise { return sanityClient.fetch(`*[_type == "processStep"] | order(stepNumber asc) { _id, title, stepNumber, subtitle, description, icon, duration, gallery[] { ..., alt, caption } }`); } export async function getFeaturedProjects(): Promise { return sanityClient.fetch(`*[_type == "project" && featured == true] | order(order asc) { _id, title, slug, category, client, date, heroImage { ..., alt }, description, tags }`); }