mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 12:13:11 +00:00
Co-authored-by: Dan Abramov <dan.abramov@me.com> Co-authored-by: Sylwia Vargas <sylwia.vargas@gmail.com> Co-authored-by: Dan Lebowitz <dan.lebo@me.com> Co-authored-by: Razvan Gradinar <grazvan@fb.com> Co-authored-by: Jared Palmer <jared@palmer.net> Co-authored-by: Dane Grant <danecando@gmail.com> Co-authored-by: Dustin Goodman <dustin.s.goodman@gmail.com> Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com> Co-authored-by: Maggie Appleton <maggie.fm.appleton@gmail.com> Co-authored-by: Alex Moldovan <alex.n.moldovan@gmail.com> Co-authored-by: Ives van Hoorne <ives.v.h@gmail.com> Co-authored-by: Brian Vaughn <bvaughn@fb.com> Co-authored-by: Dmitri Pavlutin <dpavlutin@gmail.com>
29 lines
929 B
JavaScript
29 lines
929 B
JavaScript
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 || 'Learn';
|
|
const code =
|
|
`import withLayout from 'components/Layout/Layout${layout}';
|
|
|
|
export default withLayout(${JSON.stringify(data)})
|
|
|
|
|
|
` + content;
|
|
|
|
return callback(null, code);
|
|
};
|