Generate social posts from your content
Summarizing existing content and making it more useful in different forms is one of the best features of AI tooling. Sanity AI Assist makes it possible for authors to automatically generate new content, using existing fields along with prompts that they can save and share.
In this lesson you'll use Sanity AI Assist to generate text to post on social networks while sharing a link to the content.
First you'll need new fields to write content to. Just like you made a new custom object schema type for SEO fields, create another for social networks.
In the example below we've chosen only LinkedIn and X (formerly known as Twitter) for now, feel free to include any of the countless others.
social
object schema typeimport { defineField, defineType } from "sanity";
export const socialType = defineType({ name: "social", title: "Social", type: "object", fields: [ defineField({ name: "linkedIn", title: "LinkedIn", type: "text", rows: 3, }), defineField({ name: "x", description: "Formerly known as Twitter", type: "text", rows: 2, }), ],});
Don't forget to register this type to your Sanity Studio schema types
// ...all other importsimport { socialType } from "./socialType";
export const schema: { types: SchemaTypeDefinition[] } = { types: [ // ...all other types socialType, ],};
page
and post
schema types to include the social
field.export const pageType = defineType({ // ...all other settings fields: [ // ...all other fields defineField({ name: "social", type: "social", }), ],});
To automatically generate content for these fields, you'll now install and configure the Sanity AI assistant.
npm install @sanity/assist
assist
plugin// ...all other importsimport { assist } from "@sanity/assist";
export default defineConfig({ // ...all other config plugins: [ // ...all other plugins assist(), ],});
With this installed you can create a prompt to help Sanity AI Assist generate content from your existing fields.
Sanity AI Assist works at both field level and document level, however, for this example, you will be using the document level. Look at the top right of the Studio with any document open and you should see a sparkly new icon.
The first time you click this button you may be asked to Enable AI Assist
You can see there are currently no instructions.
What we want AI Assist to do is to summarize the main body of the document
You're going to create a new prompt, use the example below for guidance.
Where you see the boxes like [Title]
, replace these with references to the fields in your document.
Make sure the Allowed fields is set to only write to the Social field object.
Take the content from [title] and [body] to generate text that will encourage people to click the link and find out more when this content is shared on social networks.
By default, AI-generated copy can be generic. Consider adding some AI context documents (now visible in your Studio structure) to inform your preferred writing style and tone of voice. You can then add this context to your instruction, so that copy generated in future will be consistently informed.
In the following lesson, you'll create a dynamic sitemap that automatically updates when content changes. Helping search engines discover and index your content more effectively.