You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
const fm = require('gray-matter');
|
|
|
|
|
|
|
|
// Makes mdx in next.js suck less by injecting necessary exports so that
|
|
|
|
// the docs are still readable on github.
|
|
|
|
//
|
|
|
|
// Layout component for a .mdx or .md page can be specfied in the frontmatter.
|
|
|
|
// This plugin assumes that the layout file and named export are the same. This
|
|
|
|
// easily changed by modifying the string below.
|
|
|
|
//
|
|
|
|
// All metadata can be written in yaml front matter. It will be passed to the
|
|
|
|
// layout component as `meta` prop.
|
|
|
|
//
|
|
|
|
// (Shamelessly stolen from Expo.io docs)
|
|
|
|
// @see https://github.com/expo/expo/blob/master/docs/common/md-loader.js
|
|
|
|
module.exports = async function (src) {
|
|
|
|
const callback = this.async();
|
|
|
|
const {content, data} = fm(src);
|
|
|
|
const layout = data.layout || 'Home';
|
|
|
|
const code =
|
|
|
|
`import withLayout from 'components/Layout/Layout${layout}';
|
|
|
|
|
|
|
|
export default withLayout(${JSON.stringify(data)})
|
|
|
|
|
|
|
|
|
|
|
|
` + content;
|
|
|
|
|
|
|
|
return callback(null, code);
|
|
|
|
};
|