forked from docschina/webpack.js.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage-loader.js
More file actions
31 lines (25 loc) · 1.1 KB
/
page-loader.js
File metadata and controls
31 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const _ = require('lodash');
const frontmatter = require('front-matter');
const loaderUtils = require('loader-utils');
const markdown = require('../src/utilities/markdown');
const highlight = require('../src/utilities/highlight');
module.exports = function (source) {
const result = frontmatter(source);
result.attributes = result.attributes || {};
result.attributes.group = result.attributes.group || '-';
result.attributes.anchors = markdown().getAnchors(result.body);
result.attributes.contributors = (result.attributes.contributors || []).sort();
result.attributes.related = Array.isArray(result.attributes.related) ? result.attributes.related : [];
result.title = result.attributes.title || 'webpack';
result.body = markdown().process(result.body, highlight);
delete result.frontmatter;
const context = this;
return `module.exports = ${JSON.stringify(result)};`.replace(
/__IMG_START__([^,\]]+)__IMG_END__/g, (match, src) => {
if (_.startsWith(src, 'http')) {
return src;
}
return `" + require(${loaderUtils.stringifyRequest(context, src)}) + "`;
}
);
};