Sitemap & Robots
Velocity automatically generates sitemap and robots.txt files.
Sitemap
Section titled “Sitemap”Automatic Generation
Section titled “Automatic Generation”The sitemap is auto-generated by @astrojs/sitemap at:
https://yoursite.com/sitemap-index.xmlConfiguration
Section titled “Configuration”Sitemap is configured in astro.config.mjs:
import sitemap from '@astrojs/sitemap';
export default defineConfig({ site: 'https://yoursite.com', integrations: [sitemap()],});Excluding Pages
Section titled “Excluding Pages”Exclude pages from the sitemap:
sitemap({ filter: (page) => !page.includes('/private/'),})Custom Entries
Section titled “Custom Entries”Add external URLs:
sitemap({ customPages: [ 'https://yoursite.com/custom-page', ],})Robots.txt
Section titled “Robots.txt”Dynamic Generation
Section titled “Dynamic Generation”Robots.txt is generated at src/pages/robots.txt.ts:
import type { APIRoute } from 'astro';
export const GET: APIRoute = () => { const sitemapUrl = new URL('/sitemap-index.xml', import.meta.env.SITE);
const robotsTxt = `User-agent: *Allow: /
Sitemap: ${sitemapUrl.href}`.trim();
return new Response(robotsTxt, { headers: { 'Content-Type': 'text/plain', }, });};Disallowing Paths
Section titled “Disallowing Paths”Block specific paths:
const robotsTxt = `User-agent: *Allow: /Disallow: /admin/Disallow: /api/Disallow: /private/
Sitemap: ${sitemapUrl.href}`.trim();Multiple User Agents
Section titled “Multiple User Agents”Configure different rules per bot:
const robotsTxt = `User-agent: GooglebotAllow: /
User-agent: *Allow: /Disallow: /private/
Sitemap: ${sitemapUrl.href}`.trim();Best Practices
Section titled “Best Practices”Sitemap
Section titled “Sitemap”- Keep sitemap under 50MB
- Limit to 50,000 URLs per file
- Update regularly for fresh content
- Include only canonical URLs
Robots.txt
Section titled “Robots.txt”- Don’t block CSS/JS files
- Don’t use for hiding content (use
noindex) - Test with Google Search Console
- Keep rules simple and specific
Verification
Section titled “Verification”Google Search Console
Section titled “Google Search Console”- Submit your sitemap URL
- Check for crawl errors
- Monitor indexing status
Testing Robots.txt
Section titled “Testing Robots.txt”Use Google’s robots.txt Tester:
- Go to Search Console
- Select your property
- Use the robots.txt Tester tool