SDK Sitemap
Add your EarlySEO blog articles to your sitemap for better SEO indexing. Guides for Next.js, Django, and Flask.
Adding blog article URLs to your sitemap helps search engines discover and index your content. The EarlySEO SDK provides built-in sitemap helpers for every supported framework.
Next.js
Automatic setup (CLI)
If you ran npx @earlyseo/blog init, a sitemap file was already created at app/blog/sitemap.ts (serves /blog/sitemap.xml). The base URL is auto-detected from the request Host header, so no extra configuration is needed. You can optionally set NEXT_PUBLIC_BASE_URL in .env.local if you want to hard-code it.
Manual setup
The SDK exports two helpers:
getBlogSitemapEntries()— returns an array of sitemap entries to merge with your owncreateBlogSitemap()— returns a standalone sitemap function
Standalone blog sitemap (recommended)
Create a dedicated sitemap just for blog articles at /blog/sitemap.xml. This won't conflict with your main app/sitemap.ts:
// app/blog/sitemap.ts → /blog/sitemap.xml
import { createBlogSitemap } from "@earlyseo/blog/next";
const siteId = process.env.EARLYSEO_SITE_ID!;
// baseUrl is auto-detected from NEXT_PUBLIC_BASE_URL or the request Host header
export default createBlogSitemap({ siteId });Merge into an existing sitemap
If you already have app/sitemap.ts, add blog entries to it:
import { getBlogSitemapEntries } from "@earlyseo/blog/next";
import type { MetadataRoute } from "next";
const siteId = process.env.EARLYSEO_SITE_ID!;
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
// baseUrl auto-detected from NEXT_PUBLIC_BASE_URL or Host header
const blogEntries = await getBlogSitemapEntries({ siteId });
return [
{ url: "https://example.com", lastModified: new Date() },
// your other pages…
...blogEntries,
];
}Standalone blog sitemap
If you want a dedicated sitemap just for blog articles:
// app/blog/sitemap.ts → /blog/sitemap.xml
import { createBlogSitemap } from "@earlyseo/blog/next";
const siteId = process.env.EARLYSEO_SITE_ID!;
export default createBlogSitemap({ siteId });Options
| Option | Type | Default | Description |
|---|---|---|---|
siteId | string | — | Your EarlySEO Site ID (required) |
baseUrl | string | auto-detected | Your site's public URL. Falls back to NEXT_PUBLIC_BASE_URL then request Host header |
basePath | string | /blog | Blog route prefix |
changeFrequency | string | weekly | Sitemap change frequency hint |
priority | number | 0.7 | Sitemap priority for article pages |
fetchInit | RequestInit | — | Additional fetch options (e.g. { next: { revalidate: 3600 } }) |
Environment variables
Add to .env.local:
EARLYSEO_SITE_ID=your-site-id
# Optional: baseUrl is auto-detected from the Host header if not set
NEXT_PUBLIC_BASE_URL=https://example.comDjango
The SDK provides an EarlySeoBlogSitemap class that plugs into Django's built-in sitemaps framework.
1. Add django.contrib.sitemaps to INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
# …
"django.contrib.sitemaps",
"earlyseo_blog.django",
]2. Register the sitemap in URLs
# urls.py
from django.contrib.sitemaps.views import sitemap
from earlyseo_blog.django.sitemap import EarlySeoBlogSitemap
sitemaps = {
"blog": EarlySeoBlogSitemap,
}
urlpatterns = [
path("blog/", include("earlyseo_blog.django.urls")),
path("sitemap.xml", sitemap, {"sitemaps": sitemaps}, name="sitemap"),
]That's it. Django will serve blog article URLs at /sitemap.xml.
Configuration
| Setting | Default | Description |
|---|---|---|
EARLYSEO_SITE_ID | — | Your site ID (required) |
EARLYSEO_BLOG_PATH | /blog | Blog URL prefix used in sitemap <loc> |
EARLYSEO_CDN_BASE_URL | https://media.earlyseo.com | Override CDN base URL |
Combining with other sitemaps
Add your own sitemaps alongside the blog:
from django.contrib.sitemaps import Sitemap
from earlyseo_blog.django.sitemap import EarlySeoBlogSitemap
class StaticSitemap(Sitemap):
changefreq = "monthly"
priority = 0.8
def items(self):
return ["home", "about", "contact"]
def location(self, item):
return f"/{item}/"
sitemaps = {
"static": StaticSitemap,
"blog": EarlySeoBlogSitemap,
}Flask
The SDK provides two ways to add a sitemap to your Flask app.
Option 1: Automatic route registration
Register a /blog/sitemap.xml route with one call:
from flask import Flask
from earlyseo_blog.flask.views import create_blog_blueprint
from earlyseo_blog.flask.sitemap import register_blog_sitemap
app = Flask(__name__)
app.config["EARLYSEO_SITE_ID"] = "your-site-id"
app.config["EARLYSEO_BASE_URL"] = "https://example.com"
app.register_blueprint(create_blog_blueprint(), url_prefix="/blog")
register_blog_sitemap(app, url_prefix="/blog")Visit /blog/sitemap.xml to see the generated XML.
Option 2: Build your own sitemap
Use create_blog_sitemap_entries() to get entry dicts and build a custom sitemap:
from earlyseo_blog.flask.sitemap import create_blog_sitemap_entries
@app.route("/sitemap.xml")
def full_sitemap():
blog_entries = create_blog_sitemap_entries(
base_url="https://example.com",
blog_path="/blog",
)
# Merge with your own entries and render XML
all_entries = static_entries + blog_entries
return render_sitemap_xml(all_entries)Configuration
| Config Key | Default | Description |
|---|---|---|
EARLYSEO_SITE_ID | — | Your site ID (required) |
EARLYSEO_BASE_URL | "" | Your site's public URL for absolute sitemap URLs |
EARLYSEO_CDN_BASE_URL | https://media.earlyseo.com | Override CDN base URL |
How it works
The sitemap helpers:
- Fetch your site manifest from the EarlySEO CDN
- Iterate through all paginated article list pages
- Collect every article slug and its creation date
- Return properly formatted sitemap entries
No database queries, no API keys — just the same CDN that powers your blog pages.
Verify your sitemap
After setup:
- Start your dev server
- Visit your sitemap URL (e.g.
/sitemap.xmlor/blog/sitemap.xml) - Confirm blog article URLs appear in the XML
- Use Google Search Console to submit your sitemap