From a26bba14c67706c1bb54b768d59111201ac97b68 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Wed, 18 Oct 2017 10:20:13 -0700 Subject: [PATCH] Add the ability to provide custom layout (#128) * Add the ability to provide custom layout When I designed the system, I added the ability to provide a custom layout that would use arbitrary JavaScript to render some custom pages. This is why files are called "DocsLayout.js", "BlogPostLayout.js"... This ability to customize it was [ripped out](https://github.com/facebook/react-native/blob/master/website/server/convert.js#L78) during the migration to Docusaurus but I need it for the project I'm working on right now (that should remain unnamed!). This adds back the ability to do it in a way that fits the third party system. In order to provide a new layout: 1) Add a `layout` field in the header of your markdown file: ```js --- layout: mylayout --- ``` 2) In your `siteConfig`, add ```js layouts: { mylayout: function({React, Marked}) { return class extends React.Component { render() { return React.createElement('div', {}, this.props.metadata.layout); } } } } ``` I think that it's a reasonable to add and would unblock me :) * Update DocsLayout.js --- lib/core/DocsLayout.js | 7 ++++++- lib/server/server.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/core/DocsLayout.js b/lib/core/DocsLayout.js index 30f11410aeeb..9edd745a37cc 100644 --- a/lib/core/DocsLayout.js +++ b/lib/core/DocsLayout.js @@ -18,6 +18,10 @@ class DocsLayout extends React.Component { const metadata = this.props.metadata; const content = this.props.children; const i18n = translation[this.props.metadata.language]; + let DocComponent = Doc; + if (this.props.Doc) { + DocComponent = this.props.Doc; + } return ( - + {rawContent} );