@@ -8,36 +8,48 @@ import Wrapper from '../wrapper'
88import Theme from '../index'
99import 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
2426const 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+
3243const 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