Skip to content

Commit 4eb6d3f

Browse files
committed
Implement Markdown Export Feature: Add API route for .md exports and update middleware for URL handling. Remove llms.txt.
1 parent 2661a20 commit 4eb6d3f

File tree

4 files changed

+33
-141
lines changed

4 files changed

+33
-141
lines changed

LLMS_TXT_FEATURE.md

Lines changed: 22 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
# LLMs.txt Feature Documentation
1+
# Markdown Export Feature Documentation
22

3-
## Overview
3+
This feature allows converting any page on the Sentry documentation site to a plain markdown format by simply appending `.md` to the end of any URL (without a trailing slash). The feature extracts the actual page content from the source MDX files and converts it to clean markdown, making the documentation more accessible to Large Language Models and other tools.
44

5-
This feature allows converting any page on the Sentry documentation site to a plain markdown format by simply appending `llms.txt` to the end of any URL. The feature extracts the actual page content from the source MDX files and converts it to clean markdown, making the documentation more accessible to Large Language Models (LLMs) and other automated tools.
5+
## Example URLs
6+
7+
- Markdown Export: https://docs.sentry.io/platforms/javascript/guides/react/user-feedback.md
8+
- Markdown Export: https://docs.sentry.io/platforms/javascript/guides/nextjs/user-feedback.md
9+
- Markdown Export: https://docs.sentry.io/platforms/javascript/guides/react/tracing.md
10+
11+
## How it works
12+
13+
- URL: /platforms/javascript/guides/react/user-feedback.md
14+
- Rewrite: /api/md-export/platforms/javascript/guides/react/user-feedback
15+
16+
## Example usage
17+
18+
```
19+
curl "http://localhost:3000/platforms/javascript/guides/react/user-feedback.md"
20+
curl "http://localhost:3000/platforms/javascript/guides/nextjs/user-feedback.md"
21+
curl "http://localhost:3000/platforms/javascript/guides/react/tracing.md"
22+
curl "http://localhost:3000/platforms/javascript/guides/vue/user-feedback.md"
23+
```
624

725
## **Feature Status: FULLY WORKING**
826

@@ -112,128 +130,4 @@ yarn add @sentry/react
112130

113131
```bash {tabTitle:pnpm}
114132
pnpm add @sentry/react
115-
```
116-
```
117-
118-
## Smart Content Processing
119-
120-
### Enhanced JSX Component Handling
121-
- **Alert components** → `> **Note:** [content]`
122-
- **PlatformIdentifier** → `` `traces-sample-rate` ``
123-
- **PlatformLink** → `[Link Text](/path/to/page)`
124-
- **PlatformContent includes** → **Actual platform-specific content loaded from files**
125-
- **Code block preservation** → All existing markdown code blocks preserved
126-
- **Nested components** → Multi-pass processing ensures complete cleanup
127-
128-
### Content Preservation Technology
129-
- ✅ **Code Block Protection**: Temporarily replaces code blocks during JSX cleanup
130-
- ✅ **Include Resolution**: Loads real content from platform-includes directory
131-
- ✅ **Platform Awareness**: Automatically detects platform/guide from URL path
132-
- ✅ **Smart Fallbacks**: Graceful degradation when includes aren't found
133-
- ✅ **Content Reconstruction**: Restores protected content after cleanup
134-
135-
## Response Format with Code Snippets
136-
137-
```markdown
138-
# Set Up User Feedback
139-
140-
The User Feedback feature allows you to collect user feedback from anywhere inside your application at any time.
141-
142-
> **Note:**
143-
If you're using a self-hosted Sentry instance, you'll need to be on version 24.4.2 or higher.
144-
145-
### Installation
146-
147-
The User Feedback integration is **already included** with the React SDK package.
148-
149-
```bash {tabTitle:npm}
150-
npm install @sentry/react --save
151-
```
152-
153-
```bash {tabTitle:yarn}
154-
yarn add @sentry/react
155-
```
156-
157-
```bash {tabTitle:pnpm}
158-
pnpm add @sentry/react
159-
```
160-
161-
### Set Up
162-
163-
```javascript
164-
Sentry.init({
165-
dsn: "___PUBLIC_DSN___",
166-
167-
integrations: [
168-
Sentry.feedbackIntegration({
169-
colorScheme: "system",
170-
}),
171-
],
172-
});
173-
```
174-
175-
---
176-
177-
**Original URL**: https://docs.sentry.io/platforms/javascript/guides/react/user-feedback
178-
**Generated**: 2025-06-10T22:25:15.123Z
179-
180-
*This is the full page content converted to markdown format.*
181-
```
182-
183-
## Technical Implementation
184-
185-
### Enhanced API Route Features
186-
```typescript
187-
// New async function for include resolution
188-
async function resolvePlatformIncludes(content: string, pathSegments: string[]): Promise<string> {
189-
// Platform detection from URL segments
190-
// File loading from platform-includes/
191-
// Content replacement with error handling
192-
}
193-
194-
// Code block preservation during cleanup
195-
cleaned = cleaned.replace(/```[\s\S]*?```/g, (match) => {
196-
codeBlocks.push(match);
197-
return `${codeBlockPlaceholder}${codeBlocks.length - 1}`;
198-
});
199-
```
200-
201-
### File System Integration
202-
- **Direct file access** to `platform-includes/` directory
203-
- **Gray-matter parsing** for include files
204-
- **Multi-path resolution** with intelligent fallbacks
205-
- **Error handling** with descriptive placeholders
206-
207-
## Benefits
208-
209-
**Complete Content**: Extracts actual page content AND code snippets
210-
**Platform-Specific**: Shows correct installation/setup for each framework
211-
**LLM-Optimized**: Clean markdown format perfect for AI processing
212-
**Smart Conversion**: JSX components converted to appropriate markdown
213-
**Code Preservation**: All code blocks and snippets properly maintained
214-
**Universal Access**: Works with any documentation page
215-
**High Performance**: Cached responses with efficient processing
216-
**Error Resilient**: Graceful fallbacks and informative error messages
217-
218-
## Testing Commands
219-
220-
```bash
221-
# Test React user feedback with full code snippets
222-
curl "http://localhost:3000/platforms/javascript/guides/react/user-feedback/llms.txt"
223-
224-
# Test Next.js-specific installation (shows wizard command)
225-
curl "http://localhost:3000/platforms/javascript/guides/nextjs/user-feedback/llms.txt"
226-
227-
# Test React tracing with platform-specific content
228-
curl "http://localhost:3000/platforms/javascript/guides/react/tracing/llms.txt"
229-
230-
# Test Vue.js user feedback (different platform)
231-
curl "http://localhost:3000/platforms/javascript/guides/vue/user-feedback/llms.txt"
232-
```
233-
234-
---
235-
236-
**Status**: ✅ **PRODUCTION READY WITH FULL CODE SNIPPETS**
237-
**Last Updated**: December 2024
238-
**Content Quality**: Full page content with platform-specific code examples
239-
**Code Coverage**: Installation, setup, configuration, and API examples all included
133+
```

