Issue with content publishing in Sanity + Eleventy + Netlify setup

7 replies
Last updated: Apr 12, 2021
Hello!! I am stuck with the content publishing for the "sanity + eleventy + netlify".
I followed the very basic guide from:
https://www.sanity.io/create (did not cloned or messed with any code yet).Connected my Github and Netlify
Accessed my "studio" on Netlify
Added a new "test post" and hit "Publish"
The new post never showed up
The "web" of my blog:
https://sanity-eleventy-blog-web-nusxzdbc.netlify.app/
What am I missing?

(PS.: I have already deployed again the "web" and "studio")
AI Update

I can see you're experiencing a common issue with the Sanity + Eleventy + Netlify setup where published posts aren't appearing on your site. This typically happens because there's a disconnect between when you publish content in Studio and when your Eleventy site rebuilds to fetch that new content.

The key issue is that Eleventy is a static site generator - it fetches content from Sanity at build time, not in real-time. When you publish a post in Studio, your Netlify-hosted website doesn't automatically know to rebuild and fetch the new content.

The Problem

When you hit "Publish" in your Sanity Studio, the content is saved to Sanity's Content Lake, but your Eleventy site on Netlify still shows the old static HTML from the last build. Your site needs to be rebuilt to query Sanity for the new post and generate the updated HTML.

The Solution

You need to trigger a rebuild of your Netlify site after publishing content. Here are your options:

1. Manual Deploy (Quick Test)

Go to your Netlify dashboard, find your web project (not the studio), and click "Trigger deploy" → "Deploy site". After the build completes (usually 1-2 minutes), your new post should appear. This confirms everything is working.

2. Set Up Automated Rebuilds with Webhooks

The standard, production-ready approach is to use GROQ-powered webhooks to automatically trigger Netlify rebuilds when content is published. Here's how:

  • Go to your Netlify site settings → Build & deploy → Build hooks
  • Click "Add build hook" and give it a name like "Sanity Content Update"
  • Copy the webhook URL Netlify provides
  • Go to your Sanity project at sanity.io/manage → select your project → API → Webhooks
  • Create a new webhook with the Netlify build hook URL
  • Configure it to trigger on document changes for your post type

This way, every time you publish content in Sanity, it automatically triggers a Netlify rebuild, and your new post appears within a few minutes. This is the standard pattern used in production by many Sanity sites.

3. Alternative: Sanity Functions (Experimental)

You can also use Sanity Functions, which are serverless, event-driven code modules that respond to content changes and can trigger external services like your Netlify build hook. While Functions offer more flexibility for complex workflows and run directly on Sanity's infrastructure, they are currently an experimental feature with APIs subject to change. For straightforward build triggering, webhooks are the more established and reliable option.

Troubleshooting: Why Your Post Might Still Not Show

If rebuilding doesn't fix it, check these common issues:

  • Missing publishedAt date: The default GROQ query typically filters for publishedAt < now(). Make sure your post has a publish date that's in the past, not the future.

  • Missing slug: The query also filters for defined(slug). Verify your post has a slug defined.

  • Draft vs Published: Ensure you clicked the "Publish" button (not just "Save"). The query specifically looks for published documents with _type == "post".

  • URL structure: Individual posts should be at /blog/[your-slug]/. If you're getting 404s on the individual post route, the slug might not be generating correctly.

Verify Your Content Exists

You can verify your content is actually in Sanity by using the Vision plugin in your Studio. Look for the "Vision" tab and run this query:

*[_type == "post" && defined(slug)] | order(publishedAt desc)

This will show you all posts with slugs, regardless of publish status, so you can confirm your test post exists in Sanity.

Quick Fix Right Now

  1. Go to your Netlify dashboard
  2. Find your web project (should be something like sanity-eleventy-blog-web)
  3. Click "Trigger deploy" → "Deploy site"
  4. Wait for the build to complete
  5. Check your site - your post should now appear

Once you confirm this works, set up the webhook automation so future posts appear automatically without manual intervention. Webhooks are fully supported and work reliably for production sites with static site generators like Eleventy.

Hi!I think that you need to trigger a rebuild of the website.
You need this plugin:
https://github.com/sanity-io/sanity-plugin-dashboard-widget-netlify Is is already included in the starter?
Hi
user E
,
The "deploy to Netlify" is already included in the starter.

I deploy my "web" again
https://sanity-eleventy-blog-web-nusxzdbc.netlify.app/
Everything seems to be OK according to the Netlify log (including the changes I made)


9:47:56 AM: Writing _site/README/index.html from ./README.md.

9:47:56 AM: Writing _site/index.html from ./index.njk.

9:47:56 AM: Writing _site/posts/index.html from ./archive.njk.

9:47:56 AM: Writing _site/posts/picture-perfect-cropping-with-hotspots/index.html from ./post.njk.

9:47:56 AM: Writing _site/authors/nicholas/index.html from ./author.njk.

9:47:56 AM: Writing _site/posts/my-first-introduction-to-portable-text/index.html from ./post.njk.

9:47:56 AM: Writing _site/posts/finally-i-found-a-content-management-system-i-can-use-on-my-phone/index.html from ./post.njk.

9:47:56 AM: Writing _site/posts/exploration-powered-by-structured-content/index.html from ./post.njk.

9:47:56 AM: Writing _site/posts/my-brand-new-blog-powered-by-sanity-io-eleventy/index.html from ./post.njk.

9:47:56 AM: Benchmark (Data): 
./_data/authors.js` took 371ms (27.1%)`

9:47:56 AM: Benchmark (Data): 
./_data/metadata.js` took 236ms (17.3%)`

9:47:56 AM: Benchmark (Data): 
./_data/posts.js` took 241ms (17.6%)`

9:47:56 AM: Creating deploy upload records

9:47:56 AM: Processed 9 files in 1.28 seconds (v0.9.0)

But my post still not there.
If you look in /template/web/client-config.js, does the projectId fall back on the correct project ID? I wonder if it might not be picking up the env variable and is falling back on the project ID of the template.
Hi
user A
! I checked my
/template/web/client-config.js
file and the
projectId
and it set properly "Project ID" provided by Sanity. I also redeployed both projects (studio / web) but I with no success with my new post.
user T
I set up this starter and managed to get it going by adding a category to my new post. I wish I could say that’s the answer, but since then I’ve been able to add other posts without categories and they show up too (after a deploy). 🤷‍♂️
OMG
user A
!You found it! Actually I tested and it is not related to the "category" but to the "Published at" field. It is required to fill it so Sanity do not "auto generate" it!
Tks a lot!
Ahh, that makes more sense. Awesome! Glad it’s working for you. :)

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?