@@ -137,23 +137,26 @@ export const hydrateComponents = (components, engines, exclude = []) => {
137
137
const findAndReplaceNested = ( obj , structures , limitRecursion ) => {
138
138
if ( ! obj ) return obj ;
139
139
if ( Array . isArray ( obj ) ) {
140
- if ( typeof obj [ 0 ] === "string" && / ^ b o o k s h o p : s t r u c t u r e : ./ . test ( obj [ 0 ] ) ) {
141
- const structureKey = obj [ 0 ] . replace ( / ^ b o o k s h o p : s t r u c t u r e : / , '' ) ;
142
- return [ randFrom ( structures [ structureKey ] , limitRecursion ) ] ;
143
- }
144
- if ( typeof obj [ 0 ] === "string" && / ^ b o o k s h o p : ./ . test ( obj [ 0 ] ) ) {
145
- const structureKey = `component:${ obj [ 0 ] . replace ( / ^ b o o k s h o p : / , '' ) } ` ;
146
- return [ randFrom ( structures [ structureKey ] , limitRecursion ) ] ;
140
+ for ( let i = 0 ; i < obj . length ; i ++ ) {
141
+ if ( typeof obj [ i ] === "string" && / ^ b o o k s h o p : s t r u c t u r e : ./ . test ( obj [ i ] ) ) {
142
+ const structureKey = obj [ i ] . replace ( / ^ b o o k s h o p : s t r u c t u r e : | ! $ / g, '' ) ;
143
+ obj [ i ] = randFrom ( structures [ structureKey ] , limitRecursion ) ;
144
+ } else if ( typeof obj [ i ] === "string" && / ^ b o o k s h o p : ./ . test ( obj [ i ] ) ) {
145
+ const structureKey = `component:${ obj [ i ] . replace ( / ^ b o o k s h o p : | ! $ / g, '' ) } ` ;
146
+ obj [ i ] = randFrom ( structures [ structureKey ] , limitRecursion ) ;
147
+ } else {
148
+ obj [ i ] = findAndReplaceNested ( obj [ i ] , structures , limitRecursion ) ;
149
+ }
147
150
}
148
- return obj . map ( o => findAndReplaceNested ( o , structures , limitRecursion ) ) ;
151
+ return obj ;
149
152
}
150
153
if ( typeof obj === "object" ) {
151
154
Object . entries ( obj ) . forEach ( ( [ key , val ] ) => {
152
155
if ( typeof val === "string" && / ^ b o o k s h o p : s t r u c t u r e : ./ . test ( val ) ) {
153
- const structureKey = val . replace ( / ^ b o o k s h o p : s t r u c t u r e : / , '' ) ;
156
+ const structureKey = val . replace ( / ^ b o o k s h o p : s t r u c t u r e : | ! $ / g , '' ) ;
154
157
obj [ key ] = randFrom ( structures [ structureKey ] , limitRecursion ) ;
155
158
} else if ( typeof val === "string" && / ^ b o o k s h o p : ./ . test ( val ) ) {
156
- const structureKey = `component:${ val . replace ( / ^ b o o k s h o p : / , '' ) } ` ;
159
+ const structureKey = `component:${ val . replace ( / ^ b o o k s h o p : | ! $ / g , '' ) } ` ;
157
160
obj [ key ] = randFrom ( structures [ structureKey ] , limitRecursion ) ;
158
161
} else {
159
162
obj [ key ] = findAndReplaceNested ( obj [ key ] , structures , limitRecursion ) ;
0 commit comments