app/api/llms-txt/[...path]/route.ts renamed to app/api/md-export/[...path]/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {getDocsRootNode, nodeForPath} from 'sentry-docs/docTree';
88
import {isDeveloperDocs} from 'sentry-docs/isDeveloperDocs';
99
import {getFileBySlugWithCache} from 'sentry-docs/mdx';
1010

11+
// This route handles .md export requests for any documentation page
1112
export async function GET(
1213
_request: Request,
1314
{params}: {params: Promise<{path: string[]}>}
@@ -198,7 +199,7 @@ For the complete content with full formatting, code examples, and interactive el
198199

199200
return createResponse(pageTitle, cleanContent, `/${pathSegments.join('/')}`);
200201
} catch (error) {
201-
console.error('Error generating llms.txt:', error);
202+
console.error('Error generating .md export:', error);
202203
return new NextResponse('Internal server error', {status: 500});
203204
}
204205
}
@@ -328,7 +329,7 @@ async function resolvePlatformIncludes(
328329
// Build platform identifier for include files
329330
let platformId = platform;
330331
if (guide && guide !== platform) {
331-
platformId = `${platform}.${guide}`;
332+
platformId = `${platform}.${guide}`;
332333
}
333334

334335
// Replace PlatformContent includes with actual content
@@ -383,4 +384,4 @@ async function resolvePlatformIncludes(
383384
}
384385

385386
return result;
386-
}
387+
}

redirects.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ const isDeveloperDocs = !!process.env.NEXT_PUBLIC_DEVELOPER_DOCS;
22

33
/** @type {import('next/dist/lib/load-custom-routes').Redirect[]} */
44
const developerDocsRedirects = [
5-
// LLMs.txt redirect - converts any page to markdown format
6-
{
7-
source: '/:path*/llms.txt',
8-
destination: '/api/llms-txt/:path*',
9-
},
105
{
116
source: '/sdk/miscellaneous/unified-api/tracing/:path*',
127
destination: '/sdk/performance/:path*',
@@ -223,11 +218,6 @@ const developerDocsRedirects = [
223218

224219
/** @type {import('next/dist/lib/load-custom-routes').Redirect[]} */
225220
const userDocsRedirects = [
226-
// LLMs.txt redirect - converts any page to markdown format
227-
{
228-
source: '/:path*/llms.txt',
229-
destination: '/api/llms-txt/:path*',
230-
},
231221
{
232222
source: '/organization/integrations/telegram-alerts-bot/',
233223
destination: '/organization/integrations/notification-incidents/telegram-alerts-bot/',

src/middleware.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export const config = {
1919

2020
// This function can be marked `async` if using `await` inside
2121
export function middleware(request: NextRequest) {
22+
// Handle .md export requests by rewriting to API route while preserving URL
23+
if (request.nextUrl.pathname.endsWith('.md')) {
24+
const pathWithoutMd = request.nextUrl.pathname.slice(0, -3); // Remove .md
25+
const rewriteUrl = new URL(`/api/md-export${pathWithoutMd}`, request.url);
26+
return NextResponse.rewrite(rewriteUrl);
27+
}
28+
2229
// Remove the llms.txt handling - it's now handled by Next.js redirects
2330
return handleRedirects(request);
2431
}

0 commit comments

Comments
 (0)