Skip to content

Commit 88a7eaf

Browse files
chore: move enhacer to its own util
1 parent eee38eb commit 88a7eaf

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

webpack.common.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const fs = require('fs');
22
const path = require('path');
33
const webpack = require('webpack');
4-
const FrontMatter = require('front-matter');
54
const CleanPlugin = require('clean-webpack-plugin');
65
const CopyWebpackPlugin = require('copy-webpack-plugin');
76
const ExtractTextPlugin = require('extract-text-webpack-plugin');
87
const DirectoryTreePlugin = require('directory-tree-webpack-plugin');
8+
const treePluginEnhacer = require('./src/utils/treePluginEnhacer.js');
99

1010
module.exports = (env = {}) => ({
1111
devtool: 'source-map',
@@ -109,25 +109,7 @@ module.exports = (env = {}) => ({
109109
dir: 'src/content',
110110
path: 'src/_content.json',
111111
extensions: /\.md/,
112-
enhance: (item, options) => {
113-
item.url = item.path
114-
.replace(item.extension, '')
115-
.replace(options.dir, '')
116-
.replace(/\/index$/, '')
117-
.replace(/^$/, '/');
118-
119-
if (item.type === 'file') {
120-
// remove underscore from fetched files
121-
if (item.name[0] === '_') {
122-
item.name = item.name.replace('_', '');
123-
item.url = item.url.replace('_', '');
124-
}
125-
let content = fs.readFileSync(item.path, 'utf8');
126-
let { attributes } = FrontMatter(content);
127-
Object.assign(item, attributes);
128-
item.anchors = []; // TODO: Add actual anchors
129-
}
130-
}
112+
enhance: treePluginEnhacer
131113
})
132114
],
133115
stats: {

0 commit comments

Comments
 (0)