Skip to content

Commit 3f63c9e

Browse files
committed
Merge branch 'main' into meteorlxy-markdown-to-vue
2 parents 4e0c08f + 68023f0 commit 3f63c9e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/core/src/page/inferPagePath.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { ensureLeadingSlash, resolveLocalePath } from '@vuepress/shared'
1+
import {
2+
ensureLeadingSlash,
3+
inferRoutePath,
4+
resolveLocalePath,
5+
} from '@vuepress/shared'
26
import type { App } from '../types/index.js'
37

48
/**
@@ -23,9 +27,7 @@ export const inferPagePath = ({
2327

2428
// infer page route path from file path
2529
// foo/bar.md -> /foo/bar.html
26-
const pathInferred = ensureLeadingSlash(filePathRelative)
27-
.replace(/\.md$/, '.html')
28-
.replace(/\/(README|index).html$/i, '/')
30+
const pathInferred = ensureLeadingSlash(inferRoutePath(filePathRelative))
2931

3032
// resolve page locale path
3133
const pathLocale = resolveLocalePath(app.siteData.locales, pathInferred)

packages/shared/src/utils/routes/inferRoutePath.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
2-
* Infer route path according to the given (markdown file) path
2+
* Infer route path of the given raw path
33
*/
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
77

88
// convert README.md to index.html
9-
let routePath = path.replace(/(^|\/)README.md$/i, '$1index.html')
9+
let routePath = rawPath.replace(/(^|\/)README.md$/i, '$1index.html')
1010

1111
// convert /foo/bar.md to /foo/bar.html
1212
if (routePath.endsWith('.md')) {

0 commit comments

Comments
 (0)