@@ -8,36 +8,48 @@ import Wrapper from '../wrapper'
8
8
import Theme from '../index'
9
9
import SEO from './Seo'
10
10
11
- const Route = ( { children, entry, ...defaultProps } ) => {
11
+ const Route = ( { children, entry, isTransclusion , ...defaultProps } ) => {
12
12
const components = useComponents ( )
13
13
const NotFound = components . notFound
14
14
const Layout = components . layout
15
15
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 >
19
21
< Layout { ...props } > { children } </ Layout >
20
22
</ Wrapper >
21
23
)
22
24
}
23
25
24
26
const findEntry = ( db , ctx ) => {
25
- const isIndex = ctx . frontmatter && ctx . frontmatter . route === '/'
27
+ const isIndex = ctx && ctx . frontmatter && ctx . frontmatter . route === '/'
26
28
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 )
28
30
const filepath = get ( 'entry.filepath' , ctx )
29
31
return db . entries . find ( propEq ( 'value.filepath' , filepath ) )
30
32
}
31
33
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
+
32
43
const Layout = ( { children, ...defaultProps } ) => {
33
44
const { pageContext : ctx } = defaultProps
34
45
const db = useDbQuery ( )
35
46
const entry = findEntry ( db , ctx )
47
+ const isTransclusion = includesTransclusion ( db , defaultProps )
36
48
return (
37
49
< Fragment >
38
50
{ entry && < SEO title = { entry . value . name } /> }
39
51
< Theme db = { db } currentEntry = { entry } >
40
- < Route { ...defaultProps } entry = { entry } >
52
+ < Route { ...defaultProps } entry = { entry } isTransclusion = { isTransclusion } >
41
53
{ children }
42
54
</ Route >
43
55
</ Theme >
0 commit comments