@resonia/sanity-plugin-trenddraft
v0.2.0
Published
TrendDraft AI content generation for Sanity Studio
Maintainers
Readme
@resonia/sanity-plugin-trenddraft
AI content generation for Sanity Studio powered by TrendDraft
Status: ✅ Published to npm (v0.1.0)
Generate AI-powered content directly in Sanity Studio with your unique voice and style. TrendDraft learns your writing patterns and incorporates your opinions into generated content.
Features
- AI Content Generation - Generate content from titles/topics directly in text fields
- Style Profiles - Use your TrendDraft style profiles for consistent voice
- Opinion Alignment - AI incorporates your recorded opinions and perspectives
- Content Goals - Specify goals (Educate, Convert, Engage, etc.)
- Field-Level Generation - Works on text, string, and rich text fields
Installation
npm install @resonia/sanity-plugin-trenddraft
# or
pnpm add @resonia/sanity-plugin-trenddraft
# or
yarn add @resonia/sanity-plugin-trenddraftConfiguration
Add it as a plugin in your sanity.config.ts:
import { defineConfig } from 'sanity';
import { trenddraft } from '@resonia/sanity-plugin-trenddraft';
export default defineConfig({
// ... other config
plugins: [
trenddraft({
apiKey: process.env.SANITY_STUDIO_TRENDDRAFT_API_KEY!,
defaultStyleProfile: 'company-voice', // optional
enableOpinionAlignment: true, // optional, default: true
fields: ['body', 'excerpt', 'metaDescription'], // optional
defaultWordCount: 800, // optional, default: 800
}),
],
});Environment Variables
Create a .env file in your Sanity studio:
SANITY_STUDIO_TRENDDRAFT_API_KEY=your_api_key_hereConfiguration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiKey | string | Required | Your TrendDraft API key |
| defaultStyleProfile | string | - | Default style profile ID |
| enableOpinionAlignment | boolean | true | Include opinions in generation |
| fields | string[] | ['body', 'content', 'excerpt', 'description'] | Fields to enable TrendDraft on |
| defaultWordCount | number | 800 | Default target word count |
| apiUrl | string | - | Custom API URL (for testing) |
Usage
Once configured, TrendDraft adds a "Generate with TrendDraft" button below enabled text fields:
- Click "Generate with TrendDraft" on any enabled field
- Enter a title/topic for your content
- Select a style profile (optional)
- Add keywords (optional)
- Choose content goals (optional)
- Set target word count
- Click "Generate"
The generated content will be inserted into the field.
Getting an API Key
- Sign up at trenddraft.xyz
- Go to Settings → API Keys
- Click "Create API Key"
- Name it "Sanity Studio"
- Select scopes:
content:generate(required)profiles:read(required)opinions:read(optional)
- Copy the key (shown only once)
Advanced Usage
Custom Input Component
For more control, you can use the input component directly:
import { createTrendDraftInput } from '@resonia/sanity-plugin-trenddraft';
const CustomTrendDraftInput = createTrendDraftInput({
apiKey: process.env.SANITY_STUDIO_TRENDDRAFT_API_KEY!,
defaultWordCount: 1200,
});Using Hooks
Build custom integrations with the provided hooks:
import { useTrendDraftApi, useStyleProfiles } from '@resonia/sanity-plugin-trenddraft';
function MyComponent() {
const { api, generateContent, isGenerating, error } = useTrendDraftApi({
apiKey: process.env.SANITY_STUDIO_TRENDDRAFT_API_KEY!,
});
const { profiles, selectedProfile, selectProfile } = useStyleProfiles({
api,
});
// ... your custom implementation
}Direct API Access
import { createApiClient } from '@resonia/sanity-plugin-trenddraft';
const api = createApiClient(process.env.SANITY_STUDIO_TRENDDRAFT_API_KEY!);
// Get profiles
const profiles = await api.getStyleProfiles();
// Generate content
const content = await api.generateContent({
title: 'My Article Title',
styleProfileId: 'profile-id',
targetWordCount: 1000,
});Supported Field Types
TrendDraft automatically enables on these field types (when field name matches):
Simple Text Fields:
stringtext
Rich Text / Portable Text Fields:
arrayofblock(e.g.,blockContent,body)- Any Portable Text field
Default Field Names:
bodycontentexcerptdescriptiontextblockContent
Customize with the fields configuration option.
Portable Text Support
For Portable Text (block content) fields, TrendDraft will:
- Convert generated text to Portable Text block format
- Support Markdown-style headings (## H2, ### H3, #### H4)
- Support blockquotes (> quote)
- Allow appending to existing content or replacing it
Example schema that works with TrendDraft:
defineField({
name: 'body',
title: 'Body',
type: 'array',
of: [
{ type: 'block' },
{ type: 'image' },
{ type: 'code' },
],
})Requirements
- Sanity Studio v3.0.0+
- React 18+
- TrendDraft account with API key
Support
License
MIT © Resonia Inc
