@@ -172,7 +172,8 @@ export class PreviewServer {
172
172
} else {
173
173
if ( ( pathname = normalize ( pathname ) ) . startsWith ( ".." ) ) throw new Error ( "Invalid path: " + pathname ) ;
174
174
175
- // Normalize the pathname (e.g., dropping ".html").
175
+ // Normalize the pathname (e.g., adding ".html" if cleanUrls is false,
176
+ // dropping ".html" if cleanUrls is true) and redirect if necessary.
176
177
const normalizedPathname = config . md . normalizeLink ( pathname ) ;
177
178
if ( url . pathname !== normalizedPathname ) {
178
179
res . writeHead ( 302 , { Location : normalizedPathname + url . search } ) ;
@@ -181,11 +182,14 @@ export class PreviewServer {
181
182
}
182
183
183
184
// If this path ends with a slash, then add an implicit /index to the
184
- // end of the path.
185
+ // end of the path. Otherwise, remove the .html extension (we use clean
186
+ // paths as the internal canonical representation; see normalizePage).
185
187
let path = join ( root , pathname ) ;
186
188
if ( pathname . endsWith ( "/" ) ) {
187
189
pathname = join ( pathname , "index" ) ;
188
190
path = join ( path , "index" ) ;
191
+ } else {
192
+ pathname = pathname . replace ( / \. h t m l $ / , "" ) ;
189
193
}
190
194
191
195
// Lastly, serve the corresponding Markdown file, if it exists.
0 commit comments