πŸ—“οΈ Everything *[NYC] is back. A free gathering for AI builders. Sept 9 β†’

sanity-plugin-hashtags

Sanity plugin providing a validated hashtags field with strict rules. (Sanity Studio v3)

Install command

npm i sanity-plugin-hashtags

sanity-plugin-hashtags

A simple Sanity Studio v3 plugin that adds a custom hashtag field type with built-in validation.

It ensures hashtags follow rules like #example #NextJS #SanityCMS, with options to configure max length, max tags, and spacing behavior.

Features

  • βœ… Custom type: "hashtag" field for Sanity schemas
  • βœ… Built-in validation (no need to re-import validation manually)
  • βœ… Configurable options:
    • maxTags β†’ limit number of hashtags (default: ∞)
    • maxLength β†’ limit length of each hashtag (default: 30)
    • allowSpaces β†’ allow/disallow spaces inside hashtags (default: false)
  • βœ… Error messages for invalid hashtags (empty, double ##, no #, etc.)

Installation

npm install sanity-plugin-hashtags
# or
yarn add sanity-plugin-hashtags
# or
pnpm add sanity-plugin-hashtags

Usage

Add the plugin to your Sanity config (sanity.config.ts):

import { defineConfig } from "sanity";
import { hashtagsPlugin } from "sanity-plugin-hashtags";

export default defineConfig({
  name: "default",
  title: "My Sanity Project",
  plugins: [hashtagsPlugin()],
});

Use the field in your schema:

import { defineType } from "sanity";

export const post = defineType({
  name: "post",
  title: "Post",
  type: "document",
  fields: [
    { name: "title", type: "string" },
    { name: "description", type: "text" },
    { name: "hashtags", type: "hashtags", title: "Hashtags" }, // πŸ‘ˆ new field
  ],
});

Example

Valid input:

#NextJS #SanityCMS #OpenSource

Invalid input will show errors, e.g.:

  • ❌ hello β†’ must start with #.
  • ❌ # β†’ cannot be empty.
  • ❌ #two#words β†’ must be separated by space.

Contributing

Want to contribute to this project? Awesome! πŸŽ‰

Please read our Contributing Guide for details on how to get started, development setup, coding guidelines, and the release process.

Related contributions