@@ -13,90 +13,90 @@ const devCache = LRU({ max: 1000 })
13
13
module . exports = async function ( src ) {
14
14
const cb = this . async ( )
15
15
try {
16
- /* IMPORTANT: I didn't indent these lines to hopefully get a better looking diff */
16
+ /* IMPORTANT: I didn't indent these lines to hopefully get a better looking diff */
17
17
18
- // explode content of <!-- include --> placeholders
19
- const file = this . resourcePath
20
- const dir = path . dirname ( file )
21
- const { explodedSrc, dependencies } = await mdExplodeIncludes ( { dir, src } )
22
- dependencies . forEach ( d => this . addDependency ( d ) )
18
+ // explode content of <!-- include --> placeholders
19
+ const file = this . resourcePath
20
+ const dir = path . dirname ( file )
21
+ const { explodedSrc, dependencies } = await mdExplodeIncludes ( { dir, src } )
22
+ dependencies . forEach ( d => this . addDependency ( d ) )
23
23
24
- const isProd = process . env . NODE_ENV === 'production'
25
- const isServer = this . target === 'node'
26
- const { markdown, sourceDir } = getOptions ( this )
24
+ const isProd = process . env . NODE_ENV === 'production'
25
+ const isServer = this . target === 'node'
26
+ const { markdown, sourceDir } = getOptions ( this )
27
27
28
- // we implement a manual cache here because this loader is chained before
29
- // vue-loader, and will be applied on the same file multiple times when
30
- // selecting the individual blocks.
31
- const key = hash ( file + explodedSrc )
32
- const cached = cache . get ( key )
33
- if ( cached && ( isProd || / \? v u e / . test ( this . resourceQuery ) ) ) {
34
- return cb ( null , cached )
35
- }
36
-
37
- const frontmatter = parseFrontmatter ( explodedSrc )
38
- const content = frontmatter . content
28
+ // we implement a manual cache here because this loader is chained before
29
+ // vue-loader, and will be applied on the same file multiple times when
30
+ // selecting the individual blocks.
31
+ const key = hash ( file + explodedSrc )
32
+ const cached = cache . get ( key )
33
+ if ( cached && ( isProd || / \? v u e / . test ( this . resourceQuery ) ) ) {
34
+ return cb ( null , cached )
35
+ }
39
36
40
- if ( ! isProd && ! isServer ) {
41
- const inferredTitle = inferTitle ( frontmatter )
42
- const headers = extractHeaders ( content , [ 'h2' , 'h3' ] , markdown )
43
- delete frontmatter . content
37
+ const frontmatter = parseFrontmatter ( explodedSrc )
38
+ const content = frontmatter . content
44
39
45
- // diff frontmatter and title, since they are not going to be part of the
46
- // returned component, changes in frontmatter do not trigger proper updates
47
- const cachedData = devCache . get ( file )
48
- if ( cachedData && (
49
- cachedData . inferredTitle !== inferredTitle ||
50
- JSON . stringify ( cachedData . frontmatter ) !== JSON . stringify ( frontmatter ) ||
51
- headersChanged ( cachedData . headers , headers )
52
- ) ) {
53
- // frontmatter changed... need to do a full reload
54
- module . exports . frontmatterEmitter . emit ( 'update' )
55
- }
40
+ if ( ! isProd && ! isServer ) {
41
+ const inferredTitle = inferTitle ( frontmatter )
42
+ const headers = extractHeaders ( content , [ 'h2' , 'h3' ] , markdown )
43
+ delete frontmatter . content
56
44
57
- devCache . set ( file , {
58
- headers,
59
- frontmatter,
60
- inferredTitle
61
- } )
45
+ // diff frontmatter and title, since they are not going to be part of the
46
+ // returned component, changes in frontmatter do not trigger proper updates
47
+ const cachedData = devCache . get ( file )
48
+ if ( cachedData && (
49
+ cachedData . inferredTitle !== inferredTitle ||
50
+ JSON . stringify ( cachedData . frontmatter ) !== JSON . stringify ( frontmatter ) ||
51
+ headersChanged ( cachedData . headers , headers )
52
+ ) ) {
53
+ // frontmatter changed... need to do a full reload
54
+ module . exports . frontmatterEmitter . emit ( 'update' )
62
55
}
63
56
64
- // the render method has been augmented to allow plugins to
65
- // register data during render
66
- const { html, data : { hoistedTags, links } } = markdown . render ( content )
57
+ devCache . set ( file , {
58
+ headers,
59
+ frontmatter,
60
+ inferredTitle
61
+ } )
62
+ }
63
+
64
+ // the render method has been augmented to allow plugins to
65
+ // register data during render
66
+ const { html, data : { hoistedTags, links } } = markdown . render ( content )
67
67
68
- // check if relative links are valid
69
- links && links . forEach ( link => {
70
- link = decodeURIComponent ( link )
71
- const shortname = link
68
+ // check if relative links are valid
69
+ links && links . forEach ( link => {
70
+ link = decodeURIComponent ( link )
71
+ const shortname = link
72
72
. replace ( / # .* $ / , '' )
73
73
. replace ( / \. h t m l $ / , '.md' )
74
- const filename = shortname
74
+ const filename = shortname
75
75
. replace ( / \/ $ / , '/README.md' )
76
76
. replace ( / ^ \/ / , sourceDir + '/' )
77
- const altname = shortname
77
+ const altname = shortname
78
78
. replace ( / \/ $ / , '/index.md' )
79
79
. replace ( / ^ \/ / , sourceDir + '/' )
80
- const file = path . resolve ( dir , filename )
81
- const altfile = altname !== filename ? path . resolve ( dir , altname ) : null
82
- if ( ! fs . existsSync ( file ) && ( ! altfile || ! fs . existsSync ( altfile ) ) ) {
83
- this . emitWarning (
84
- new Error (
85
- `\nFile for relative link "${ link } " does not exist.\n` +
80
+ const file = path . resolve ( dir , filename )
81
+ const altfile = altname !== filename ? path . resolve ( dir , altname ) : null
82
+ if ( ! fs . existsSync ( file ) && ( ! altfile || ! fs . existsSync ( altfile ) ) ) {
83
+ this . emitWarning (
84
+ new Error (
85
+ `\nFile for relative link "${ link } " does not exist.\n` +
86
86
`(Resolved file: ${ file } )\n`
87
- )
88
87
)
89
- }
90
- } )
88
+ )
89
+ }
90
+ } )
91
91
92
- const res = (
93
- `<template>\n` +
92
+ const res = (
93
+ `<template>\n` +
94
94
`<div class="content">${ html } </div>\n` +
95
95
`</template>\n` +
96
96
( hoistedTags || [ ] ) . join ( '\n' )
97
- )
98
- cache . set ( key , res )
99
- return cb ( null , res )
97
+ )
98
+ cache . set ( key , res )
99
+ return cb ( null , res )
100
100
} catch ( e ) {
101
101
return cb ( e )
102
102
}
0 commit comments