Tillitsdone
down Scroll to discover

Best Practices for Structuring Content in Sanity

Discover essential best practices for organizing and structuring your content in Sanity CMS when building Astro.js websites.

Learn about schema design, content architecture, and optimization strategies.
thumbnail

A modern abstract composition featuring floating geometric shapes and flowing lines dominated by emerald green and soft white tones captured from a top-down perspective with dramatic lighting high-quality ultra-realistic cinematic 8K UHD high resolution sharp and detail

As the web development landscape evolves, combining Astro.js with Sanity CMS has emerged as a powerful solution for building modern websites. Today, let’s dive into the best practices for structuring your content in Sanity when working with Astro.js projects.

Understanding Content Architecture

Before diving into the technical details, it’s crucial to establish a solid foundation for your content structure. Think of your content as building blocks that need to be both flexible and maintainable.

Abstract architectural structure with interconnected translucent layers in breezeway blue and etched glass colors shot from a low angle perspective with natural light streaming through high-quality ultra-realistic cinematic 8K UHD high resolution sharp and detail

Schema Design Principles

When designing your Sanity schemas for Astro.js projects, consider these key principles:

1. Modular Content Types

Break down your content into reusable components. Instead of creating monolithic content types, design smaller, modular pieces that can be combined in different ways. For example:

export default {
name: 'contentBlock',
title: 'Content Block',
type: 'object',
fields: [
{
name: 'heading',
type: 'string',
},
{
name: 'content',
type: 'array',
of: [{ type: 'block' }]
}
]
}

2. References and Relationships

Leverage Sanity’s reference system to create relationships between content types. This approach helps maintain content consistency and enables dynamic updates across your site:

{
name: 'author',
type: 'reference',
to: [{ type: 'person' }]
}

3. Portable Text for Rich Content

Utilize Portable Text for rich content editing. It provides a flexible structure that works seamlessly with Astro’s rendering system:

{
name: 'body',
type: 'array',
of: [
{ type: 'block' },
{ type: 'image' },
{ type: 'code' }
]
}

Optimizing for Astro.js Integration

When building your Sanity schema with Astro.js in mind, consider these optimization strategies:

1. Static vs Dynamic Content

Identify which content needs to be static and which requires dynamic loading. Structure your schemas accordingly to leverage Astro’s partial hydration features effectively.

2. Image Handling

Implement proper image handling using Sanity’s asset pipeline. Define image schemas with multiple variations to support responsive designs:

{
name: 'mainImage',
type: 'image',
options: {
hotspot: true
},
fields: [
{
name: 'alt',
type: 'string',
title: 'Alternative Text',
}
]
}

3. SEO Optimization

Include SEO-focused fields in your schemas to take advantage of Astro’s excellent SEO capabilities:

{
name: 'seo',
title: 'SEO Settings',
type: 'object',
fields: [
{
name: 'metaTitle',
type: 'string',
},
{
name: 'metaDescription',
type: 'text',
}
]
}

Content Validation and Governance

Implement strong validation rules to maintain content quality and consistency across your site:

  1. Set up custom validation rules for different content types
  2. Establish clear naming conventions for fields and types
  3. Use field-level validation to ensure data integrity

Deployment and Performance Considerations

Remember to optimize your content structure for performance:

  1. Use appropriate field types to minimize query complexity
  2. Implement efficient content revalidation strategies
  3. Consider content caching patterns for frequently accessed data

Futuristic abstract network of light beams flowing through a minimal architectural space rendered in sun-washed brick and whisper white colors captured from a diagonal perspective high-quality ultra-realistic cinematic 8K UHD high resolution sharp and detail

Conclusion

Following these best practices will help you create a robust content structure that leverages the best of both Sanity and Astro.js. Remember to keep your schema design flexible enough to accommodate future changes while maintaining a clear and organized content architecture.

Abstract geometric patterns creating a flowing composition with interconnected shapes featuring minimal modern greys and soft white tones photographed from an aerial perspective high-quality ultra-realistic cinematic 8K UHD high resolution sharp and detail

icons/code-outline.svg AstroJs Blogs
Astro is an all-in-one web framework. It includes everything you need to create a website, built-in.
icons/logo-tid.svg
Talk with CEO
Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.