11const { resolve } = require ( 'path' )
2- const _ = require ( 'lodash' )
3- const frontMatter = require ( 'front-matter' )
42const ImmutableStack = require ( '../../lib/ImmutableStack' )
5- const { removeExtension, isTemplateFile } = require ( '../../lib/contentModelHelpers' )
3+ const { removeExtension } = require ( '../../lib/contentModelHelpers' )
64const ContentModelEntryNode = require ( '../../lib/ContentModelEntryNode' )
75const matcha = require ( '../../lib/matcha' )
86
97const models = {
108 Homepage : require ( './models/homepage' ) ,
9+ PagesDirectory : require ( './models/pagesDirectory' ) ,
1110 Subpage : require ( './models/subpage' ) ,
1211 Collection : require ( './models/collection' ) ,
1312 Asset : require ( './models/asset' )
@@ -231,11 +230,11 @@ class ContentModel extends ContentModelEntryNode {
231230 nameOptions : [ this . settings . pagesDirectory , 'subpages' , 'pages' ]
232231 } ) ,
233232
234- asset : matcha . true ( ) ,
235-
236233 assetsDirectory : matcha . directory ( {
237234 nameOptions : [ this . settings . assetsDirectory , 'assets' ]
238- } )
235+ } ) ,
236+
237+ asset : matcha . true ( )
239238 }
240239 }
241240
@@ -246,6 +245,7 @@ class ContentModel extends ContentModelEntryNode {
246245 this . context ,
247246 { homepageDirectory : this . settings . homepageDirectory }
248247 ) ,
248+ pagesDirectory : [ ] ,
249249 subpages : [ ] ,
250250 collections : [ ] ,
251251 assets : [ ]
@@ -272,21 +272,14 @@ class ContentModel extends ContentModelEntryNode {
272272 }
273273
274274 if ( this . matchers . pagesDirectory ( node ) ) {
275- return node . children . forEach ( childNode => {
276- if ( this . matchers . subpage ( childNode ) ) {
277- tree . subpages . push (
278- new models . Subpage ( childNode , this . context , {
279- pagesDirectory : this . settings . pagesDirectory
280- } )
281- )
282- } else if ( this . matchers . asset ( childNode ) ) {
283- tree . assets . push (
284- new models . Asset ( childNode , this . context , {
285- assetsDirectory : this . settings . assetsDirectory
286- } )
287- )
288- }
275+ tree . pagesDirectory = new models . PagesDirectory ( node , this . context , {
276+ pagesDirectory : this . settings . pagesDirectory ,
277+ assetsDirectory : this . settings . assetsDirectory ,
278+ debug : this . settings . debug
289279 } )
280+ tree . subpages . push ( ...tree . pagesDirectory . subtree . subpages )
281+ tree . assets . push ( ...tree . pagesDirectory . subtree . assets )
282+ return
290283 }
291284
292285 if ( this . matchers . collection ( node ) ) {
0 commit comments