From 435001a257a3b8a0565df029b1098384a571abbd Mon Sep 17 00:00:00 2001 From: Mauricio Palma Date: Tue, 31 Mar 2020 09:50:49 +0200 Subject: [PATCH] feat(gatsby-theme-docz): include MDX transclusion support (#1436) --- core/gatsby-theme-docz/src/base/Layout.js | 26 +++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/core/gatsby-theme-docz/src/base/Layout.js b/core/gatsby-theme-docz/src/base/Layout.js index c3faaabb7..59c52605a 100644 --- a/core/gatsby-theme-docz/src/base/Layout.js +++ b/core/gatsby-theme-docz/src/base/Layout.js @@ -8,36 +8,48 @@ import Wrapper from '../wrapper' import Theme from '../index' import SEO from './Seo' -const Route = ({ children, entry, ...defaultProps }) => { +const Route = ({ children, entry, isTransclusion, ...defaultProps }) => { const components = useComponents() const NotFound = components.notFound const Layout = components.layout const props = { ...defaultProps, doc: entry } - if (!entry) return - return ( - + if (!entry && !isTransclusion) return + return isTransclusion ? ( + children + ) : ( + {children} ) } const findEntry = (db, ctx) => { - const isIndex = ctx.frontmatter && ctx.frontmatter.route === '/' + const isIndex = ctx && ctx.frontmatter && ctx.frontmatter.route === '/' const eqIndex = propEq('value.route', '/') - if (!ctx.entry && isIndex) return db.entries.find(eqIndex) + if (ctx && !ctx.entry && isIndex) return db.entries.find(eqIndex) const filepath = get('entry.filepath', ctx) return db.entries.find(propEq('value.filepath', filepath)) } +const includesTransclusion = (db, props) => { + const { entries } = db + const filepath = get('_frontmatter.__filemeta.filename', props) + return ( + !props.pageContext && + entries.includes(entries.find(propEq('value.filepath', filepath))) + ) +} + const Layout = ({ children, ...defaultProps }) => { const { pageContext: ctx } = defaultProps const db = useDbQuery() const entry = findEntry(db, ctx) + const isTransclusion = includesTransclusion(db, defaultProps) return ( {entry && } - + {children}