Skip to content

Commit cbcf166

Browse files
committed
fix(core): ensure trailing slash of page path (close #114)
1 parent 9cf0d21 commit cbcf166

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

packages/@vuepress/core/__tests__/page/resolvePagePath.spec.ts

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,31 @@ const testCases: [
1414
},
1515
},
1616
],
17-
'/permalink',
17+
'/permalink/',
18+
],
19+
[
20+
[
21+
{
22+
permalink: '/permalink/',
23+
pathInferred: '/inferred/',
24+
options: {
25+
path: '/options/',
26+
},
27+
},
28+
],
29+
'/permalink/',
30+
],
31+
[
32+
[
33+
{
34+
permalink: '/permalink.html',
35+
pathInferred: '/inferred.html',
36+
options: {
37+
path: '/options.html',
38+
},
39+
},
40+
],
41+
'/permalink.html',
1842
],
1943
[
2044
[
@@ -26,7 +50,19 @@ const testCases: [
2650
},
2751
},
2852
],
29-
'/inferred',
53+
'/inferred/',
54+
],
55+
[
56+
[
57+
{
58+
permalink: null,
59+
pathInferred: '/inferred/',
60+
options: {
61+
path: '/options/',
62+
},
63+
},
64+
],
65+
'/inferred/',
3066
],
3167
[
3268
[
@@ -38,7 +74,31 @@ const testCases: [
3874
},
3975
},
4076
],
41-
'/options',
77+
'/options/',
78+
],
79+
[
80+
[
81+
{
82+
permalink: null,
83+
pathInferred: null,
84+
options: {
85+
path: '/options/',
86+
},
87+
},
88+
],
89+
'/options/',
90+
],
91+
[
92+
[
93+
{
94+
permalink: null,
95+
pathInferred: null,
96+
options: {
97+
path: '/options.html',
98+
},
99+
},
100+
],
101+
'/options.html',
42102
],
43103
]
44104

packages/@vuepress/core/src/page/resolvePagePath.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ensureEndingSlash } from '@vuepress/shared'
12
import { logger } from '@vuepress/utils'
23
import type { PageOptions } from '../types'
34

@@ -13,13 +14,17 @@ export const resolvePagePath = ({
1314
pathInferred: string | null
1415
options: PageOptions
1516
}): string => {
16-
const pagePath = permalink || pathInferred || options.path
17+
let pagePath = permalink || pathInferred || options.path
1718

1819
if (!pagePath) {
1920
throw logger.createError(
2021
`page path is empty, page options: ${JSON.stringify(options)}`
2122
)
2223
}
2324

25+
if (!pagePath.endsWith('.html')) {
26+
pagePath = ensureEndingSlash(pagePath)
27+
}
28+
2429
return encodeURI(pagePath)
2530
}

0 commit comments

Comments
 (0)