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

  1. Go to sanity.io/manage and create a new project
  2. Name it and choose Blank project as the template (BloggFast provides its own schema)
  3. Copy your Project ID from the project settings page
  4. Go to API → TokensAdd API token
  5. Name it (e.g., BloggFast Server), set permissions to Editor, and copy the generated token

Configure environment variables

.env.local
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:

sanity.config.ts
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

The 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/):

TypeFileWhat it represents
postpostType.tsFull blog articles with Portable Text body, cover image, author, category, and SEO fields
authorauthorType.tsAuthor profiles with name, bio, avatar image, and slug
categorycategoryType.tsArticle categories with title and description
blockContentblockContentType.tsRich 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.ts module merges content from both sources for listing pages
  • The article page renders Portable Text (Sanity) with @portabletext/react, or markdown (Postgres) with react-markdown

Articles share a slug as the common key between Prisma and Sanity records, allowing the app to look up content from either source.