diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2021-07-19 21:08:50 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2021-07-19 21:08:50 -0500 |
commit | f1f25f4764dd8d297a59765b0df85f55da2b39ee (patch) | |
tree | 9c10f3fcde264a1b13dccc64b9037f46d9bbc121 /plugins | |
download | homepage-f1f25f4764dd8d297a59765b0df85f55da2b39ee.tar.xz homepage-f1f25f4764dd8d297a59765b0df85f55da2b39ee.zip |
Init
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/index.js | 3 | ||||
-rw-r--r-- | plugins/pluginFactory.js | 16 | ||||
-rw-r--r-- | plugins/withMarkdownLoader.js | 31 |
3 files changed, 50 insertions, 0 deletions
diff --git a/plugins/index.js b/plugins/index.js new file mode 100644 index 0000000..ad4e6d0 --- /dev/null +++ b/plugins/index.js @@ -0,0 +1,3 @@ +const withMarkdownLoader = require('./withMarkdownLoader'); + +module.exports = { withMarkdownLoader };
\ No newline at end of file diff --git a/plugins/pluginFactory.js b/plugins/pluginFactory.js new file mode 100644 index 0000000..385361f --- /dev/null +++ b/plugins/pluginFactory.js @@ -0,0 +1,16 @@ +const pluginFactory = (configure) => (nextConfig = {}) => { + return Object.assign({}, nextConfig, { + webpack(config, options) { + + configure(config, options); + + if(typeof nextConfig.webpack === 'function') { + return nextConfig.webpack(config, options); + } + + return config; + } + }); +} + +module.exports = pluginFactory;
\ No newline at end of file diff --git a/plugins/withMarkdownLoader.js b/plugins/withMarkdownLoader.js new file mode 100644 index 0000000..7dd51b6 --- /dev/null +++ b/plugins/withMarkdownLoader.js @@ -0,0 +1,31 @@ +const hljs = require('highlight.js'); +const pluginFactory = require('./pluginFactory'); + +function highlight(code, lang) { + const language = hljs.getLanguage(lang) ? lang : 'plaintext'; + + const highlighted = hljs.highlight(code, { language }).value; + return highlighted; +} + +const withMarkdownLoader = pluginFactory((config, _options) => { + config.module.rules.push({ + test: /\.md$/, + use: [ + { + loader: 'html-loader', + options: { + esModule: true + } + }, + { + loader: 'markdown-loader', + options: { + highlight + } + } + ] + }); +}); + +module.exports = withMarkdownLoader;
\ No newline at end of file |