Generating social posts from your existing content
Building on the previous lesson's concepts around field grouping, this section introduces a new group called social
.
This is going to be where you use Sanity AI Assist to generate content based on the existing content in your portable text fields.
The reason for doing this is to speed up the whole ideation of social posts. This, in turn, boosts your SEO as a result of sharing your content across a wider audience on different social platforms.
For this example, you will need to add two fields to handle cross-posting to LinkedIn and X.
import { defineField } from "sanity";
export const socialType = defineType({
fields: [
defineField({
name: "socialLinkedIn",
type: "text",
rows: 4,
}),
defineField({
name: "socialX",
type: "text",
rows: 4,
}),
],
});
Once you've got these fields added, you will need to look at adding Sanity Assistant to your project.
npm install @sanity/assistant
import { assist } from "@sanity/assist";
export default defineConfig({
/* other config */
plugins: [
/* other plugins */
assist(),
],
});
Once that's been done 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 and you should see a sparkly new button.
Press this button and you will be able to create a new prompt. You may see something like manage instructions
. Press once again and add a new item.
You're going to create a new prompt, but luckily the hard work has already been done for you. See the prompt below. Wherever you see [Title Field]
, [Description Field]
and [Text Field]
you can replace these with references to the fields in your document.
Take the context from [Title Field] and [Description Field] and [Text Field] and generate out all share content, focusing on the type of audience for each.
Before running the prompt, you may want to reduce the number of fields to only include the fields you've added in this lesson. E.g make sure socialLinkedIn
and socialX
are the only fields checked from the allowed fields
pane.
Here's an example of a prompt used for sharing on LinkedIn, X and a specific version for YouTube that takes advantage of the context field (opens in a new tab) to provide extra information for Sanity AI Assist.
In the next chapter, you will learn how to create a dynamic sitemap that automatically updates when content changes in Sanity, helping search engines discover and index your content more effectively.