Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 435001a

Browse files
authored
feat(gatsby-theme-docz): include MDX transclusion support (#1436)
1 parent 8f071eb commit 435001a

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

core/gatsby-theme-docz/src/base/Layout.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,48 @@ import Wrapper from '../wrapper'
88
import Theme from '../index'
99
import SEO from './Seo'
1010

11-
const Route = ({ children, entry, ...defaultProps }) => {
11+
const Route = ({ children, entry, isTransclusion, ...defaultProps }) => {
1212
const components = useComponents()
1313
const NotFound = components.notFound
1414
const Layout = components.layout
1515
const props = { ...defaultProps, doc: entry }
16-
if (!entry) return <NotFound />
17-
return (
18-
<Wrapper doc={entry}>
16+
if (!entry && !isTransclusion) return <NotFound />
17+
return isTransclusion ? (
18+
children
19+
) : (
20+
<Wrapper>
1921
<Layout {...props}>{children}</Layout>
2022
</Wrapper>
2123
)
2224
}
2325

2426
const findEntry = (db, ctx) => {
25-
const isIndex = ctx.frontmatter && ctx.frontmatter.route === '/'
27+
const isIndex = ctx && ctx.frontmatter && ctx.frontmatter.route === '/'
2628
const eqIndex = propEq('value.route', '/')
27-
if (!ctx.entry && isIndex) return db.entries.find(eqIndex)
29+
if (ctx && !ctx.entry && isIndex) return db.entries.find(eqIndex)
2830
const filepath = get('entry.filepath', ctx)
2931
return db.entries.find(propEq('value.filepath', filepath))
3032
}
3133

34+
const includesTransclusion = (db, props) => {
35+
const { entries } = db
36+
const filepath = get('_frontmatter.__filemeta.filename', props)
37+
return (
38+
!props.pageContext &&
39+
entries.includes(entries.find(propEq('value.filepath', filepath)))
40+
)
41+
}
42+
3243
const Layout = ({ children, ...defaultProps }) => {
3344
const { pageContext: ctx } = defaultProps
3445
const db = useDbQuery()
3546
const entry = findEntry(db, ctx)
47+
const isTransclusion = includesTransclusion(db, defaultProps)
3648
return (
3749
<Fragment>
3850
{entry && <SEO title={entry.value.name} />}
3951
<Theme db={db} currentEntry={entry}>
40-
<Route {...defaultProps} entry={entry}>
52+
<Route {...defaultProps} entry={entry} isTransclusion={isTransclusion}>
4153
{children}
4254
</Route>
4355
</Theme>

0 commit comments

Comments
 (0)