@@ -52,20 +52,31 @@ exports.handler = (event, context, callback) => {
5252 return
5353 }
5454
55- // Handle directory requests by appending index.html for requests without file extensions
55+ // Check Accept header for markdown/text requests
56+ const headers = request . headers ;
57+ const acceptHeader = headers . accept ? headers . accept [ 0 ] . value : '' ;
58+ const wantsMarkdown = acceptHeader . includes ( 'text/markdown' ) ||
59+ acceptHeader . includes ( 'text/plain' ) ;
60+
61+ // Handle directory requests by appending index.html or index.md for requests without file extensions
5662 let uri = request . uri ;
5763
5864 // Check if the URI has a dot after the last slash (indicating a filename)
5965 // This is more accurate than just checking the end of the URI
6066 const hasFileExtension = / \. [ ^ / ] * $ / . test ( uri . split ( '/' ) . pop ( ) ) ;
6167
62- // If it's not a file, treat it as a directory and append index.html
68+ // If it's not a file, treat it as a directory
6369 if ( ! hasFileExtension ) {
64- // Ensure the URI ends with a slash before appending index.html
70+ // Ensure the URI ends with a slash before appending index file
6571 if ( ! uri . endsWith ( "/" ) ) {
6672 uri += "/" ;
6773 }
68- uri += "index.html" ;
74+ // Serve markdown if Accept header requests it, otherwise serve HTML
75+ uri += wantsMarkdown ? "index.md" : "index.html" ;
76+ request . uri = uri ;
77+ } else if ( wantsMarkdown && uri . endsWith ( '.html' ) ) {
78+ // If requesting a specific HTML file but wants markdown, try the .md version
79+ uri = uri . replace ( / \. h t m l $ / , '.md' ) ;
6980 request . uri = uri ;
7081 }
7182
0 commit comments