Sanity CMS Setup
How to create a Sanity project, configure content types, and connect it to BloggFast.
Last updated:
What Sanity does in BloggFast
Sanity is the headless CMS for BloggFast. It provides a rich editing interface (Sanity Studio) embedded directly in your app at /studio — no separate server or deployment needed.
Sanity handles:
- Rich text article editing with Portable Text (blockContent)
- Image uploads with automatic optimization via the Sanity CDN
- Author and category management
- Draft/published workflow for editors
- Real-time collaborative editing
- GROQ query API for content retrieval
Create a Sanity project
- Go to sanity.io/manage and create a new project
- Name it and choose Blank project as the template (BloggFast provides its own schema)
- Copy your Project ID from the project settings page
- Go to API → Tokens → Add API token
- Name it (e.g.,
BloggFast Server), set permissions to Editor, and copy the generated token
Configure environment variables
NEXT_PUBLIC_SANITY_PROJECT_ID=your_project_id # e.g., pup1pp2q
NEXT_PUBLIC_SANITY_DATASET=production
SANITY_API_TOKEN=sk...Update sanity.config.ts
The sanity.config.ts file at the project root hardcodes the project ID and dataset. Update these to match your project:
const projectId = 'your_project_id' // Replace with your Sanity project ID
const dataset = 'production'
const apiVersion = '2026-03-16'
export default defineConfig({
basePath: '/studio',
projectId,
dataset,
schema,
plugins: [
structureTool({ structure }),
visionTool({ defaultApiVersion: apiVersion }),
],
})Note
sanity.config.ts uses hardcoded values rather than environment variables because it's a client-side config file used directly by the Sanity Studio. Make sure the project ID here matches your NEXT_PUBLIC_SANITY_PROJECT_ID env variable.Content types
BloggFast ships with these Sanity schema types (in src/sanity/schemaTypes/):
| Type | File | What it represents |
|---|---|---|
post | postType.ts | Full blog articles with Portable Text body, cover image, author, category, and SEO fields |
author | authorType.ts | Author profiles with name, bio, avatar image, and slug |
category | categoryType.ts | Article categories with title and description |
blockContent | blockContentType.ts | Rich text block definition — headlines, bold, italic, links, images, and code |
Dual content strategy
BloggFast uses a hybrid content storage approach. Articles can have their body content stored in either Postgres (as raw markdown in the body field) or Sanity (as Portable Text). The app handles both:
- AI-generated articles are saved directly to Postgres as markdown and optionally uploaded to Sanity
- Manually managed articles can be edited in Sanity Studio with full rich text
- The
unified-queries.tsmodule merges content from both sources for listing pages - The article page renders Portable Text (Sanity) with
@portabletext/react, or markdown (Postgres) withreact-markdown
Articles share a slug as the common key between Prisma and Sanity records, allowing the app to look up content from either source.