Home Singleton Schema
Relevant source files
The following files were used as context for generating this wiki page:
The Home Singleton Schema defines the structure and behavior of the landing page content for the personal website. In Sanity Studio, a "singleton" is a unique document type intended to have only one instance, ensuring that global content like a homepage remains centralized and unique within the Content Lake. Sources: sanity/schemas/singletons/home.ts:4-6, sanity/plugins/settings.tsx:7-10
This schema manages core identity elements including the site title, an SEO-friendly overview description, and a curated list of showcase projects. It is integrated into the Studio via a custom singleton plugin that prevents duplication and hides it from standard "new document" menus. Sources: sanity.config.ts:54-55, sanity/plugins/settings.tsx:13-25
Data Model Definition
The home document type is defined using Sanity's defineType helper. It contains three primary fields: title, overview, and showcaseProjects.
Schema Fields
| Field Name | Type | Description | Constraints |
|---|---|---|---|
title | string | The main title of the personal website. | Required |
overview | array (Portable Text) | Description used for SEO meta tags and the subheader. | Required, max 155 chars |
showcaseProjects | array (References) | References to project documents to be featured. | None |
Sources: sanity/schemas/singletons/home.ts:11-73, sanity.types.ts:250-281
Field Logic and Relationships
- Overview: Implemented as an array of block content (Portable Text) restricted to simple paragraphs with italics, bolding, and links. Sources: sanity/schemas/singletons/home.ts:22-58
- Showcase Projects: Maintains an array of references to the
projectdocument type, allowing the editor to manually sort and select which projects appear on the landing page. Sources: sanity/schemas/singletons/home.ts:63-72
The diagram shows the relationship between the Home singleton and Project documents.
Sources: sanity/schemas/singletons/home.ts:68, sanity.types.ts:275-280
Singleton Implementation logic
To enforce the singleton pattern, the project utilizes a singletonPlugin and a custom pageStructure resolver.
Plugin Actions
The singletonPlugin modifies default Sanity Studio behavior for types designated as singletons:
- Filters New Document Options: Prevents users from creating multiple "Home" documents via the global "plus" button.
- Restricts Actions: Removes the "duplicate" action from the document editor to maintain a single source of truth.
Sources: sanity/plugins/settings.tsx:13-35, sanity.config.ts:54-55
Desk Structure
The pageStructure function maps the singleton type to a specific editor ID in the Studio's sidebar, ensuring the "Home" link always opens the specific home document ID. Sources: sanity/plugins/settings.tsx:43-50
Data Fetching and Querying
Content from the Home singleton is retrieved using a GROQ query that dereferences the showcaseProjects to provide full project details to the frontend.
GROQ Query Detail
The homePageQuery fetches the first document of type home and expands the project references:
*[_type == "home"][0]{
_id,
_type,
overview,
showcaseProjects[]{
_key,
...@->{
_id,
_type,
coverImage,
overview,
"slug": slug.current,
tags,
title,
}
},
title,
}
Sources: sanity/lib/queries.ts:3-21
Application Flow
The flow of data from the initial request to the rendered homepage component.
Sources: app/(personal)/page.tsx:7-24, components/HomePage.tsx:13-25
Frontend Rendering
The HomePage component consumes the data result from the singleton schema. It utilizes a Header component for the title and overview, and iterates through showcaseProjects to display them using ProjectListItem. Sources: components/HomePage.tsx:28-62
Component Mapping
| Schema Field | Component Property | Logic |
|---|---|---|
title | <Header title={title} /> | Passed directly as a string. |
overview | <Header description={overview} /> | Passed as Portable Text. |
showcaseProjects | <OptimisticSortOrder /> | Wraps the list for visual editing support. |
Sources: components/HomePage.tsx:39-49
Conclusion
The Home Singleton Schema provides a structured yet flexible way to manage site-wide landing page content. By combining Sanity's schema definitions with custom Studio plugins, the system ensures data integrity (preventing duplicates) while allowing high-fidelity content management for the end-user. Sources: sanity/schemas/singletons/home.ts:4-10, sanity.config.ts:42-55