Skip to content

Commit 0a2f7dc

Browse files
committed
fix(core): use absolute path when creating pages (close vuepress#421)
BREAKING CHANGE: now `PageOptions` does not accept relative file path
1 parent 4dbd99d commit 0a2f7dc

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

packages/@vuepress/core/src/app/createAppPages.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ const log = debug('vuepress:core/app')
1010
export const createAppPages = async (app: App): Promise<Page[]> => {
1111
log('createAppPages start')
1212

13-
// resolve page file paths according to the page patterns
14-
const pagePaths = await globby(app.options.pagePatterns, {
13+
// resolve page absolute file paths according to the page patterns
14+
const pageFilePaths = await globby(app.options.pagePatterns, {
15+
absolute: true,
1516
cwd: app.dir.source(),
1617
})
1718

1819
// create pages from files
1920
const pages = await Promise.all(
20-
pagePaths.map((filePath) => createPage(app, { filePath }))
21+
pageFilePaths.map((filePath) => createPage(app, { filePath }))
2122
)
2223

2324
// if there is no 404 page, add one

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

+2-11
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,8 @@ export const resolvePageFilePath = ({
2222
}
2323
}
2424

25-
// absolute file path
26-
if (path.isAbsolute(filePath)) {
27-
return {
28-
filePath,
29-
filePathRelative: path.relative(app.dir.source(), filePath),
30-
}
31-
}
32-
33-
// relative file path
3425
return {
35-
filePath: app.dir.source(filePath),
36-
filePathRelative: filePath,
26+
filePath,
27+
filePathRelative: path.relative(app.dir.source(), filePath),
3728
}
3829
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ export const resolvePageOptions = async ({
1010
app: App
1111
optionsRaw: PageOptions
1212
}): Promise<PageOptions> => {
13+
// avoid mutating the original options object provided by user
1314
const options = { ...optionsRaw }
1415

1516
// plugin hook: extendsPageOptions
1617
const extendsPageOptions = await app.pluginApi.hooks.extendsPageOptions.process(
17-
optionsRaw,
18+
options,
1819
app
1920
)
2021
extendsPageOptions.forEach((item) => Object.assign(options, item))

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

+23-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,29 @@ export interface Page<T extends PageData = PageData> extends PageData {
135135
* Options to create vuepress page
136136
*/
137137
export interface PageOptions {
138-
path?: string
138+
/**
139+
* If `filePath` is not set, this option will be used as the raw
140+
* markdown content of the page.
141+
*
142+
* If `filePath` is set, this option will be ignored, while the
143+
* content of the file will be used.
144+
*/
145+
content?: string
146+
147+
/**
148+
* Absolute file path of the markdown source file.
149+
*/
139150
filePath?: string
151+
152+
/**
153+
* Default frontmatter of the page, which could be overridden by
154+
* the frontmatter of the markdown content.
155+
*/
140156
frontmatter?: PageFrontmatter
141-
content?: string
157+
158+
/**
159+
* If this option is set, it will be used as the final route path
160+
* of the page, ignoring the relative path and permalink.
161+
*/
162+
path?: string
142163
}

0 commit comments

Comments
 (0)