@gluhar/studio

中文文档
6.4.1发布于 2026/11/16MITTypeScriptES Module近 30 天下载 2780

Sanity Studio plugin with everything gluhar Studios share: field-level i18n types, rich text, links, SEO, slugs, singletons, media, the language filter, and Presentation from the content registry.

原始使用文档
文档目录5 节
  1. What gluhar() registers
  2. Presentation ( presentation() )
  3. Rich text
  4. Helpers
  5. Development

@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 localeBlockParagraphsfield-level i18n, one field per locale (read with l() on the site)
richtextportable 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
paragraphstext with marks only — no styles, no blocks
link nestedLinkpage reference (to linkTypes, default ['page']) or custom URL; name, new tab, query params
seo defaultSeotitle, description, OG image
gluharSlug uidslug generated from the default-locale name; stable key with "Generate from Name"
faq location
pageonly 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 /:slug doesn't swallow /en); the homepage from the default type's homeSlug.
  • locations: each routed document in every locale ("Name — EN"), titled from name.<defaultLocale> (titleField to change).
  • previewMode defaults to @nuxtjs/sanity's /preview/enable + /preview/disable. Any other presentationTool option 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's url). 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.

版本与发布记录

@gluhar/studio 共发布 22 个版本,首次发布于 2026/10/21;过去 12 个月发布了 22 个版本。

版本发布日期距今
6.4.1latest2026/11/16今天
6.4.02026/11/161 天前
6.3.22026/11/161 天前
6.3.12026/11/151 天前
6.3.02026/11/151 天前
6.2.02026/11/151 天前

其他发布通道:next → 6.0.0-next.12。

关于 @gluhar/studio 的常见问题

@gluhar/studio 是什么?

Sanity Studio plugin with everything gluhar Studios share: field-level i18n types, rich text, links, SEO, slugs, singletons, media, the language filter, and Presentation from the content registry.

如何安装 @gluhar/studio?

在项目目录运行 npm install @gluhar/studio,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.2)、sanity(^6.4.0)、react-dom(^19.2)、styled-components(^6.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gluhar/studio 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gluhar/studio 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@gluhar/studio 可以商用吗?

@gluhar/studio 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gluhar/studio 的下载量有多少?

根据 npm 官方下载统计,@gluhar/studio 在 2026/10/17 – 2026/11/15 这 30 天内被下载 2,780 次,日均约 93 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gluhar/studio 还在维护吗?

最新版本 6.4.1 发布于 2026/11/16(今天);至今共发布 22 个版本,其中过去 12 个月发布了 22 个;首次发布于 2026/10/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。