Skip to content

Astro Sitemap and RSS — SEO Feeds Generation

DodaTech Updated 2026-06-28 3 min read

In this tutorial, you will learn about Astro Sitemap and RSS. We cover key concepts, practical examples, and best practices to help you master this topic.

Learn Astro sitemap and RSS generation: configure sitemap.xml, create RSS feeds for blogs, and optimize for search engine discovery of your content.

In this lesson, you'll install the sitemap integration, generate RSS feeds from content collections, and configure both for optimal SEO.

What You'll Learn

How to generate sitemap.xml with the sitemap integration, create RSS feeds with @astrojs/rss, filter pages, and customize feed metadata.

Why It Matters

Sitemaps help search engines discover all your pages. RSS feeds let users subscribe to your content. Both are essential for content-driven sites.

Real-World Use

DodaTech's tutorial site generates a sitemap with 15,000+ URLs and an RSS feed for new tutorial notifications.

flowchart LR
    A[Site Pages] --> B[Sitemap Integration]
    A --> C[RSS Generation]
    B --> D[sitemap.xml]
    C --> E[feed.xml]
    D --> F[Search Engine Discovery]
    style B fill:#ff5a03,color:#fff

Sitemap Integration

Install and configure:

npx astro add sitemap
import { defineConfig } from "astro/config";
import sitemap from "@astrojs/sitemap";

export default defineConfig({
  site: "https://example.com",
  integrations: [
    sitemap({
      filter: (page) => !page.includes("/admin/"),
      changefreq: "weekly",
      priority: 0.7,
      lastmod: new Date(),
    }),
  ],
});

Output: A sitemap.xml is generated at build time with all public page URLs listed with their change frequency and priority.

RSS Feed

Install @astrojs/rss:

npm install @astrojs/rss

Create an RSS endpoint:

---
// src/pages/feed.xml.ts
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";

export async function GET() {
  const posts = await getCollection("blog");
  return rss({
    title: "DodaTech Blog",
    description: "Latest tutorials and articles",
    site: "https://dodatech.com",
    items: posts.map(post => ({
      title: post.data.title,
      pubDate: post.data.date,
      description: post.data.description,
      link: `/blog/${post.slug}/`,
    })),
  });
}

Output: A /feed.xml RSS feed listing all blog posts with titles, dates, descriptions, and links.

Customizing RSS

Add custom data and styling:

import rss from "@astrojs/rss";
import { getCollection } from "astro:content";

export async function GET(context) {
  const posts = await getCollection("blog");
  return rss({
    title: "DodaTech Blog",
    description: "Latest tutorials and articles",
    site: context.site,
    items: posts.map(post => ({
      title: post.data.title,
      pubDate: post.data.date,
      description: post.data.description,
      link: `/blog/${post.slug}/`,
      categories: post.data.tags,
      author: "DodaTech",
    })),
    customData: "<language>en-us</language>",
    stylesheet: "/rss-style.xsl",
  });
}

Filtering Sitemap Pages

Exclude specific routes:

sitemap({
  filter: (page) => {
    const exclude = ["/admin", "/draft", "/404"];
    return !exclude.some(path => page.includes(path));
  },
});

Common Mistakes

  1. Forgetting site in Astro config: Sitemap and RSS need the site URL. Without it, generated URLs are incorrect.
  2. Not filtering out draft pages: Include drafts in your sitemap if you don't want them indexed. Filter draft: true pages.
  3. Missing pubDate in RSS items: RSS feeds require a publication date for each item. Without it, feed readers may reject the feed.
  4. Using .xml files in src/pages/: Sitemap and RSS endpoints should be .ts files that return XML, not static .xml files.
  5. Not validating the sitemap: After generation, validate your sitemap.xml using Google Search Console or an online validator.

Practice Questions

  1. What does the sitemap integration generate? Answer: A sitemap.xml file listing all public page URLs with metadata for search engines.

  2. How do you create an RSS feed in Astro? Answer: Create a .ts file in src/pages/ that imports @astrojs/rss and returns the RSS XML.

  3. Why filter pages in the sitemap config? Answer: To exclude admin pages, draft content, or other pages that shouldn't appear in search results.

  4. What is the purpose of changefreq and priority in sitemaps? Answer: They hint to search engines how often content changes and which pages are most important for crawling.

Challenge

Build a blog with both a sitemap and RSS feed. The sitemap should exclude draft posts and admin pages. The RSS feed should include categories and author information.

Mini Project

Create a content site with three content collections (blog, docs, tutorials). Generate a combined sitemap that includes all three collections and separate RSS feeds for each collection.

FAQ

Does the sitemap support images and video?

: Yes. The sitemap integration supports image and video sitemap extensions for media-rich content.

Can I generate multiple sitemaps?

: Yes. For large sites, use sitemap index files. Configure sitemap() with custom options for multi-sitemap output.

Do RSS feeds work with static output?

: Yes. Both sitemaps and RSS feeds are generated as static XML files during the build.

How often should I update my sitemap?

: Every time you deploy. The build Process generates a fresh sitemap automatically.

What's Next

Learn about Astro View Transitions for smooth page animations and navigation transitions.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro