File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 1
- import { ensureLeadingSlash , resolveLocalePath } from '@vuepress/shared'
1
+ import {
2
+ ensureLeadingSlash ,
3
+ inferRoutePath ,
4
+ resolveLocalePath ,
5
+ } from '@vuepress/shared'
2
6
import type { App } from '../types/index.js'
3
7
4
8
/**
@@ -23,9 +27,7 @@ export const inferPagePath = ({
23
27
24
28
// infer page route path from file path
25
29
// foo/bar.md -> /foo/bar.html
26
- const pathInferred = ensureLeadingSlash ( filePathRelative )
27
- . replace ( / \. m d $ / , '.html' )
28
- . replace ( / \/ ( R E A D M E | i n d e x ) .h t m l $ / i, '/' )
30
+ const pathInferred = ensureLeadingSlash ( inferRoutePath ( filePathRelative ) )
29
31
30
32
// resolve page locale path
31
33
const pathLocale = resolveLocalePath ( app . siteData . locales , pathInferred )
Original file line number Diff line number Diff line change 1
1
/**
2
- * Infer route path according to the given (markdown file) path
2
+ * Infer route path of the given raw path
3
3
*/
4
- export const inferRoutePath = ( path : string ) : string => {
5
- // if the pathname is empty or ends with `/`, return as is
6
- if ( ! path || path . endsWith ( '/' ) ) return path
4
+ export const inferRoutePath = ( rawPath : string ) : string => {
5
+ // if the raw path is empty or ends with `/`, return as is
6
+ if ( ! rawPath || rawPath . endsWith ( '/' ) ) return rawPath
7
7
8
8
// convert README.md to index.html
9
- let routePath = path . replace ( / ( ^ | \/ ) R E A D M E .m d $ / i, '$1index.html' )
9
+ let routePath = rawPath . replace ( / ( ^ | \/ ) R E A D M E .m d $ / i, '$1index.html' )
10
10
11
11
// convert /foo/bar.md to /foo/bar.html
12
12
if ( routePath . endsWith ( '.md' ) ) {
You can’t perform that action at this time.
0 commit comments