-
Notifications
You must be signed in to change notification settings - Fork 235
feat: optimize markdown urls for agents #4057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deployment failed with the following error: Learn More: https://vercel.link/3Fpeeb1 |
|
Deployment failed with the following error: |
|
Hi @ruf-io check this out! |
| ]; | ||
|
|
||
| const hasAIAgentUserAgent = aiAgentPatterns.some((pattern) => | ||
| userAgent.toLowerCase().includes(pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saimonkat do the models really put their name in the user agent? I did not see that in testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ruf-io the User-Agent detection is actually a fallback mechanism. The primary detection is the Accept header. User-Agent patterns serve as a fallback for specific agents (for example, Claude Code actually uses Claude-Test-Request), but the primary indicator is the Accept header.
This PR optimizes markdown URLs for AI agents by:
Technical Implementation
src/middleware.js- Intercepts AI agent requests and redirects to GitHub raw URLssrc/utils/ai-agent-detection.js- Detects AI agents and maps URLs to markdown file pathssrc/constants/content.js- Centralized configuration for content sectionsSupported Sections
/docs/*→content/docs/*.md/postgresql/*→content/postgresql/*.md/guides/*→content/guides/*.md/branching/*→content/branching/*.md/programs/*→content/pages/programs/*.md/use-cases/*→content/pages/use-cases/*.mdExcluded from Optimization
Tests
Tests
Full testing report by Claude Code
Successfully implemented direct markdown serving for AI agents, achieving 99% bandwidth reduction and 99% token savings with 100% content accuracy.
Test Results
1. AI Agent Detection ✅
User-Agent patterns tested (all working):
Accept header detection:
Accept: text/html→ HTMLAccept: application/json, text/plain, application/xml→ MarkdownAccept: */*→ HTML (default)Route coverage verified:
/docs/introduction→ serves markdown directly/guides/node→ serves markdown directly/postgresql/postgresql-extensions→ serves markdown directly/docs/changelog→ serves HTML (excluded, as expected)/guides→ serves HTML (excluded, as expected)/branching→ serves HTML (excluded, as expected)2. File Size Comparison
Result: Markdown is 82x smaller than HTML
3. Token Usage & Cost Savings
Projected savings at scale:
4. Content Accuracy ✅
Markdown version contains:
Result: 100% content match between HTML and Markdown versions
Summary
Preview