Skip to content

Commit afbfa62

Browse files
authored
Merge pull request #23970 from dvdksn/fix-wantsmarkdown-redirect
fix: use the correct filepath to markdown rendition (no index.md)
2 parents 50f7d86 + 9afd284 commit afbfa62

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

hack/releaser/cloudfront-lambda-redirects.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ exports.handler = (event, context, callback) => {
6767

6868
// If it's not a file, treat it as a directory
6969
if (!hasFileExtension) {
70-
// Ensure the URI ends with a slash before appending index file
71-
if (!uri.endsWith("/")) {
72-
uri += "/";
70+
if (wantsMarkdown) {
71+
// Markdown files are flattened: /path/to/page.md not /path/to/page/index.md
72+
uri = uri.replace(/\/$/, '') + '.md';
73+
} else {
74+
// HTML uses directory structure with index.html
75+
if (!uri.endsWith("/")) {
76+
uri += "/";
77+
}
78+
uri += "index.html";
7379
}
74-
// Serve markdown if Accept header requests it, otherwise serve HTML
75-
uri += wantsMarkdown ? "index.md" : "index.html";
7680
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(/\.html$/, '.md');
81+
} else if (wantsMarkdown && uri.endsWith('/index.html')) {
82+
// If requesting index.html but wants markdown, use the flattened .md file
83+
uri = uri.replace(/\/index\.html$/, '.md');
8084
request.uri = uri;
8185
}
8286

0 commit comments

Comments
 (0)