@@ -2,9 +2,14 @@ const { dirname } = require('path')
22const _ = require ( 'lodash' )
33const Dictionary = require ( '../../../dictionary' )
44const { last } = require ( '../../../helpers' )
5- const contentTypes = require ( './contentTypes' )
65const { createLocalAsset } = require ( '../models/localAsset' )
76
7+ const {
8+ createCollectionHome,
9+ createFolderedCollectionHome,
10+ createFolderedCollectionHomeIndex
11+ } = require ( './models/collectionHome' )
12+
813const {
914 createCategory,
1015 createCategoryIndex
@@ -31,6 +36,14 @@ const isTemplateFile = (fsObject) => {
3136 return new RegExp ( templateExtensions . join ( '|' ) , 'i' ) . test ( fsObject . extension )
3237}
3338
39+ const isCollectionHomeFile = ( fsObject ) => {
40+ return isTemplateFile ( fsObject ) && fsObject . name . match ( / ^ ( i n d e x | h o m e | c o l l e c t i o n ) \. .+ $ / )
41+ }
42+
43+ const isCollectionHomeDirectory = ( fsObject ) => {
44+ return fsObject . name . match ( `^(index|home|collection)$` )
45+ }
46+
3447const isFolderedPostIndexFile = ( fsObject ) => {
3548 return isTemplateFile ( fsObject ) && fsObject . name . match ( / ^ p o s t \. .+ $ / )
3649}
@@ -85,6 +98,39 @@ const upsertEntry = ({
8598 }
8699}
87100
101+ const withCollectionHome = ( contentModel , fsObject ) => {
102+ return newEntry ( {
103+ contentModel,
104+ key : 'index' ,
105+ entryFn : ( ) => createCollectionHome ( fsObject ) . data ,
106+ replace : true
107+ } )
108+ }
109+
110+ const withFolderedCollectionHome = ( contentModel , fsObject ) => {
111+ return newEntry ( {
112+ contentModel,
113+ key : 'index' ,
114+ entryFn : ( ) => {
115+ return createFolderedCollectionHome ( {
116+ ...fsObject ,
117+ children : fsObject . children . map ( mapFolderedCollectionHomeTree )
118+ } ) . data
119+ } ,
120+ replace : true
121+ } )
122+ }
123+
124+ const mapFolderedCollectionHomeTree = ( fsObject ) => {
125+ if ( isCollectionHomeFile ( fsObject ) ) {
126+ return createFolderedCollectionHomeIndex ( fsObject )
127+ }
128+ return createLocalAsset ( {
129+ ...fsObject ,
130+ isFolder : ! ! fsObject . children
131+ } )
132+ }
133+
88134const withLocalAsset = ( contentModel , fsObject ) => {
89135 return newEntry ( {
90136 contentModel,
@@ -190,6 +236,9 @@ const mapCategoryTree = (fsObject) => {
190236
191237const mapCollectionTree = ( fsTree ) => {
192238 return fsTree . reduce ( ( contentModel , fsObject ) => {
239+ if ( isCollectionHomeFile ( fsObject ) ) {
240+ return withCollectionHome ( contentModel , fsObject )
241+ }
193242 if ( isTemplateFile ( fsObject ) ) {
194243 return withDefaultCategory (
195244 withDefaultCategoryPost ( contentModel , fsObject ) ,
@@ -199,6 +248,9 @@ const mapCollectionTree = (fsTree) => {
199248 if ( ! fsObject . children ) {
200249 return withLocalAsset ( contentModel , fsObject )
201250 }
251+ if ( isCollectionHomeDirectory ( fsObject ) ) {
252+ return withFolderedCollectionHome ( contentModel , fsObject )
253+ }
202254 if ( fsObject . children . some ( isFolderedPostIndexFile ) ) {
203255 return withDefaultCategory (
204256 withFolderedPost ( contentModel , fsObject ) ,
@@ -207,6 +259,7 @@ const mapCollectionTree = (fsTree) => {
207259 }
208260 return withCategory ( contentModel , fsObject )
209261 } , {
262+ index : createCollectionHome ( { } ) . data ,
210263 categories : [ ] ,
211264 posts : [ ] ,
212265 localAssets : [ ] ,
0 commit comments