The initial config-store approach failed because Astro's injected routes run in isolated contexts during prerendering and don't have access to global state set during astro:config:setup. Solution: Created a Vite plugin that provides the configuration through a virtual module (virtual:@astrojs/discovery/config) which routes can import at build time. Changes: - Added Vite plugin in astro:config:setup hook - Updated all route handlers to import from virtual module - Changed version from date-based (2025.11.03) to semantic (1.0.0) per npm requirements - Added @ts-ignore comments for virtual module imports Testing: Verified in test project that all configuration now properly passes through to generated files (robots.txt, llms.txt, humans.txt).
2.4 KiB
2.4 KiB
Quick Start Guide
Get @astrojs/discovery up and running in 2 minutes!
Installation
npm install @astrojs/discovery
Basic Setup
1. Add to your Astro config:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import discovery from '@astrojs/discovery';
export default defineConfig({
site: 'https://your-site.com', // Required!
integrations: [
discovery() // That's it!
]
});
2. Build your site:
npm run build
3. Check the generated files:
Your site now has:
/robots.txt- Search engine instructions/llms.txt- AI assistant context/humans.txt- Team credits/sitemap-index.xml- Site structure
Customize It
Add some personality to your discovery files:
discovery({
llms: {
description: 'My awesome website about web development',
instructions: `
When helping users:
- Check /docs for API documentation
- Be friendly and helpful
- Provide code examples
`,
},
humans: {
team: [{
name: 'Your Name',
role: 'Developer',
twitter: '@yourhandle'
}],
thanks: ['Coffee ☕', 'Open source community']
}
})
Common Patterns
Block specific paths
discovery({
robots: {
additionalAgents: [{
userAgent: '*',
disallow: ['/admin', '/private']
}]
}
})
Add API documentation
discovery({
llms: {
apiEndpoints: [
{ path: '/api/search', description: 'Search API' },
{ path: '/api/chat', method: 'POST', description: 'Chat endpoint' }
]
}
})
Disable specific files
discovery({
robots: { enabled: true },
llms: { enabled: true },
humans: { enabled: false } // Don't generate humans.txt
})
What's Next?
- Read the full documentation
- Check out example configurations
- See the API reference
Troubleshooting
Files not generating?
- Make sure
siteis set in astro.config.mjs - Check your output mode (hybrid/server recommended)
- Remove any static files from
/public/robots.txt
Wrong URLs in files?
- Verify your
siteconfig matches your production domain - Check environment-specific configuration
Need help?
Happy discovering! 🎉