fix: use Vite virtual module for configuration instead of global state
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).
This commit is contained in:
parent
d25dde4627
commit
c7b47bba5c
8 changed files with 594 additions and 8 deletions
131
QUICKSTART.md
Normal file
131
QUICKSTART.md
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
# Quick Start Guide
|
||||
|
||||
Get @astrojs/discovery up and running in 2 minutes!
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @astrojs/discovery
|
||||
```
|
||||
|
||||
## Basic Setup
|
||||
|
||||
**1. Add to your Astro config:**
|
||||
|
||||
```typescript
|
||||
// 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:**
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
```typescript
|
||||
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
|
||||
|
||||
```typescript
|
||||
discovery({
|
||||
robots: {
|
||||
additionalAgents: [{
|
||||
userAgent: '*',
|
||||
disallow: ['/admin', '/private']
|
||||
}]
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Add API documentation
|
||||
|
||||
```typescript
|
||||
discovery({
|
||||
llms: {
|
||||
apiEndpoints: [
|
||||
{ path: '/api/search', description: 'Search API' },
|
||||
{ path: '/api/chat', method: 'POST', description: 'Chat endpoint' }
|
||||
]
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Disable specific files
|
||||
|
||||
```typescript
|
||||
discovery({
|
||||
robots: { enabled: true },
|
||||
llms: { enabled: true },
|
||||
humans: { enabled: false } // Don't generate humans.txt
|
||||
})
|
||||
```
|
||||
|
||||
## What's Next?
|
||||
|
||||
- Read the [full documentation](README.md)
|
||||
- Check out [example configurations](example/)
|
||||
- See the [API reference](README.md#api-reference)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Files not generating?**
|
||||
- Make sure `site` is 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 `site` config matches your production domain
|
||||
- Check environment-specific configuration
|
||||
|
||||
**Need help?**
|
||||
- [Open an issue](https://github.com/withastro/astro-discovery/issues)
|
||||
- [Read the docs](README.md)
|
||||
- [View examples](example/)
|
||||
|
||||
---
|
||||
|
||||
**Happy discovering! 🎉**
|
||||
Loading…
Add table
Add a link
Reference in a new issue