@@ -68,8 +68,11 @@ exports.handler = (event, context, callback) => {
6868 // If it's not a file, treat it as a directory
6969 if ( ! hasFileExtension ) {
7070 if ( wantsMarkdown ) {
71- // Markdown files are flattened: /path/to/page.md not /path/to/page/index.md
72- uri = uri . replace ( / \/ $ / , '' ) + '.md' ;
71+ // Markdown files are flattened: /path/to/page.md not /path/to/page/index.md.
72+ // Homepage has no flattened equivalent, so serve llms.txt as the
73+ // agent-oriented markdown index of the site.
74+ const stripped = uri . replace ( / \/ $ / , '' ) ;
75+ uri = stripped === '' ? '/llms.txt' : stripped + '.md' ;
7376 } else {
7477 // HTML uses directory structure with index.html
7578 if ( ! uri . endsWith ( "/" ) ) {
@@ -79,8 +82,9 @@ exports.handler = (event, context, callback) => {
7982 }
8083 request . uri = uri ;
8184 } else if ( wantsMarkdown && uri . endsWith ( '/index.html' ) ) {
82- // If requesting index.html but wants markdown, use the flattened .md file
83- uri = uri . replace ( / \/ i n d e x \. h t m l $ / , '.md' ) ;
85+ // If requesting index.html but wants markdown, use the flattened .md file.
86+ // Root index.html has no flattened equivalent, so serve llms.txt instead.
87+ uri = uri === '/index.html' ? '/llms.txt' : uri . replace ( / \/ i n d e x \. h t m l $ / , '.md' ) ;
8488 request . uri = uri ;
8589 }
8690
0 commit comments