Integrations

Sanity

Connect your Sanity project with a Project ID and an Editor token, and publish articles as live posts.

The Sanity integration publishes your Nimblo articles into your Sanity project. Each article is saved as a live post, and your website shows it the same way it shows posts you write yourself.

Don't see Sanity in Settings > Publishing? Ask your workspace admin to connect it.

How articles look on your site

Formatting and mobile-friendliness depend on your website's theme and CSS. We deliver semantic content; your theme controls the styling. Learn more

Before you start

  • You can open your project in sanity.io/manage and create API tokens.
  • Your schema is deployed (npx sanity schemas deploy, see For your developer), or you have at least one published blog post. We read your post fields from your schema, or from your existing posts.
  • You know your dataset name. It is usually production.

How to connect

Go to Settings > Publishing, find Sanity under Connect Your Website, and click Connect. The wizard has 4 steps: connect your project, pick your post type, match your fields, and the Sanity connected screen.

Copy your Project ID

In sanity.io/manage, open your project. The Project ID is shown at the top of the page, next to a copy button. Use the Project ID, not the Organization ID shown next to it.

Create an Editor token

In the same project, go to API > Tokens > Add API token. In the wizard, Open Sanity takes you there once you have entered the Project ID.

  1. Name it anything, e.g. "Nimblo"
  2. Set permissions to Editor
  3. Click Add token and copy the token. Sanity only shows it once.

The token needs Editor access. A Viewer token can read your posts but cannot publish. We test this when you connect.

Paste your details and pick the post type

In the wizard, paste the Project ID, keep or change the Dataset, paste the API token (Editor) and click Continue. We check the token right away. If the ID you pasted looks like an Organization ID, the wizard warns you.

Then pick the Post type your site uses for blog posts. It is usually post, and we select it for you when it exists.

Match your fields

Choose which field of your posts gets each part of the article. We fill in the usual names for you, so most of the time you only confirm them.

Article partUsual Sanity fieldRequired
TitletitleYes
SlugslugYes
Article textbodyYes
Hero imagemainImageNo
Publish datepublishedAtNo
Meta descriptionexcerptNo

We build each post's link from the Blog path URL in Settings, like yoursite.com/blog/your-article.

Click Connect. You'll see the Sanity connected screen with your project, dataset and post type. If your site still needs the Nimblo block, the screen shows your developer how to add it.

Change settings or disconnect

Click the Sanity card in Settings > Publishing to open the Sanity connected screen. From there you can click Change settings or Disconnect. When you change settings for the same project, leave the token empty to keep the one you saved. Your field matching stays as you left it.

If you disconnect, articles stop being published to Sanity. Posts already in Sanity stay.

What we publish

Each article becomes a live post in Sanity, not a draft:

  • Title, slug, meta description and date go into the fields you matched.
  • Hero image and images inside the article are uploaded to your Sanity image library.
  • Article text is saved as Sanity's rich text: headings, paragraphs, lists, quotes, links, bold and italic.
  • Links to outside sources are marked nofollow and open in a new tab, once your developer renders them (see Render it on your site). Links to your own pages stay followed.

Tables, videos, CTA cards and the FAQ schema depend on the blocks your posts can hold. We check your schema, or your posts if no schema is deployed, when you connect, when you open the Sanity connected screen or click Check again there, and every time an article publishes:

Article partWith the Nimblo blockWith your own blockWithout either
CTA cardsExactly as on Nimblo-A heading, their text and links
TablesExactly as on NimbloYour table block, e.g. @sanity/tableA bulleted list, one row per bullet
YouTube videosThe video playerYour video block, e.g. youtubeA link to the video
FAQ and article schema (JSON-LD)Included, for rich results-Left out
Linked images, like your logoExactly as on Nimblo-The image, then its link as text

Here's one of our own articles, published to a test site that reads its posts from Sanity, with the Nimblo block set up:

Publishing the same article again updates its post instead of creating a copy. Fields you set yourself in Sanity, like the author or categories, are kept. If you have an open draft of that post in Sanity Studio, the draft is updated too.

For your developer

Your website reads posts from Sanity, so the article shows up wherever your site already lists blog posts. Three things make it look exactly like it does on Nimblo.

1. Add the Nimblo block

One block type holds what Sanity's rich text can't: CTA cards, tables, videos and the FAQ schema. We send them as ready-made HTML, styled inline, so they look the same on any site.

Add the type to your Studio schema and allow it in your post body:

import { defineArrayMember, defineField, defineType } from 'sanity';

export const articleHtml = defineType({
  name: 'articleHtml',
  title: 'Nimblo block',
  type: 'object',
  fields: [defineField({ name: 'html', type: 'text', readOnly: true })],
});

// In your post type's body field:
defineField({
  name: 'body',
  type: 'array',
  of: [
    defineArrayMember({ type: 'block' }),
    defineArrayMember({ type: 'image' }),
    defineArrayMember({ type: 'articleHtml' }),
  ],
});

Register articleHtml with your other schema types, then deploy your schema so we can see the block:

npx sanity schemas deploy

Already connected? Nothing else to do. We check your schema again when you open the Sanity connected screen or click Check again there, and every time an article publishes.

The Sanity connected screen also shows these steps, with copy buttons, until the block is found:

2. Render it on your site

Render the block's HTML as it is, give headings their block key as the id, so the table of contents links work, and add the nofollow and new tab we send on links to outside sources:

import { PortableText } from '@portabletext/react';

const components = {
  types: {
    articleHtml: ({ value }) => <div dangerouslySetInnerHTML={{ __html: value.html }} />,
  },
  block: {
    h2: ({ children, value }) => <h2 id={value._key}>{children}</h2>,
    h3: ({ children, value }) => <h3 id={value._key}>{children}</h3>,
  },
  marks: {
    link: ({ children, value }) => (
      <a href={value.href} rel={value.rel} target={value.blank ? '_blank' : undefined}>
        {children}
      </a>
    ),
  },
};

