6
6
7
7
const { EventEmitter } = require ( 'events' )
8
8
const { getOptions } = require ( 'loader-utils' )
9
- const { fs, path, hash , parseFrontmatter, inferTitle, extractHeaders } = require ( '@vuepress/shared-utils' )
9
+ const { fs, path, parseFrontmatter, inferTitle, extractHeaders } = require ( '@vuepress/shared-utils' )
10
10
const LRU = require ( 'lru-cache' )
11
11
const md = require ( '@vuepress/markdown' )
12
12
13
- const cache = new LRU ( { max : 1000 } )
14
13
const devCache = new LRU ( { max : 1000 } )
15
14
16
15
/**
@@ -32,26 +31,18 @@ module.exports = function (src) {
32
31
// vue-loader, and will be applied on the same file multiple times when
33
32
// selecting the individual blocks.
34
33
const file = this . resourcePath
35
- const key = hash ( file + src )
36
- const cached = cache . get ( key )
37
- if ( cached && ( isProd || / \? v u e / . test ( this . resourceQuery ) ) ) {
38
- return cached
39
- }
40
-
41
- const frontmatter = parseFrontmatter ( src )
42
- const content = frontmatter . content
34
+ const { content, data } = parseFrontmatter ( src )
43
35
44
36
if ( ! isProd && ! isServer ) {
45
- const inferredTitle = inferTitle ( frontmatter . data , frontmatter . content )
37
+ const inferredTitle = inferTitle ( data , content )
46
38
const headers = extractHeaders ( content , [ 'h2' , 'h3' ] , markdown )
47
- delete frontmatter . content
48
39
49
40
// diff frontmatter and title, since they are not going to be part of the
50
41
// returned component, changes in frontmatter do not trigger proper updates
51
42
const cachedData = devCache . get ( file )
52
43
if ( cachedData && (
53
44
cachedData . inferredTitle !== inferredTitle
54
- || JSON . stringify ( cachedData . frontmatterData ) !== JSON . stringify ( frontmatter . data )
45
+ || JSON . stringify ( cachedData . frontmatterData ) !== JSON . stringify ( data )
55
46
|| headersChanged ( cachedData . headers , headers )
56
47
) ) {
57
48
// frontmatter changed... need to do a full reload
@@ -60,7 +51,7 @@ module.exports = function (src) {
60
51
61
52
devCache . set ( file , {
62
53
headers,
63
- frontmatterData : frontmatter . data ,
54
+ frontmatterData : data ,
64
55
inferredTitle
65
56
} )
66
57
}
@@ -73,7 +64,7 @@ module.exports = function (src) {
73
64
dataBlockString
74
65
} = markdown . render ( content , {
75
66
loader,
76
- frontmatter : frontmatter . data ,
67
+ frontmatter : data ,
77
68
relPath : path . relative ( sourceDir , file )
78
69
} )
79
70
@@ -114,7 +105,6 @@ module.exports = function (src) {
114
105
+ ( hoistedTags || [ ] ) . join ( '\n' )
115
106
+ `\n${ dataBlockString } \n`
116
107
)
117
- cache . set ( key , res )
118
108
return res
119
109
}
120
110
0 commit comments