Skip to content

Commit 199f99e

Browse files
committed
try unindent lines for diff
1 parent 43c760b commit 199f99e

File tree

1 file changed

+71
-70
lines changed

1 file changed

+71
-70
lines changed

lib/webpack/markdownLoader.js

+71-70
Original file line numberDiff line numberDiff line change
@@ -13,87 +13,88 @@ const devCache = LRU({ max: 1000 })
1313
module.exports = async function (src) {
1414
const cb = this.async()
1515
try {
16-
const file = this.resourcePath
17-
const dir = path.dirname(file)
16+
/* IMPORTANT: I didn't indent these lines to hopefully get a better looking diff
17+
const file = this.resourcePath
18+
const dir = path.dirname(file)
1819

19-
const { explodedSrc, dependencies } = await mdExplodeIncludes({ cwd: dir, src })
20-
dependencies.forEach(d => this.addDependency(d))
20+
const { explodedSrc, dependencies } = await mdExplodeIncludes({ cwd: dir, src })
21+
dependencies.forEach(d => this.addDependency(d))
2122

22-
const isProd = process.env.NODE_ENV === 'production'
23-
const isServer = this.target === 'node'
24-
const { markdown, sourceDir } = getOptions(this)
23+
const isProd = process.env.NODE_ENV === 'production'
24+
const isServer = this.target === 'node'
25+
const { markdown, sourceDir } = getOptions(this)
2526

26-
// we implement a manual cache here because this loader is chained before
27-
// vue-loader, and will be applied on the same file multiple times when
28-
// selecting the individual blocks.
29-
const key = hash(file + explodedSrc)
30-
const cached = cache.get(key)
31-
if (cached && (isProd || /\?vue/.test(this.resourceQuery))) {
32-
return cb(null, cached)
33-
}
34-
35-
const frontmatter = parseFrontmatter(explodedSrc)
36-
const content = frontmatter.content
27+
// we implement a manual cache here because this loader is chained before
28+
// vue-loader, and will be applied on the same file multiple times when
29+
// selecting the individual blocks.
30+
const key = hash(file + explodedSrc)
31+
const cached = cache.get(key)
32+
if (cached && (isProd || /\?vue/.test(this.resourceQuery))) {
33+
return cb(null, cached)
34+
}
3735

38-
if (!isProd && !isServer) {
39-
const inferredTitle = inferTitle(frontmatter)
40-
const headers = extractHeaders(content, ['h2', 'h3'], markdown)
41-
delete frontmatter.content
36+
const frontmatter = parseFrontmatter(explodedSrc)
37+
const content = frontmatter.content
4238

43-
// diff frontmatter and title, since they are not going to be part of the
44-
// returned component, changes in frontmatter do not trigger proper updates
45-
const cachedData = devCache.get(file)
46-
if (cachedData && (
47-
cachedData.inferredTitle !== inferredTitle ||
48-
JSON.stringify(cachedData.frontmatter) !== JSON.stringify(frontmatter) ||
49-
headersChanged(cachedData.headers, headers)
50-
)) {
51-
// frontmatter changed... need to do a full reload
52-
module.exports.frontmatterEmitter.emit('update')
53-
}
39+
if (!isProd && !isServer) {
40+
const inferredTitle = inferTitle(frontmatter)
41+
const headers = extractHeaders(content, ['h2', 'h3'], markdown)
42+
delete frontmatter.content
5443

55-
devCache.set(file, {
56-
headers,
57-
frontmatter,
58-
inferredTitle
59-
})
44+
// diff frontmatter and title, since they are not going to be part of the
45+
// returned component, changes in frontmatter do not trigger proper updates
46+
const cachedData = devCache.get(file)
47+
if (cachedData && (
48+
cachedData.inferredTitle !== inferredTitle ||
49+
JSON.stringify(cachedData.frontmatter) !== JSON.stringify(frontmatter) ||
50+
headersChanged(cachedData.headers, headers)
51+
)) {
52+
// frontmatter changed... need to do a full reload
53+
module.exports.frontmatterEmitter.emit('update')
6054
}
6155

62-
// the render method has been augmented to allow plugins to
63-
// register data during render
64-
const { html, data: { hoistedTags, links }} = markdown.render(content)
56+
devCache.set(file, {
57+
headers,
58+
frontmatter,
59+
inferredTitle
60+
})
61+
}
62+
63+
// the render method has been augmented to allow plugins to
64+
// register data during render
65+
const { html, data: { hoistedTags, links }} = markdown.render(content)
6566

66-
// check if relative links are valid
67-
links && links.forEach(link => {
68-
const shortname = link
69-
.replace(/#.*$/, '')
70-
.replace(/\.html$/, '.md')
71-
const filename = shortname
72-
.replace(/\/$/, '/README.md')
73-
.replace(/^\//, sourceDir + '/')
74-
const altname = shortname
75-
.replace(/\/$/, '/index.md')
76-
.replace(/^\//, sourceDir + '/')
77-
const file = path.resolve(dir, filename)
78-
const altfile = altname !== filename ? path.resolve(dir, altname) : null
79-
if (!fs.existsSync(file) && (!altfile || !fs.existsSync(altfile))) {
80-
this.emitWarning(
81-
new Error(
82-
`\nFile for relative link "${link}" does not exist.\n` +
83-
`(Resolved file: ${file})\n`
84-
)
67+
// check if relative links are valid
68+
links && links.forEach(link => {
69+
const shortname = link
70+
.replace(/#.*$/, '')
71+
.replace(/\.html$/, '.md')
72+
const filename = shortname
73+
.replace(/\/$/, '/README.md')
74+
.replace(/^\//, sourceDir + '/')
75+
const altname = shortname
76+
.replace(/\/$/, '/index.md')
77+
.replace(/^\//, sourceDir + '/')
78+
const file = path.resolve(dir, filename)
79+
const altfile = altname !== filename ? path.resolve(dir, altname) : null
80+
if (!fs.existsSync(file) && (!altfile || !fs.existsSync(altfile))) {
81+
this.emitWarning(
82+
new Error(
83+
`\nFile for relative link "${link}" does not exist.\n` +
84+
`(Resolved file: ${file})\n`
8585
)
86-
}
87-
})
86+
)
87+
}
88+
})
8889

89-
const res = (
90-
`<template>\n` +
91-
`<div class="content">${html}</div>\n` +
92-
`</template>\n` +
93-
(hoistedTags || []).join('\n')
94-
)
95-
cache.set(key, res)
96-
return cb(null, res)
90+
const res = (
91+
`<template>\n` +
92+
`<div class="content">${html}</div>\n` +
93+
`</template>\n` +
94+
(hoistedTags || []).join('\n')
95+
)
96+
cache.set(key, res)
97+
return cb(null, res)
9798
} catch (e) {
9899
return cb(e)
99100
}

0 commit comments

Comments
 (0)