Installation

Install and set up @onruntime/next-sitemap

2 min read
262 words

Installation

Install the package using your preferred package manager:

# npm
npm install @onruntime/next-sitemap

# yarn
yarn add @onruntime/next-sitemap

# pnpm
pnpm add @onruntime/next-sitemap

Basic Setup

App Router (Next.js 13+)

Create a sitemap.ts file in your app directory:

// app/sitemap.ts
import { generateSitemap } from "@onruntime/next-sitemap/app";

export default async function sitemap() {
  return generateSitemap({
    baseUrl: "https://your-domain.com",
  });
}

robots.txt

Create a robots.ts file for robots.txt generation:

// app/robots.ts
import { generateRobots } from "@onruntime/next-sitemap/app";

export default function robots() {
  return generateRobots({
    baseUrl: "https://your-domain.com",
  });
}

Project Structure

After setup, your project should look like this:

sitemap.ts
robots.ts
page.tsx

Verify Installation

Start your development server and visit:

  • http://localhost:3000/sitemap.xml - Your sitemap
  • http://localhost:3000/robots.txt - Your robots.txt

You should see generated XML for your sitemap and text content for robots.txt.

Development vs Production

The sitemap will include all routes discovered at build time. In development, it reflects your current route structure.

Environment Variables

For production, set your base URL:

# .env.production
NEXT_PUBLIC_SITE_URL=https://your-domain.com

Then use it in your configuration:

// app/sitemap.ts
import { generateSitemap } from "@onruntime/next-sitemap/app";

export default async function sitemap() {
  return generateSitemap({
    baseUrl: process.env.NEXT_PUBLIC_SITE_URL || "https://your-domain.com",
  });
}

Next Steps