Person schema for Sanity and Astro
Someone on the site: an expert, a team member, a consultant, a reporter. The core is what every theme drew: a name, what they do, one line about them and a photo.
- Core fields
- 5
- Extensions
- 3 (9 fields)
- schema.org
- Person
- Licence
- MIT
Free, with no account. Same data in both editions: the Astro entry id is the Sanity slug.
Core fields
What every person has. A slug is added in Sanity.
| Field | Type | Required | What it holds |
|---|---|---|---|
| name | string | Yes | Name |
| role | string | Yes | RoleWhat they do here: Head of the help desk. |
| line | text | No | One lineOne sentence about them, for a card or a byline. |
| photo | image | No | PhotoSquare, at least 768 × 768. Without one, the initials show. |
| order | number | No | OrderLower comes first. |
Extensions
Fields for one kind of site, on top of the core. An extension never changes a core field, and there are no settings: a different need is a different extension.
byline: Byline
For people who write: what they cover, a short biography and where else to find them. Fits news, publishing, blogs, podcasts.
| Field | Type | Required | What it holds |
|---|---|---|---|
| beat | string | No | BeatWhat they cover: Housing and planning. |
| bio | text | No | BiographyFor the author page. Plain text; an empty line starts a new paragraph. |
| links | list of link | No | LinksProfiles and a website. The label says where it goes. |
contact: Direct contact
A direct line and address, for firms where you ask for a person by name (agents, lawyers, recruiters). Fits professional services, real estate, recruitment.
| Field | Type | Required | What it holds |
|---|---|---|---|
| phone | string | No | PhoneAs it should be dialled and shown: 020 7946 0321. |
| No |
expertise: Expertise
What a professional knows and since when: the fields a client picks an adviser by. Fits law, finance, health, real estate.
| Field | Type | Required | What it holds |
|---|---|---|---|
| specialisms | list of string | No | SpecialismsShort: Lease extensions, Probate. |
| languages | list of string | No | Languages |
| qualified | number | No | Qualified inThe year. |
| office | string | No | Office |
Get the code
Plain TypeScript with no package of ours: the files become your code. Tested in a new Sanity Studio and a new Astro project.
For your Studio: the document type, the same fields as an inline object, a GROQ projection and a list query, and the TypeScript type the projection returns.
Install with the shadcn CLI
npx shadcn@latest add https://www.themes.dev/sanity/r/person.jsonThe CLI needs a components.json in the project. No CLI? Copy the files below: they are all there is.
// Sanity schema: person v1.// From themes.dev content models (https://www.themes.dev/sanity/models/), MIT. Your code now: edit it freely.import { defineArrayMember, defineField, defineType } from 'sanity'; const fields = [ defineField({ name: 'name', title: 'Name', type: 'string', validation: (rule) => rule.required().max(60) }), defineField({ name: 'role', title: 'Role', description: 'What they do here: Head of the help desk.', type: 'string', validation: (rule) => rule.required().max(60) }), defineField({ name: 'line', title: 'One line', description: 'One sentence about them, for a card or a byline.', type: 'text', rows: 2, validation: (rule) => rule.max(160) }), defineField({ name: 'photo', title: 'Photo', description: 'Square, at least 768 × 768. Without one, the initials show.', type: 'image', options: { hotspot: true }, fields: [defineField({ name: 'alt', title: 'Alternative text', type: 'string', description: 'What it shows, for people who can’t see it. Empty when the text beside it says it.', validation: (rule) => rule.max(180) })] }), defineField({ name: 'order', title: 'Order', description: 'Lower comes first.', type: 'number', validation: (rule) => rule.integer() }),]; /** The id other entries refer to, and the Astro edition's entry id: the same string in both. */const slug = defineField({ name: 'slug', title: 'Slug', type: 'slug', description: 'Lowercase letters, digits and hyphens.', options: { source: 'name', maxLength: 64 }, validation: (rule) => rule.required() }); /** Someone on the site: an expert, a team member, a consultant, a reporter. The core is what every theme drew: a name, what they do, one line about them and a photo. */export const person = defineType({ name: 'person', title: 'Person', type: 'document', fields: [fields[0], slug, ...fields.slice(1)], orderings: [{ title: 'Order', name: 'order', by: [{ field: 'order', direction: 'asc' }] }], preview: { select: { title: 'name', subtitle: 'role', media: 'photo' } },}); /** The same fields as an object, for a page that keeps its own people inline. */export const personEntry = defineType({ name: 'personEntry', title: 'Person', type: 'object', fields, preview: { select: { title: 'name', subtitle: 'role', media: 'photo' } },}); /** GROQ: one person as the PersonRecord type (types/person.ts) describes it. */export const personProjection = `{ "id": slug.current, name, role, line, "photo": photo{ "src": asset->url, "alt": coalesce(alt, ""), "width": asset->metadata.dimensions.width, "height": asset->metadata.dimensions.height }, order }`; /** GROQ: every person, in order. */export const personListQuery = `*[_type == "person" && defined(slug.current)] | order(order asc, _createdAt asc) ${personProjection}`;// TypeScript types: person v1.// From themes.dev content models (https://www.themes.dev/sanity/models/), MIT. Your code now: edit it freely.import type { ImageRef } from './kinds'; /** Someone on the site: an expert, a team member, a consultant, a reporter. The core is what every theme drew: a name, what they do, one line about them and a photo. */export interface Person { name: string; /** What they do here: Head of the help desk. */ role: string; /** One sentence about them, for a card or a byline. */ line?: string; /** Square, at least 768 × 768. Without one, the initials show. */ photo?: ImageRef; /** Lower comes first. */ order?: number;} /** What the GROQ projection returns: the fields and the id (the slug, the same as the Astro entry's id). */export type PersonRecord = Person & { id: string };// Shared shapes of the generated content models./** An image: the path or URL without size suffix, and its alternative text (empty when the text beside it says it). */export interface ImageRef { src: string; alt: string; /** Intrinsic size, so the page reserves the box before the file arrives. */ width: number; height: number;} export interface Link { label: string; href: string;} /** Portable Text as Sanity stores it: blocks, and images with their alt text. */export type RichText = { _type: string; _key: string; [key: string]: unknown }[];Use it
In Sanity
// sanity.config.tsimport { person, personEntry } from './schemaTypes/person'; export default defineConfig({ // … schema: { types: [person, personEntry] },}); // In your site: the projection returns the Person type in types/person.ts.import { personListQuery } from './schemaTypes/person';const people = await client.fetch(personListQuery);In Astro
// src/content.config.tsimport { defineCollection } from 'astro:content';import { file } from 'astro/loaders';import { personSchema } from './models/person'; const people = defineCollection({ loader: file('./src/content/people.json'), schema: personSchema,}); export const collections = { people };An image is always { src, alt, width, height } in both editions: the GROQ projection reads the size from the asset, and in Astro it sits in your data, so pages never shift while they load.