Skip to content

Commit 63d755e

Browse files
committed
unindent stuff to have better diff
1 parent 04785a8 commit 63d755e

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

lib/webpack/markdownLoader.js

+63-63
Original file line numberDiff line numberDiff line change
@@ -13,90 +13,90 @@ const devCache = LRU({ max: 1000 })
1313
module.exports = async function (src) {
1414
const cb = this.async()
1515
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 */
1717

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))
2323

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)
2727

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 || /\?vue/.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 || /\?vue/.test(this.resourceQuery))) {
34+
return cb(null, cached)
35+
}
3936

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
4439

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
5644

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')
6255
}
6356

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)
6767

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
7272
.replace(/#.*$/, '')
7373
.replace(/\.html$/, '.md')
74-
const filename = shortname
74+
const filename = shortname
7575
.replace(/\/$/, '/README.md')
7676
.replace(/^\//, sourceDir + '/')
77-
const altname = shortname
77+
const altname = shortname
7878
.replace(/\/$/, '/index.md')
7979
.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` +
8686
`(Resolved file: ${file})\n`
87-
)
8887
)
89-
}
90-
})
88+
)
89+
}
90+
})
9191

92-
const res = (
93-
`<template>\n` +
92+
const res = (
93+
`<template>\n` +
9494
`<div class="content">${html}</div>\n` +
9595
`</template>\n` +
9696
(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)
100100
} catch (e) {
101101
return cb(e)
102102
}

0 commit comments

Comments
 (0)