<PortableText value={post.body} components={components} />;
Full example: a Next.js post page

A complete post page that reads one post from Sanity and renders it. Replace your-project-id and production with your own.

// app/blog/[slug]/page.tsx
import { notFound } from 'next/navigation';

import { PortableText } from '@portabletext/react';
import { createClient } from '@sanity/client';

const sanity = createClient({
  projectId: 'your-project-id',
  dataset: 'production',
  apiVersion: '2024-01-01',
  useCdn: false,
});

const imageUrl = (ref: string) => {
  const [, id, size, format] = ref.split('-');
  return `https://cdn.sanity.io/images/your-project-id/production/${id}-${size}.${format}`;
};

const components = {
  types: {
    articleHtml: ({ value }) => <div dangerouslySetInnerHTML={{ __html: value.html }} />,
    image: ({ value }) => <img src={imageUrl(value.asset._ref)} alt={value.alt ?? ''} />,
  },
  block: {
    h2: ({ children, value }) => <h2 id={value._key}>{children}</h2>,
    h3: ({ children, value }) => <h3 id={value._key}>{children}</h3>,
  },
  marks: {
    link: ({ children, value }) => (
      <a href={value.href} rel={value.rel} target={value.blank ? '_blank' : undefined}>
        {children}
      </a>
    ),
  },
};

export default async function PostPage({ params }) {
  const { slug } = await params;
  const post = await sanity.fetch(
    `*[_type == "post" && slug.current == $slug][0]{title, mainImage, body}`,
    { slug }
  );
  if (!post) notFound();

  return (
    <article>
      <h1>{post.title}</h1>
      {post.mainImage && <img src={imageUrl(post.mainImage.asset._ref)} alt="" />}
      <PortableText value={post.body} components={components} />
    </article>
  );
}
Not using React? (Astro, Vue, Svelte, plain HTML)

Use @portabletext/to-html to turn the post body into HTML, then put that HTML in your page:

import { escapeHTML, toHTML } from '@portabletext/to-html';

const html = toHTML(post.body, {
  components: {
    types: {
      articleHtml: ({ value }) => value.html,
      image: ({ value }) =>
        `<img src="${imageUrl(value.asset._ref)}" alt="${escapeHTML(value.alt ?? '')}">`,
    },
    block: {
      h2: ({ children, value }) => `<h2 id="${value._key}">${children}</h2>`,
      h3: ({ children, value }) => `<h3 id="${value._key}">${children}</h3>`,
    },
    marks: {
      link: ({ children, value }) =>
        `<a href="${escapeHTML(value.href)}"${value.rel ? ` rel="${escapeHTML(value.rel)}"` : ''}${value.blank ? ' target="_blank"' : ''}>${children}</a>`,
    },
  },
});

Does your site build pages ahead of time or cache them? A new post shows up once your site rebuilds or its cache refreshes.

3. Images in the text

Image blocks are regular Sanity image blocks with an alt text. Render them the way your site already renders images, for example with @sanity/image-url.

Your schema is not deployed? We can only see the blocks your existing posts already use. Run npx sanity schemas deploy, then click Check again on the Sanity connected screen, so we can use every block your Studio allows.

Check that it works

New articles publish to Sanity automatically when Automatically Publish is on in Settings > Publishing. To check the connection now:

  1. Open any article from Blog content and click Publish in the article sidebar.
  2. Open your Sanity Studio and go to your posts. The article appears there.

The post's link shows in Nimblo once the page is live on your website. If your site rebuilds after new posts, this can take a few minutes, or until your sitemap updates.

Troubleshooting & FAQ

"Sanity rejected the API token for this project"

Check that you entered the Project ID, not the Organization ID, and that the token was created in that same project. Then copy the token again from API > Tokens. If you can't find it, create a new one. Sanity only shows a token once.

"The Sanity API token does not have access to this dataset"

The token cannot write to the dataset, usually because it has Viewer access. Create a new token with Editor access and connect again.

"Sanity project or dataset not found"

Check the Project ID and the Dataset name in the wizard. Both must match your project in sanity.io/manage.

"No published post found in Sanity"

We read your post fields from your deployed schema, or from your published posts when there is none. Run npx sanity schemas deploy in your Studio folder, or publish one post of that type in Sanity Studio, then try again.

A field is missing from the field list.

Without a deployed schema, we only list the fields that are filled on your newest posts. Deploy your schema, or fill that field on one of your posts and publish it. Then click Change settings to match it.

"Sanity already has a post with the slug"

Another published post in Sanity already uses the article's slug, and we never write over it. Change the slug of the article in Nimblo or of the post in Sanity, then publish again.

Can I publish articles as drafts first?

No. Articles are always saved as live posts in Sanity. If you don't want new articles to go live on their own, turn off Automatically Publish in Settings > Publishing and publish each article yourself.

Can I republish an article after editing it?

Yes. Open the article from Blog content. In the article sidebar, click Published (or Re-Publish if you changed the slug), then click Yes to confirm. We update the same Sanity post and keep fields you set in Sanity, like the author.

The article is in Sanity but not on my website.

Your website decides which Sanity posts it shows. Check that the post type you picked is the one your site lists, and that your site has rebuilt since the post was published.

Links to outside sources show as followed on my site.

We send those links with nofollow and mark them to open in a new tab, but Sanity only stores that. Your site shows it once it renders links with the link mark from Render it on your site. Then republish an article, or wait for your site to rebuild.

Need more help?

Contact Nimblo.