Live D1 Posts with R2 Images

Live D1 Posts with R2 Images

How AstroWEBTheme demonstrates a live Cloudflare D1 post whose hero image is resolved from Cloudflare R2 media metadata.

AstroWEBTheme includes a hybrid content path for client sites that want both repository-owned markdown and live CMS entries.

The live demo post uses three D1 tables:

  • content_entries stores the published post.
  • media_assets stores the R2 object key, public URL behavior, alt text, title, and caption.
  • content_media_relations connects the post to the media asset.

How It Renders

When a blog detail page is requested, the resolver checks D1 first in hybrid mode. If the slug exists and the entry is published, the page renders the D1 body HTML. The project hook then resolves hero_image_id through media_assets and builds the public R2 URL from the media config.

The post header also shows source rows so clients can see that the article is live from D1 and the image is attached through R2 metadata.

Demo Slug

The seeded demo slug is:

/blog/agentic-websites-with-astrowebtheme/

Why This Pattern Helps Clients

Static content is excellent for speed and version control. Live content is better for editors, approvals, dashboards, and frequent updates. AstroWEBTheme lets a client start static and move selected collections to D1 without replacing the whole site architecture.

Security Note

The content body from D1 is sanitized before rendering. Production deployments should combine that with response-header CSP, same-origin admin routes, authenticated dashboard access, and reviewed media permissions.