@gluhar/studio
Sanity Studio plugin with everything gluhar Studios share. It replaces the hand-copied schemas/gluhar/ folder and src/ helpers in each project. Sanity 6, React 19.
// sanity/sanity.config.ts
import { defineConfig } from 'sanity'
import { structureTool } from 'sanity/structure'
import { gluhar } from '@gluhar/studio'
import { locales, defaultLocale } from '../config/i18n.config'
export default defineConfig({
...api,
plugins: [
structureTool({ structure }),
gluhar({
locales,
defaultLocale,
singletons: { types: ['header', 'footer', 'defaultSeo'], ids: ['homepage'] },
page: { sections: ['hero', 'textSection'] },
}),
],
schema: { types: projectSchemas },
})
The Studio's package.json must declare sanity, react, react-dom and styled-components itself (the Sanity CLI checks the declaration, not only the install).
What gluhar() registers
| Types | |
|---|---|
localeString localeText localeBlock localeBlockParagraphs | field-level i18n, one field per locale (read with l() on the site) |
richtext | portable text: normal / h2–h4, strong / em / strike / highlight, link annotation, and image (alt, caption, hotspot), videoFile, videoEmbed (YouTube), table. One array per locale when there are 2+ locales |
paragraphs | text with marks only — no styles, no blocks |
link nestedLink | page reference (to linkTypes, default ['page']) or custom URL; name, new tab, query params |
seo defaultSeo | title, description, OG image |
gluharSlug uid | slug generated from the default-locale name; stable key with "Generate from Name" |
faq location | |
page | only when page is passed — or build your own from pageFields() |
Plus: singleton handling (no "create", only publish / discard / restore), sanity-plugin-media, and @sanity/language-filter on locale* fields (2+ locales). Turn any off with media: false, languageFilter: false, richText: false. @sanity/vision is off by default; add it with vision: true.
Content Releases and Scheduled drafts stay in the project's defineConfig, not the plugin. Sanity reads releases.enabled from the workspace config only, so a plugin can't turn it off. The starter disables both:
export default defineConfig({
// ...
releases: { enabled: false },
scheduledDrafts: { enabled: false },
})
Projects keep their own schemas and structure. Delete the project's copies of everything above, or Sanity reports duplicate types.
Presentation (presentation())
Visual editing wired from the site's content registry (config/content.config.ts, see @gluhar/routes), so mainDocuments and locations stay in step with the site's router:
import { createContentRoutes, documentUrl, gluhar, presentation } from '@gluhar/studio'
import registry from '../config/content.config'
import { locales, defaultLocale } from '@locale-config'
const routes = createContentRoutes(registry, { locales, defaultLocale })
export default defineConfig({
plugins: [
structureTool({ structure, defaultDocumentNode }),
presentation({ routes, origin: process.env.SANITY_STUDIO_PREVIEW_URL || 'http://localhost:3000' }),
gluhar({ locales, defaultLocale /* … */ }),
],
})
mainDocuments: every routed type at its prefix, per locale, prefixed locales first (so/:slugdoesn't swallow/en); the homepage from the default type'shomeSlug.locations: each routed document in every locale ("Name — EN"), titled fromname.<defaultLocale>(titleFieldto change).previewModedefaults to @nuxtjs/sanity's/preview/enable+/preview/disable. Any otherpresentationTooloption passes through.- Prefixes are the registry's literal ones (the Studio can't read the uid → slug map): rename an index page and update its
prefix. documentUrl(routes, origin)→(doc) => url, for a preview pane (sanity-plugin-iframe-pane'surl). No?preview=true: drafts show only with a preview session, which Presentation sets.
If the Studio imports config/content.config.ts and config/i18n.config.ts from the project, keep both plain static modules: they're bundled into the Studio.
Rich text
The richtext block types (richTextTypes) are a contract with @gluhar/sanity's renderer — rename one and it renders as nothing on the site. Variants:
import { defineRichText } from '@gluhar/studio'
defineRichText({ name: 'articleBody', styles: ['normal', 'h2', 'h3'], types: ['image', 'table'] }, locales)
Helpers
pageFields({ defaultLocale, sections }),pagePreview(defaultLocale)— compose a project-specific page type.singletonItem(S, { id, title, icon })— the structure half of a singleton.generateKeyFrom('name.bg'),LocaleStringSameAs,HighlightDecorator— inputs.isUniqueAcrossAllDocuments— slug uniqueness across every type (options.isUnique).
Development
npm run build (pkg-utils) · npm run typecheck · playground: cd playground && npx sanity schema validate && npx sanity build.
pkg-utils is pinned to 10.x — 11+ requires TypeScript 6, and the Nuxt modules' builder still requires 5.9.