To schedule posts in Astro on Cloudflare, hide posts dated after the build and rebuild when a postโs date arrives. The rebuild comes from a deploy hook (a URL that starts a build) called by a small Worker on a Cron Trigger. For hourly checks, have the build write the next publish time to a JSON file so the Worker only starts a build when a post is due.
It works with Workers Builds, Cloudflare Pages or wrangler deploy from GitHub Actions. If your site is not on Cloudflare yet, start with deploying Astro to Cloudflare Workers. We tested it on October 22, 2026 with Astro 7.4.2 and Wrangler 4.151.3, with a stand-in deploy hook.
Why donโt future-dated Astro posts appear on their own?
A static site is a folder of HTML files generated at build time. If a blog post is dated next Tuesday and your filter hides future posts, the build skips it: no page, no listing entry, no RSS item. Nothing runs on Tuesday to change that. The post appears only when something builds the entire website again after its publication date.
Astro also has no scheduling feature, so it does not hide future posts for you. A Markdown file dated next year shows up immediately unless your code filters it out. So scheduling in Astro is always the same two parts:
- A date filter that every route uses.
- A scheduled rebuild that runs after the publish time.
Most guides for this problem use a Netlify build hook or a Vercel deploy hook called from a GitHub Action. Cloudflare has its own pieces for both halves, and they cost nothing on the free plan for a normal blog. If you are moving from a Vercel deployment, the process is similar: the hook URL and the scheduler change, the date filter does not.
Which scheduling method should you use?
Choose by how you deploy and how precise the publish time needs to be. This comparison covers the options we found in other guides plus the Cloudflare-specific ones. Limits below are from Cloudflareโs Workers Builds limits, Workers limits and Pages limits pages and GitHubโs schedule event docs, checked October 22 and again November 1, 2026.
| Method | You need | Builds it uses | Timing | Best for |
|---|---|---|---|---|
| Cron Worker calls the hook daily | Workers Builds or Pages Git | One per day | Once a day | A blog that publishes by date only |
| Cron Worker checks a JSON file, calls when due | Workers Builds or Pages Git | One per scheduled post | Within the check interval | Most blogs: precise and cheap |
| GitHub Actions calls the hook | Deploy hook, GitHub repo | One per run | Can be delayed at busy times | Teams that keep all automation in GitHub |
GitHub Actions builds and runs wrangler | API token, no Git integration | Runs in GitHub, not Cloudflare | Can be delayed at busy times | Sites deployed with wrangler deploy |
| On-demand rendering for blog routes | @astrojs/cloudflare adapter | None | Exact, at request time | Sites already rendering on demand |
Third-party automation or draft flips | Another service or a bot commit | One per run | Depends on the service | Rarely worth the extra moving part |
Our recommendation for a static blog on Workers Builds is the second row. Steps 1 to 5 below build it, and the GitHub Actions versions come after.
Step 1: Hide posts dated after the build
Put the publish rule in one helper function so every route uses the same one. This example assumes a blog content collection with date and draft fields in each postโs frontmatter. If your schema calls the field pubDate, as the Astro blog starter does, use that name instead:
// src/content.config.ts
import { defineCollection } from "astro:content";
import { glob } from "astro/loaders";
import { z } from "astro/zod";
const blog = defineCollection({
loader: glob({ pattern: "**/*.md", base: "./src/content/blog" }),
schema: z.object({
title: z.string(),
date: z.coerce.date(),
draft: z.boolean().default(false),
}),
});
export const collections = { blog };
// src/lib/posts.ts
import { getCollection } from "astro:content";
export const BUILD_TIME = new Date(__BUILD_TIME__);
export const isLive = (data: { date: Date; draft: boolean }) =>
!data.draft && data.date <= BUILD_TIME;
export async function getLivePosts() {
const posts = await getCollection("blog", ({ data }) =>
import.meta.env.DEV ? true : isLive(data),
);
return posts.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
}
import.meta.env.DEV keeps every post visible in astro dev, so you can still preview a scheduled post while writing it. Production builds apply the filter. The helper exports BUILD_TIME because the endpoint in Step 5 needs the same value.
The two fields work together like this. A post with draft: false and a future date is scheduled, not a draft:
draft | date | Result |
|---|---|---|
true | any | Never published |
false | past or now | Published in the next build |
false | future | Published in the first build after it |
Use the helper on every route
The most common scheduling bug is a filter on the blog index but not on the post pages, tag pages or feed. Then a scheduled post exists at its URL, or a product announcement shows up in RSS readers a week early. Use getLivePosts() everywhere under src/pages that reads the collection, including any component that renders a list of recent posts:
---
// src/pages/blog/[id].astro
import { render } from "astro:content";
import { getLivePosts } from "../../lib/posts";
export async function getStaticPaths() {
const posts = await getLivePosts();
return posts.map((post) => ({ params: { id: post.id }, props: { post } }));
}
const { post } = Astro.props;
const { Content } = await render(post);
---
<h1>{post.data.title}</h1>
<Content />
// src/pages/rss.xml.ts
import rss from "@astrojs/rss";
import type { APIContext } from "astro";
import { getLivePosts } from "../lib/posts";
export async function GET(context: APIContext) {
const posts = await getLivePosts();
return rss({
title: "Blog",
description: "Posts",
site: context.site!,
items: posts.map((p) => ({
title: p.data.title,
pubDate: p.data.date,
link: `/blog/${p.id}/`,
})),
});
}
Do the same in tag, category and pagination routes. @astrojs/sitemap needs no change: it lists the pages Astro built. In our test (@astrojs/rss 4.0.19, @astrojs/sitemap 3.7.4), a post dated in the future was missing from sitemap-0.xml until a build after its date included it.
Freeze one build time
Define the build time once in astro.config.mjs instead of calling new Date() in each file:
// astro.config.mjs
import { defineConfig } from "astro/config";
export default defineConfig({
site: "https://example.com",
vite: {
define: {
__BUILD_TIME__: JSON.stringify(
new Date(process.env.PUBLISH_AS_OF || Date.now()).toISOString(),
),
},
},
});
Add declare const __BUILD_TIME__: string; to src/env.d.ts so TypeScript knows about it.
If some routes render on demand (dynamic) and others are prerendered, new Date() means โbuild timeโ in one place and โrequest timeโ in another, and a post can be listed but return a 404 error, or the reverse. getastrothemes.com mixes both, and this constant is how we make sure they agree.
PUBLISH_AS_OF is a bonus. It lets you build the site as it will look on a future day:
PUBLISH_AS_OF=2026-11-03T00:00:00Z npx astro build
Run it before a scheduled day to check that the post renders, the listing order is right and its internal links resolve.
Step 2: Set the publish time and timezone
The time zone rule is simple once you have seen it: a date with no time means midnight UTC. These are the results from our test build with three posts. The column on the right is the build time at which each post first appeared, so you can see exactly what to expect:
Frontmatter date | Parsed as (UTC) | Missing from build at | Present in build at |
|---|---|---|---|
2026-11-03 | 2026-11-03T00:00:00Z | 2026-10-22 (today) | 2026-11-03T00:00Z |
2026-11-04T09:00:00-05:00 | 2026-11-04T14:00:00Z | 2026-11-04T13:59Z | 2026-11-04T14:00Z |
2026-10-02 with draft: true | 2026-10-02T00:00:00Z | every build | never |
Two consequences:
- Date-only posts go live the evening before in the Americas. Midnight UTC is 7 or 8 p.m. the previous day in New York, depending on daylight saving time. If that matters, add a time.
- Write the UTC offset for the date you publish, not today. New York is
-05:00in winter and-04:00in summer. YAML reads the offset you write; it does not know about daylight saving time.
The value must be an unquoted timestamp or a string Zod can parse; z.coerce.date() handles both, and the format 2026-11-04T09:00:00-05:00 is the safest to type.
Step 3: Create a Cloudflare deploy hook
A deploy hook is a webhook: a URL that starts a build of one branch when it receives an HTTP POST. It is available once your Worker is connected to a GitHub repository (or another Git provider) through Workers Builds, the same setup that builds the site on every push.
- In the Cloudflare dashboard, go to Workers & Pages and select your Worker.
- Open Settings > Builds > Deploy Hooks.
- Name the hook (for example,
scheduled-posts), pick your production branch, and select Create. - Copy the URL. It looks like
https://api.cloudflare.com/client/v4/workers/builds/deploy_hooks/<DEPLOY_HOOK_ID>.
What the Deploy Hooks docs say, as of November 1, 2026:
- No auth header. The ID in the URL is the credential, so treat the URL as a secret. There is no regenerate button: if it leaks, delete the hook and create a new one.
- Duplicates are dropped. If the hook fires again while the previous build is still queued or initializing, Cloudflare returns the existing
build_uuidwithalready_exists: trueinstead of starting another build. - Rate limits. 10 builds per minute per Worker and 100 per minute per account.
- Free build minutes. Workers Free includes 3,000 build minutes a month with one build at a time. Paid includes 6,000, then $0.005 per minute.
Deploy hooks for Workers Builds arrived on April 1, 2026. Older tutorials that say Workers has no build hooks are out of date.
On Cloudflare Pages, open the Pages project, go to Settings > Builds, and select Add deploy hook (Pages docs). Copy the URL the dashboard shows. Pages projects have no Cron Triggers of their own, so the Worker in the next step is how you call it. The free Pages plan allows 500 builds a month.
Step 4: Add a Cron Worker that calls the hook
The simplest version rebuilds once a day. Create a separate Worker; it does not need to live in your siteโs repository:
// my-blog-publisher/index.js
export default {
async scheduled(controller, env) {
const res = await fetch(env.DEPLOY_HOOK_URL, { method: "POST" });
if (!res.ok) throw new Error(`Deploy hook failed: HTTP ${res.status}`);
},
};
// my-blog-publisher/wrangler.jsonc
{
"name": "my-blog-publisher",
"main": "index.js",
"compatibility_date": "2026-10-01",
"triggers": { "crons": ["5 0 * * *"] },
"observability": { "enabled": true },
}
Store the hook URL as a secret and deploy:
npx wrangler secret put DEPLOY_HOOK_URL
npx wrangler deploy
Things to know about Cron Triggers:
- They run on UTC.
5 0 * * *is 00:05 UTC, just after date-only posts become due. - Changes can take up to 15 minutes to apply after a deploy.
- Weekdays count from 1 = Sunday. If you schedule by weekday, use names like
MONto avoid off-by-one mistakes. - The free plan has 5 Cron Triggers per account, 250 on Paid. This Worker uses one.
A daily rebuild is fine if you only publish by date. If you set specific publish hours, you would need an hourly cron, and calling the hook every hour starts 720 builds a month whether or not anything is due. At two minutes per build, that is 1,440 of your 3,000 free minutes, and most of those deployments change nothing. Step 5 skips those empty builds.
Step 5: Build only when a post is due
The fix is to let the build tell the Worker when the next post is due. Add a static endpoint that exports a GET function and writes the earliest future publish time in JSON format:
// src/pages/publish-schedule.json.ts
import { getCollection } from "astro:content";
import { BUILD_TIME } from "../lib/posts";
// Tells the rebuild Worker when the next scheduled post is due.
// Only a timestamp is exposed, never titles or slugs.
export async function GET() {
const upcoming = (await getCollection("blog", ({ data }) => !data.draft))
.map((post) => post.data.date)
.filter((date) => date > BUILD_TIME)
.sort((a, b) => a.getTime() - b.getTime());
return Response.json({
builtAt: BUILD_TIME.toISOString(),
nextPublishAt: upcoming[0]?.toISOString() ?? null,
});
}
A static build writes this to dist/publish-schedule.json. Our test build on October 22 produced:
{
"builtAt": "2026-10-21T18:19:32.480Z",
"nextPublishAt": "2026-11-03T00:00:00.000Z"
}
Now the Worker reads that file first and calls the hook only when nextPublishAt has passed:
// my-blog-publisher/index.js
export default {
async scheduled(controller, env) {
// 1. Ask the live site when the next scheduled post is due.
const res = await fetch(
`${env.SITE_URL}/publish-schedule.json?t=${Date.now()}`,
);
if (!res.ok) throw new Error(`Schedule check failed: HTTP ${res.status}`);
const { nextPublishAt } = await res.json();
// 2. Nothing due yet: stop without spending a build.
if (
!nextPublishAt ||
Date.parse(nextPublishAt) > controller.scheduledTime
) {
console.log(
`Nothing due. Next post: ${nextPublishAt ?? "none scheduled"}`,
);
return;
}
// 3. A post is due: start a build.
const hook = await fetch(env.DEPLOY_HOOK_URL, { method: "POST" });
if (!hook.ok) throw new Error(`Deploy hook failed: HTTP ${hook.status}`);
const { result } = await hook.json();
console.log(
`Build started for post due ${nextPublishAt}: ${result.build_uuid}`,
);
},
};
// my-blog-publisher/wrangler.jsonc
{
"name": "my-blog-publisher",
"main": "index.js",
"compatibility_date": "2026-10-01",
"triggers": { "crons": ["5 * * * *"] },
"vars": { "SITE_URL": "https://example.com" },
"observability": { "enabled": true },
}
Why this design holds up:
- It fixes itself. After a build finishes successfully, the post is no longer in the future, so
nextPublishAtmoves to the next post (ornull) and the Worker goes quiet. If a build fails, the live file still shows the old time, so the next hourly check will try again. You never have to update anything manually. - It costs one build per scheduled post. The hourly checks are small Worker invocations, not builds.
- It is as precise as your cron. With
5 * * * *, a post due at 14:00 UTC goes live after the 14:05 check plus build time. Use*/15 * * * *for quarter-hour precision. - Nothing private leaks. The file only holds a timestamp. Anyone can see that something is scheduled, but not what.
The ?t= query string skips any cache in front of the file, so the Worker always reads what the last build wrote.
Test it before a real post goes out
Donโt wait for publish day to find out the cron never fired. Test both halves locally.
The site. Build with a simulated date and look at the output:
PUBLISH_AS_OF=2026-11-03T00:00:00Z npx astro build
cat dist/publish-schedule.json
The Worker. Start Wrangler with scheduled-event testing, then call the scheduled route. The time parameter overrides controller.scheduledTime, so you can pretend it is publish day:
npx wrangler dev --test-scheduled
curl "http://localhost:8787/cdn-cgi/local/scheduled?cron=5+*+*+*+*&format=json"
curl "http://localhost:8787/cdn-cgi/local/scheduled?cron=5+*+*+*+*&time=1793664300000&format=json"
1793664300000 is 2026-11-03T00:05Z in milliseconds. For local runs, put DEPLOY_HOOK_URL in a .dev.vars file that points at a test endpoint, not your real hook.
If one wrangler dev session runs several Workers, Cloudflareโs Cron Triggers docs also list a Local Explorer endpoint (checked November 1, 2026). Send a POST to /cdn-cgi/local/explorer/api/local/scheduled?worker=<WORKER_NAME> with a JSON body that has a non-empty cron field, and a GET to /cdn-cgi/local/explorer/api/local/workers lists the exact Worker names. We did not use it in our test.
Our run against a local copy of the test site and a stand-in hook gave the expected results, with no unexpected hook calls:
| Simulated time | nextPublishAt on the site | Worker log | Hook called |
|---|---|---|---|
| 2026-10-22 (today) | 2026-11-03T00:00Z | Nothing due. Next post: 2026-11-03... | No |
| 2026-11-03T00:05Z | 2026-11-03T00:00Z | Build started for post due 2026-11-03... | Yes, once |
| 2026-11-03T01:05Z, after rebuild | 2026-11-04T14:00Z | Nothing due. Next post: 2026-11-04... | No |
| Site unreachable | n/a | outcome: "exception" | No |
The last row matters: a failed check throws, so the run is recorded as an exception instead of passing silently.
After deploying, open the Worker in the dashboard and go to Settings > Trigger Events > View events. Cloudflare keeps the 100 most recent cron runs there; Workers Logs keeps more, and the console.log text from the Worker shows up there. Builds triggered by the hook show a โdeploy hookโ label in the site Workerโs build history, which makes it easy to tell them apart from builds started by a push.
Deploying with wrangler instead of Workers Builds
Deploy hooks start a Workers Builds build, so they need the Git integration. If you deploy with npx wrangler deploy from your laptop or CI, the scheduled job has to build and deploy itself.
That is how getastrothemes.com works. A GitHub Actions workflow (one job with runs-on: ubuntu-latest) runs at 03:00 UTC (09:00 in Dhaka, where our team works), checks whether any post is dated today, and only then installs dependencies, builds and runs wrangler deploy. A trimmed version:
# .github/workflows/scheduled-publish.yml
name: Scheduled publish
on:
schedule:
- cron: "0 3 * * *"
workflow_dispatch:
concurrency:
group: production-deploy
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: main
- name: Check for a post dated today
id: due
run: |
today="$(date -u +%F)"
if grep -l "^date: ${today}" src/content/blog/*.md; then
echo "deploy=true" >> "$GITHUB_OUTPUT"
fi
- uses: actions/setup-node@v7
if: steps.due.outputs.deploy == 'true'
with:
node-version: 22
- name: Build and deploy
if: steps.due.outputs.deploy == 'true'
run: npm ci && npx astro build && npx wrangler deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Three details in it are worth copying:
ref: mainalways deploys the tip ofmain. Re-running an old workflow run would otherwise check out that runโs commit and roll production back.concurrencystops a scheduled deploy and a manual deploy from overlapping.- The date check keeps the workflow from deploying on days with nothing to publish. It also means anything merged to
mainships with the next scheduled post, so keepmainreleasable.
If your site does use Workers Builds and you prefer to keep scheduling in GitHub, replace the build steps with one curl -fsS -X POST "$DEPLOY_HOOK_URL" line and store the hook URL as a repository secret. workflow_dispatch adds a Run workflow button, which is the easiest way to try it.
Know GitHubโs limits before you rely on it for a client site. Per GitHubโs docs, checked November 1, 2026: scheduled runs can be delayed at busy times and some queued jobs may be dropped, the shortest interval is five minutes, schedules run only on the default branch, and public repositories lose their schedules after 60 days with no activity. GitHub now accepts an IANA timezone key next to cron (for example, timezone: "America/New_York"), so our schedule could be written as cron: "0 9 * * *" with timezone: "Asia/Dhaka". Our workflow still uses UTC. Cloudflare Cron Triggers do not depend on repository activity, which is why we suggest them for client sites nobody commits to every week.
Common problems and fixes
| Symptom | Cause and fix |
|---|---|
| Scheduled post is reachable by URL before its date | The filter is on the index but not in getStaticPaths. Use one helper in every route. |
| Post shows in RSS readers early | rss.xml reads the collection without the filter. Use the same helper. |
| Post went live the evening before | Date-only values are midnight UTC. Add a time and offset. |
| Post appeared an hour off after a clock change | The offset in frontmatter was for the wrong season. Write the offset for the publish date. |
| Post listed but its page returns 404 | Prerendered and on-demand routes compared against different clocks. Use one frozen __BUILD_TIME__. |
| Cron never ran after deploying | Trigger changes can take up to 15 minutes. Check Trigger Events, and confirm the cron is in UTC. |
| Worker logs โNothing dueโ on publish day | The live publish-schedule.json is from an old build, or the post is still draft: true. |
wrangler dev says the compatibility date โis in the futureโ | Wrangler compares against the current UTC date. We hit this when our local date was a day ahead of UTC. Use an earlier date. |
Node.js v22.22.1 is not supported by Astro! | Astro 7.4.2 to 7.4.4 require Node 22.23.4 or newer (checked November 1, 2026). Upgrade Node locally and in CI. |
| GitHub schedule stopped running | Public repository with 60 days of no activity. Re-enable it or move the schedule to a Cloudflare Cron Trigger. |
Checklist
-
getLivePosts()(or your equivalent) used in the index, post pages, tags, pagination and RSS -
__BUILD_TIME__defined once inastro.config.mjs - Publish times written with a time and UTC offset where the hour matters
- Deploy hook created and stored as a secret, never committed
- Cron Worker deployed, schedule written in UTC
-
publish-schedule.jsonbuilt and readable on the live site - Tested with
PUBLISH_AS_OFandwrangler dev --test-scheduled - Trigger Events checked after the first real run
Where to go from here
Scheduling adds a few small files to a static Astro blog: a helper that filters by publication date, an endpoint that says when the next post is due, and a Worker that knows when to rebuild. Once that system is in place, publishing means setting a date and pushing the Markdown file.
If your site is not on Cloudflare yet, our Astro on Cloudflare Workers guide covers the wrangler config, Workers Builds and environment variables. If you are still choosing a starting point, see our Astro blog themes roundup, the premium Astro themes and free Astro themes, and the steps to install and customize an Astro theme. If your theme names its blog collection or date field differently, change those two names in the helper and the endpoint; the rest stays the same.