Skip to content

Instantly share code, notes, and snippets.

View cupofcrazy's full-sized avatar
🌠
wavy.

Tobi cupofcrazy

🌠
wavy.
View GitHub Profile
@cupofcrazy
cupofcrazy / word-count.tsx
Created April 17, 2025 02:21
Word Count input component for Sanity.io Portable Text
import { useFormValue } from 'sanity'
import { Flex, Badge, Inline } from '@sanity/ui'
import { PortableTextBlock } from '@portabletext/types'
export const WordCount = (props: any) => {
const content = useFormValue(props.path) as PortableTextBlock[]
const countWords = (blocks: PortableTextBlock[]): number => {
if (!blocks) return 0
@cupofcrazy
cupofcrazy / structure.ts
Created October 4, 2024 01:58
Sanity Structure Template
import { type StructureBuilder } from "sanity/structure";
export const structure = (S: StructureBuilder) => {
return S.list()
.title("Content")
.items([
S.listItem()
.title("Home")
.icon(INSERT_ICON_HERE)
@cupofcrazy
cupofcrazy / schemas.ts
Last active April 17, 2025 02:26
Personal reusable Sanity schema types (WIP)
// A11Y Image with alt
const a11yImage = defineType({
name: 'a11yImage',
title: 'A11y Image',
type: 'object',
fields: [
defineField({
name: 'shot',
title: 'Shot',