Skip to content

Commit

Permalink
add descriptions and update schema previews
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Christ committed Aug 3, 2024
1 parent 921e8f2 commit adf5c17
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 41 deletions.
7 changes: 5 additions & 2 deletions sanity/schemas/documents/announcement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineField, defineType } from 'sanity'
import { VscMegaphone } from 'react-icons/vsc'
import { VscMegaphone, VscCalendar } from 'react-icons/vsc'
import { getBlockText } from '@sanity/src/utils'

export default defineType({
Expand Down Expand Up @@ -41,10 +41,13 @@ export default defineType({
select: {
content: 'content',
cta: 'cta.label',
start: 'start',
end: 'end',
},
prepare: ({ content, cta }) => ({
prepare: ({ content, cta, start, end }) => ({
title: getBlockText(content),
subtitle: cta,
media: (start || end) && VscCalendar,
}),
},
})
6 changes: 4 additions & 2 deletions sanity/schemas/documents/logo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defineField, defineType } from 'sanity'
import { VscSymbolMisc } from 'react-icons/vsc'
import { VscVerified } from 'react-icons/vsc'

export default defineType({
name: 'logo',
title: 'Logo',
icon: VscSymbolMisc,
icon: VscVerified,
type: 'document',
fields: [
defineField({
Expand All @@ -24,10 +24,12 @@ export default defineType({
}),
defineField({
name: 'light',
description: 'On dark backgrounds',
type: 'image',
}),
defineField({
name: 'dark',
description: 'On light backgrounds',
type: 'image',
}),
],
Expand Down
11 changes: 10 additions & 1 deletion sanity/schemas/documents/page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineField, defineType } from 'sanity'
import { VscHome, VscEyeClosed, VscQuestion } from 'react-icons/vsc'

export default defineType({
name: 'page',
Expand All @@ -17,6 +18,7 @@ export default defineType({
}),
defineField({
name: 'modules',
description: 'Page content',
type: 'array',
of: [
{ type: 'accordion-list' },
Expand Down Expand Up @@ -54,10 +56,17 @@ export default defineType({
select: {
title: 'title',
slug: 'metadata.slug.current',
media: 'metadata.image',
noindex: 'metadata.noIndex',
},
prepare: ({ title, slug }) => ({
prepare: ({ title, slug, media, noindex }) => ({
title,
subtitle: slug && (slug === 'index' ? '/' : `/${slug}`),
media:
media ||
(slug === 'index' && VscHome) ||
(slug === '404' && VscQuestion) ||
(noindex && VscEyeClosed),
}),
},
})
34 changes: 22 additions & 12 deletions sanity/schemas/documents/redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,38 @@ export default defineType({
fields: [
defineField({
name: 'source',
title: 'Redirect from',
placeholder: 'e.g. /old-path, /old-blog/:slug',
type: 'string',
placeholder: '/, /blog/:path*, etc',
}),
defineField({
name: 'destination',
title: 'Redirect to',
placeholder: 'e.g. /new-path, /blog/:slug',
type: 'string',
placeholder: '/, /blog/:path*, etc',
description: (
<a
href="https://nextjs.org/docs/app/api-reference/next-config-js/redirects"
target="_blank"
>
Next.js Documentation
</a>
),
}),
defineField({
name: 'permanent',
type: 'boolean',
initialValue: true,
description:
'If true will use the 308 status code which instructs clients/search engines to cache the redirect forever, if false will use the 307 status code which is temporary and is not cached.',
description: (
<>
<p>
If <code>true</code> will use the 308 status code which instructs
clients/search engines to cache the redirect forever, if{' '}
<code>false</code> will use the 307 status code which is temporary
and is not cached.
</p>
<p>
<a
href="https://nextjs.org/docs/app/api-reference/next-config-js/redirects"
target="_blank"
>
Next.js redirects documentation
</a>
</p>
</>
),
}),
],
preview: {
Expand Down
37 changes: 20 additions & 17 deletions sanity/schemas/documents/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineField, defineType } from 'sanity'

export default defineType({
name: 'site',
title: 'Site',
title: 'Site settings',
type: 'document',
groups: [
{ name: 'general', title: 'General', default: true },
Expand All @@ -29,26 +29,17 @@ export default defineType({
type: 'array',
of: [{ type: 'reference', to: [{ type: 'announcement' }] }],
group: 'general',
description: 'Higher order has higher precedence',
description:
'One announcement shown at a time. Top items have higher precedence.',
}),
defineField({
name: 'ctas',
title: 'Call-to-action',
title: 'Call-to-action (Site-wide)',
description: 'Typically used in the header and/or footer.',
type: 'array',
of: [{ type: 'cta' }],
group: 'general',
}),
defineField({
name: 'copyright',
type: 'array',
of: [
{
type: 'block',
styles: [{ title: 'Normal', value: 'normal' }],
},
],
group: 'general',
}),
defineField({
name: 'headerMenu',
type: 'reference',
Expand All @@ -67,17 +58,29 @@ export default defineType({
to: [{ type: 'navigation' }],
group: 'navigation',
}),
defineField({
name: 'copyright',
type: 'array',
of: [
{
type: 'block',
styles: [{ title: 'Normal', value: 'normal' }],
},
],
group: 'general',
}),
defineField({
name: 'ogimage',
title: 'Open Graph Image (global)',
description: 'Used for social sharing previews',
title: 'Open Graph Image (Site-wide)',
description:
'Used for social sharing previews. Set page-specific images in Page documents.',
type: 'image',
group: 'general',
}),
],
preview: {
prepare: () => ({
title: 'Site',
title: 'Site settings',
}),
},
})
4 changes: 2 additions & 2 deletions sanity/schemas/documents/testimonial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default defineType({
author: 'author',
},
prepare: ({ content, author }) => ({
title: getBlockText(content),
subtitle: author?.name || author?.title || 'No author',
title: author?.name || author?.title || 'No author',
subtitle: getBlockText(content),
media: author?.image,
}),
},
Expand Down
4 changes: 3 additions & 1 deletion sanity/schemas/objects/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default defineType({
}),
defineField({
name: 'external',
placeholder: 'https://example.com',
type: 'url',
validation: (Rule) =>
Rule.uri({
Expand All @@ -43,7 +44,8 @@ export default defineType({
}),
defineField({
name: 'params',
title: 'URL params',
title: 'URL parameters',
placeholder: 'e.g. #jump-link or ?foo=bar',
type: 'string',
hidden: ({ parent }) => parent?.type !== 'internal',
}),
Expand Down
1 change: 1 addition & 0 deletions sanity/schemas/objects/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineField, defineType } from 'sanity'
export default defineType({
name: 'metadata',
title: 'Metadata',
description: 'For search engines',
type: 'object',
fields: [
defineField({
Expand Down
6 changes: 3 additions & 3 deletions sanity/src/structure.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { group, singleton } from './utils'
import type { StructureResolver } from 'sanity/structure'

import { VscServerProcess } from 'react-icons/vsc'
import { VscMultipleWindows, VscServerProcess } from 'react-icons/vsc'
import { BsDatabaseAdd } from 'react-icons/bs'

const structure: StructureResolver = (S, context) =>
S.list()
.title('Content')
.items([
singleton(S, 'site').icon(VscServerProcess),
S.documentTypeListItem('page').title('Pages'),
singleton(S, 'site').title('Site settings').icon(VscServerProcess),
S.documentTypeListItem('page').title('Pages').icon(VscMultipleWindows),
S.divider(),

S.documentTypeListItem('navigation'),
Expand Down
2 changes: 1 addition & 1 deletion src/types/Sanity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ declare global {
logo?: Logo
announcements?: Announcement[]
ctas?: CTA[]
copyright?: any
headerMenu?: Navigation
footerMenu?: Navigation
social?: Navigation
copyright?: any
ogimage?: string
}>

Expand Down

0 comments on commit adf5c17

Please sign in to comment.