NextJS2 MIN READ
25.12.2025
.md

Adding an RSS Feed to My Next.js Blog

Last updated: 08.02.2026

🎧

Adding an RSS Feed to My Next.js Blog

Audio Narration

RSS feed illustartion

I just added a fully-featured RSS feed to my blog, making it easy for readers to subscribe and stay updated on new posts. The implementation leverages Next.js App Router and Sanity's content API to generate a standards-compliant RSS 2.0 feed with extended features.

What's in the Feed

The RSS feed includes everything you'd expect from a modern feed:

  • Full post metadata including title, description, and publication dates
  • Author attribution using Dublin Core namespace
  • Category tags for easy filtering
  • Image enclosures for featured images
  • Audio enclosures for TTS narration
  • Auto-generated summaries in the description field

Technical Implementation

The feed is generated server-side using a Next.js API route at /posts/rss.xml. It queries all published posts from Sanity using the existing allPostsQuery, ensuring consistency with what's displayed on the site.

Key implementation details:

  • Proper XML escaping to prevent injection attacks
  • Aggressive caching (1 hour with stale-while-revalidate) to minimize server load
  • RSS 2.0 compliance with extended namespaces (Dublin Core, Atom, Content Module)
  • Auto-discovery via HTML metadata in the site layout
  • Graceful error handling with fallback empty feed

Why RSS Still Matters

Despite the rise of social media and email newsletters, RSS remains relevant for several reasons:

  • Reader control: Subscribers choose when and how to consume content
  • Privacy: No tracking or data collection
  • Platform independence: Works with any RSS reader
  • No algorithmic filtering: Every post reaches every subscriber

The Result

Readers can now subscribe to the blog using any RSS reader (Feedly, Inoreader, NetNewsWire, etc.) by visiting https://andreskristensen.blog/posts/rss.xml. The feed automatically updates whenever new posts are published, and includes both text content and audio narration for each article.

This addition makes the blog more accessible and gives readers another way to stay connected—one that respects their time and privacy.

Continue Reading
varlock
NextJSSecurity5 MIN

Securing My Blog's Secrets with Varlock and Doppler

The author describes the security risks of traditional .env files in Next.js projects: secrets stored in plain text on local machines, duplicated across environments, and easily exposed through accidental commits or misconfigured deployments. Varlock is introduced as a structured, schema-based replacement for dotenv, using a committed .env.schema file that defines variable types, requirements, and sensitivity without storing actual secrets. It integrates with Next.js as a drop-in replacement for @next/env, providing TypeScript types, startup validation, sensitivity-aware client bundling, and log redaction. Doppler is chosen as the secrets provider for its generous free tier, clean dashboard, environment configs, and especially its native Vercel sync, which keeps secrets updated without tokens or runtime API calls. Locally, Varlock’s exec() calls the Doppler CLI to fetch secrets in memory; in production, Vercel’s environment variables are used directly, with the same schema validating both paths. Benefits include zero secrets on disk, early configuration error detection, automatic sensitivity handling, and an AI-friendly schema. The author would skip Varlock’s Doppler plugin next time and rely solely on the CLI-based exec() approach despite a small startup performance cost.

Read post
ai agent
AINextJSSanity2 MIN

Serving Your Blog as Markdown So AI Agents Can Actually Read It

The article explains how to serve clean Markdown versions of blog posts so AI agents can consume content without HTML noise like navigation, scripts, and cookie banners. It recommends two access patterns: appending .md to post URLs, or using an Accept: text/markdown header for content negotiation. In Next.js, rewrites in next.config.ts route both patterns to an internal /md/posts/[slug] handler. That route fetches the post from Sanity, converts it to Markdown, and returns it with a text/markdown Content-Type and short caching headers. A buildPostMarkdown helper constructs the Markdown document with a title, canonical URL, optional hero image, auto-generated summary, and body converted from Portable Text via @portabletext/markdown. Code blocks stored in Sanity as _type: "code" are correctly rendered as fenced Markdown code blocks with language tags, making them ideal for AI agents and syntax highlighters. A /posts.md index provides a machine-readable sitemap listing all posts with metadata and links, enabling agents to discover and traverse content efficiently using either the .md suffix or Accept header approach.

Read post