Skip to content

Commit 83c9aae

Browse files
committed
feat(core): add deps to page object
1 parent fe20ccc commit 83c9aae

File tree

5 files changed

+52
-25
lines changed

5 files changed

+52
-25
lines changed

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

+16-8
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,26 @@ describe('core > page > createPage', () => {
2121
const page = await createPage(app, {
2222
path: '/',
2323
})
24+
25+
// page data
2426
expect(page.key).toBeTruthy()
2527
expect(page.path).toBe('/')
28+
expect(page.lang).toBe('en-US')
29+
expect(page.title).toBe('')
30+
expect(page.frontmatter).toEqual({})
31+
expect(page.excerpt).toBe('')
32+
expect(page.headers).toEqual([])
33+
34+
// extra data
2635
expect(page.pathInferred).toBeNull()
2736
expect(page.pathLocale).toBe('/')
37+
expect(page.content).toBe('')
38+
expect(page.slug).toBe('')
39+
expect(page.date).toBe('0000-00-00')
40+
expect(page.deps).toEqual([])
41+
expect(page.links).toEqual([])
42+
43+
// file info
2844
expect(page.filePath).toBeNull()
2945
expect(page.filePathRelative).toBeNull()
3046
expect(page.htmlFilePath).toBe(app.dir.dest(`index.html`))
@@ -44,13 +60,5 @@ describe('core > page > createPage', () => {
4460
`pages/${page.htmlFilePathRelative}.js`
4561
)
4662
expect(page.dataFileChunkName).toBe(page.key)
47-
expect(page.title).toBe('')
48-
expect(page.content).toBe('')
49-
expect(page.frontmatter).toEqual({})
50-
expect(page.excerpt).toBe('')
51-
expect(page.headers).toEqual([])
52-
expect(page.links).toEqual([])
53-
expect(page.slug).toBe('')
54-
expect(page.date).toBe('0000-00-00')
5563
})
5664
})

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

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('core > page > resolvePageComponentInfo', () => {
1919
})
2020

2121
expect(resolved).toEqual({
22+
deps: [],
2223
headers: [],
2324
links: [],
2425
componentFilePath: app.dir.temp('pages/foo.html.vue'),
@@ -40,6 +41,7 @@ describe('core > page > resolvePageComponentInfo', () => {
4041
})
4142

4243
expect(resolved).toEqual({
44+
deps: [],
4345
headers: [],
4446
links: [],
4547
componentFilePath: app.dir.temp('pages/foo.html.vue'),

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const createPage = async (
8181

8282
// resolve page component and extract headers & links
8383
const {
84+
deps,
8485
headers,
8586
links,
8687
componentFilePath,
@@ -107,10 +108,25 @@ export const createPage = async (
107108
const title = resolvePageTitle({ content, frontmatter, headers })
108109

109110
return {
111+
// page data
110112
key,
111113
path,
114+
title,
115+
lang,
116+
frontmatter,
117+
excerpt,
118+
headers,
119+
120+
// extra data
112121
pathInferred,
113122
pathLocale,
123+
content,
124+
slug,
125+
date,
126+
deps,
127+
links,
128+
129+
// file info
114130
filePath,
115131
filePathRelative,
116132
componentFilePath,
@@ -122,14 +138,5 @@ export const createPage = async (
122138
dataFileChunkName,
123139
htmlFilePath,
124140
htmlFilePathRelative,
125-
title,
126-
content,
127-
frontmatter,
128-
excerpt,
129-
headers,
130-
links,
131-
slug,
132-
date,
133-
lang,
134141
}
135142
}

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const resolvePageComponentInfo = async ({
2626
htmlFilePathRelative: string
2727
key: string
2828
}): Promise<{
29+
deps: string[]
2930
headers: MarkdownHeader[]
3031
links: MarkdownLink[]
3132
componentFilePath: string
@@ -43,9 +44,12 @@ export const resolvePageComponentInfo = async ({
4344
const rendered = app.markdown.render(content, markdownEnv)
4445

4546
/* istanbul ignore next */
46-
const { headers = [], links = [], hoistedTags = [] } = markdownEnv
47-
48-
// TODO: links check
47+
const {
48+
headers = [],
49+
hoistedTags = [],
50+
importedFiles = [],
51+
links = [],
52+
} = markdownEnv
4953

5054
// resolve component file content
5155
// take the rendered markdown content as <template>
@@ -64,6 +68,7 @@ export const resolvePageComponentInfo = async ({
6468
const componentFileChunkName = key
6569

6670
return {
71+
deps: importedFiles,
6772
headers,
6873
links,
6974
componentFilePath,

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ export interface Page extends PageData {
9191
*/
9292
content: string
9393

94-
/**
95-
* Links of the page
96-
*/
97-
links: MarkdownLink[]
98-
9994
/**
10095
* Slug of the page
10196
*/
@@ -107,6 +102,16 @@ export interface Page extends PageData {
107102
* @example '2020-09-09'
108103
*/
109104
date: string
105+
106+
/**
107+
* Dependencies of the page
108+
*/
109+
deps: string[]
110+
111+
/**
112+
* Links of the page
113+
*/
114+
links: MarkdownLink[]
110115
}
111116

112117
/**

0 commit comments

Comments
 (0)