@@ -37,16 +37,16 @@ const redirectStatusCode = process.env.NODE_ENV === 'development' ? 302 : 301;
3737 */
3838function isAIOrDevTool ( userAgent : string ) : boolean {
3939 const patterns = [
40- / c l a u d e / i, // Claude Desktop/Code
41- / c u r s o r / i, // Cursor IDE
42- / c o p i l o t / i, // GitHub Copilot
43- / c h a t g p t / i, // ChatGPT
44- / o p e n a i / i, // OpenAI tools
45- / a n t h r o p i c / i, // Anthropic tools
46- / v s c o d e / i, // VS Code extensions
47- / i n t e l l i j / i, // IntelliJ plugins
48- / s u b l i m e / i, // Sublime Text plugins
49- / g o t / i, // Got HTTP library (sindresorhus/got)
40+ / c l a u d e / i, // Claude Desktop/Code
41+ / c u r s o r / i, // Cursor IDE
42+ / c o p i l o t / i, // GitHub Copilot
43+ / c h a t g p t / i, // ChatGPT
44+ / o p e n a i / i, // OpenAI tools
45+ / a n t h r o p i c / i, // Anthropic tools
46+ / v s c o d e / i, // VS Code extensions
47+ / i n t e l l i j / i, // IntelliJ plugins
48+ / s u b l i m e / i, // Sublime Text plugins
49+ / g o t / i, // Got HTTP library (sindresorhus/got)
5050 // Add more patterns as needed
5151 ] ;
5252
@@ -63,14 +63,19 @@ const handleAIClientRedirect = (request: NextRequest) => {
6363 // Determine if this will be served as markdown
6464 const forceMarkdown = url . searchParams . get ( 'format' ) === 'md' ;
6565 const isAIClient = isAIOrDevTool ( userAgent ) ;
66- const willServeMarkdown = ( isAIClient || forceMarkdown ) && ! url . pathname . endsWith ( '.md' ) ;
66+ const willServeMarkdown =
67+ ( isAIClient || forceMarkdown ) && ! url . pathname . endsWith ( '.md' ) ;
6768
6869 // Log user agent for debugging (only for non-static assets)
69- if ( ! url . pathname . startsWith ( '/_next/' ) &&
70- ! url . pathname . includes ( '.' ) &&
71- ! url . pathname . startsWith ( '/api/' ) ) {
70+ if (
71+ ! url . pathname . startsWith ( '/_next/' ) &&
72+ ! url . pathname . includes ( '.' ) &&
73+ ! url . pathname . startsWith ( '/api/' )
74+ ) {
7275 const contentType = willServeMarkdown ? '📄 MARKDOWN' : '🌐 HTML' ;
73- console . log ( `[Middleware] ${ url . pathname } - ${ contentType } - User-Agent: ${ userAgent } ` ) ;
76+ console . log (
77+ `[Middleware] ${ url . pathname } - ${ contentType } - User-Agent: ${ userAgent } `
78+ ) ;
7479 }
7580
7681 // Skip if already requesting a markdown file
@@ -79,17 +84,21 @@ const handleAIClientRedirect = (request: NextRequest) => {
7984 }
8085
8186 // Skip API routes and static assets (should already be filtered by matcher)
82- if ( url . pathname . startsWith ( '/api/' ) ||
83- url . pathname . startsWith ( '/_next/' ) ||
84- url . pathname . includes ( '.' ) ) {
87+ if (
88+ url . pathname . startsWith ( '/api/' ) ||
89+ url . pathname . startsWith ( '/_next/' ) ||
90+ url . pathname . includes ( '.' )
91+ ) {
8592 return undefined ;
8693 }
8794
8895 // Check for AI client detection
8996
9097 if ( isAIClient || forceMarkdown ) {
9198 // Log the redirect for debugging
92- console . log ( `[Middleware] Redirecting to markdown: ${ isAIClient ? 'AI client detected' : 'Manual format=md' } ` ) ;
99+ console . log (
100+ `[Middleware] Redirecting to markdown: ${ isAIClient ? 'AI client detected' : 'Manual format=md' } `
101+ ) ;
93102
94103 // Create new URL with .md extension
95104 const newUrl = url . clone ( ) ;
0 commit comments