sanity-plugin-hashtags
Sanity plugin providing a validated hashtags field with strict rules. (Sanity Studio v3)
Install command
npm i sanity-plugin-hashtagssanity-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-hashtagsUsage
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 #OpenSourceInvalid 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.