mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
feat: init
This commit is contained in:
3
packages/markdown-loader/src/index.ts
Normal file
3
packages/markdown-loader/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { webpackLoader } from './loader';
|
||||
|
||||
export default webpackLoader;
|
||||
27
packages/markdown-loader/src/loader.ts
Normal file
27
packages/markdown-loader/src/loader.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as webpack from 'webpack';
|
||||
import fm from 'front-matter';
|
||||
|
||||
function webpackLoader(
|
||||
this: webpack.LoaderContext<{}>,
|
||||
contents: string = ''
|
||||
) {
|
||||
const callback = this.async();
|
||||
|
||||
const run = async () => {
|
||||
const { attributes, body } = fm(contents);
|
||||
return {
|
||||
attributes,
|
||||
body,
|
||||
};
|
||||
};
|
||||
|
||||
run()
|
||||
.then((content) => {
|
||||
callback(null, `module.exports=${JSON.stringify(content)}`);
|
||||
})
|
||||
.catch((error) => {
|
||||
callback(error);
|
||||
});
|
||||
}
|
||||
|
||||
export { webpackLoader };
|
||||
Reference in New Issue
Block a user