Skip to content

Conversation

@mostlyerror
Copy link
Owner

Summary

This PR integrates Sanity.io as a headless CMS for managing blog content on the Good Robot Co. website. The implementation enables dynamic blog post creation and management while maintaining the static site architecture through Next.js static site generation.

Key Features

  • Sanity Studio integration with custom schema for blog posts, authors, and categories
  • Dynamic blog routing (/blog/[slug]) with static generation at build time
  • Rich text rendering using Portable Text with proper React component mapping
  • SEO optimization with metadata generation from Sanity documents
  • Image optimization through Sanity's image pipeline
  • Comprehensive testing including integration and build validation tests

Technical Changes

  • Added Sanity client configuration and TypeScript types
  • Implemented blogPost document type with rich content support
  • Created RichText component for Portable Text rendering
  • Updated blog listing page to fetch posts from Sanity
  • Added dynamic route handler with generateStaticParams for SSG
  • Extended GitHub Actions workflow with Sanity integration tests
  • Added build validation to ensure static output integrity

Configuration

  • Environment variables for Sanity project connection
  • Example .env.local.example file for local development
  • Updated tests/config.js to include new blog routes
  • Documentation in SANITY_SETUP.md for CMS configuration

Testing

  • Sanity Integration Tests: Validates CMS connectivity and data fetching at runtime
  • Build Validation Tests: Ensures blog posts generate correctly in static output
  • Smoke Tests: Updated workflow to test new blog routes
  • All tests integrated into GitHub Actions CI/CD pipeline

Test Plan

Prerequisites:

  • Set up Sanity project credentials in repository secrets (SANITY_PROJECT_ID)
  • Configure SANITY_DATASET variable (defaults to 'production')
  • Create at least one test blog post in Sanity Studio

Local Testing:

  1. Copy .env.local.example to .env.local and add Sanity credentials
  2. Run npm install to install new dependencies
  3. Run npm run dev and verify:
    • Blog listing page loads at /blog
    • Individual blog posts render at /blog/[slug]
    • Images display correctly via Sanity CDN
    • Rich text content renders properly
  4. Run test suites:
    • npm run test:smoke - All smoke tests pass
    • npm run test:sanity - Sanity integration tests pass
  5. Build and validate static output:
    • npm run build - Build completes successfully
    • npm run test:build - Build validation passes
    • Verify out/blog/ contains generated HTML files

CI/CD Testing:

  • GitHub Actions workflow runs successfully
  • All test jobs pass (smoke tests, Sanity integration, build validation)
  • Static build generates without errors

Sanity Studio Testing:

  1. Run npm run sanity:dev to launch Sanity Studio locally
  2. Verify schema types load correctly
  3. Create/edit test blog post and confirm changes reflect on site

Deployment Testing:

  • Vercel deployment succeeds with Sanity environment variables
  • Published blog posts display correctly on production
  • SEO metadata appears in page source
  • Open Graph images generate correctly

Documentation:

  • See SANITY_SETUP.md for detailed CMS configuration instructions
  • See PLAYBOOK.md for development workflow and best practices

🤖 Generated with Claude Code

Integrates Sanity.io as the headless CMS for blog content, replacing
static content with dynamic content management capabilities. This enables
easy blog post creation, editing, and management through Sanity Studio.

Key additions:
- Sanity client configuration and schema types
- Blog post document type with rich text support
- Dynamic blog routes with static generation
- Portable Text rendering component
- Integration tests for CMS functionality
- Build validation for static site generation
- Environment configuration and documentation

Technical implementation:
- Next.js 14 App Router with generateStaticParams
- Sanity client with proper TypeScript types
- Portable Text to React component rendering
- SEO metadata from Sanity documents
- Image optimization via Sanity's image pipeline

Testing coverage:
- Sanity integration tests (runtime)
- Build validation tests (static output)
- Updated GitHub Actions workflow with new test suites

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Jan 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
goodrobotco.com Ready Ready Preview, Comment Jan 12, 2026 2:01am

This commit fixes multiple build issues that were causing GitHub Actions to fail:

1. **Upgrade Next.js 14 → 15**: Resolve peer dependency conflict with next-sanity@11.6.12
   which requires Next.js 15+

2. **Handle Next.js 15 breaking changes**:
   - Update blog/[slug]/page.tsx to handle async params (now Promise-based)
   - Add `export const dynamic = 'force-static'` to robots.ts and sitemap.ts
     for static export compatibility

3. **Fix image handling**: Add proper null checks for featuredImage.asset
   to prevent build errors when images don't have asset references

4. **Update .gitignore**: Add .env and /dist to prevent committing sensitive
   config and build artifacts

The tsconfig.json changes were automatically applied by Next.js 15 for
top-level await support (target: ES2017).

Note: A sample blog post was created in Sanity to satisfy static export
requirements (dynamic routes need at least one static path).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add null checks for featuredImage.asset in blog listing page to prevent
build errors when images don't have asset references. This matches the
fix applied to the blog post detail page.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Next.js 15 changed the static export structure:
- Blog listing: out/blog.html (was out/blog/index.html)
- Blog posts: out/blog/{slug}.html (was out/blog/{slug}/index.html)

Updated the validation test to check for the new file structure.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mostlyerror mostlyerror merged commit fd12df7 into main Jan 12, 2026
5 checks passed
@mostlyerror mostlyerror deleted the sanity-cms-integration branch January 12, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants