Socket
Book a DemoInstallSign in
Socket

@ismarslomic/sanity-plugin-tag-hierarchy

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ismarslomic/sanity-plugin-tag-hierarchy

A multi-tag input supporting tag hierarchy and tag management

1.0.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

sanity-plugin-tag-hierarchy

CI & Release

This is a Sanity Studio v3 plugin.

A multi-tag input supporting tag hierarchy (max 2 levels), grouping tagged documents in Desk tool and browsing documents by tags in the Studio.

Installation

npm install @ismarslomic/sanity-plugin-tag-hierarchy

Usage

Add it as a plugin in sanity.config.ts (or .js):

import {defineConfig} from 'sanity'
import {tagHierarchy} from 'sanity-plugin-tag-hierarchy'

export default defineConfig({
  //...
  plugins: [tagHierarchy({})],
})

Parent/child tags

This plugin supports tag hierarchy of 2 levels: Parent and Child.

A "Parent" Tag is any tag document that does not have the parent field defined.

A "Child" Tag is any tag document with a parent field reference.

Add tag input to schema

Allow selecting multiple tags, but only child tags:

defineField({
  name: 'tags',
  type: 'array',
  of: [
    {
      type: 'reference',
      to: {type: 'tag'},
      options: {
        filter: 'defined(parent)',
        disableNew: true,
      },
    }
  ]
})

Screenshot: Tag reference in Post document

tag-reference.png

Add Parent-Child tag structure in Desk

import { createDeskHierarchy } from 'sanity-plugin-tag-hierarchy'

export default defineConfig({
  plugins: [
    deskTool({
      structure: (S: StructureBuilder, context: StructureResolverContext) => {
        return S.list()
          .title('Content')
          .items([
            createDeskHierarchy(S, context.documentStore, 'Tags')
          ])
      },
    }),
  ]
})

Screenshot: Parent tag structure in Sanity Desk

tag-reference.png

Screenshot: Child tag structure in Sanity Desk

tag-reference.png

License

MIT © Ismar Slomic

Develop & test

This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.

See Testing a plugin in Sanity Studio on how to run this plugin with hotreload in the studio.

Release new version

We use the Sanity semantic-release to automate publish to NPM.

Run "CI & Release" workflow.

Make sure to select the main branch and check "Release new version".

Semantic release will only release on configured branches, so it is safe to run release on any branch.

Keywords

sanity

FAQs

Package last updated on 12 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.