strapi-layout-plugin 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/controllers/layout.js +276 -271
- package/server/register.js +30 -0
- package/server/routes/index.js +2 -1
- package/server/templates/page/controller.js +9 -0
- package/server/templates/page/route.js +9 -0
- package/server/templates/page/schema.json +54 -0
- package/server/templates/page/service.js +9 -0
package/package.json
CHANGED
|
@@ -1,292 +1,297 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const getComponentPopulate = (strapi, componentUid, depth = 0) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
if (depth > 2) return '*';
|
|
5
|
+
const component = strapi.components[componentUid];
|
|
6
|
+
if (!component) return '*';
|
|
7
|
+
|
|
8
|
+
const populate = {};
|
|
9
|
+
const attributes = component.attributes || {};
|
|
10
|
+
|
|
11
|
+
for (const [attrName, attrDef] of Object.entries(attributes)) {
|
|
12
|
+
const type = attrDef.type;
|
|
13
|
+
if (type === 'media') {
|
|
14
|
+
populate[attrName] = true;
|
|
15
|
+
} else if (type === 'component') {
|
|
16
|
+
const targetComp = attrDef.component;
|
|
17
|
+
populate[attrName] = {
|
|
18
|
+
populate: getComponentPopulate(strapi, targetComp, depth + 1)
|
|
19
|
+
};
|
|
20
|
+
} else if (type === 'relation') {
|
|
21
|
+
populate[attrName] = { populate: '*' };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return Object.keys(populate).length > 0 ? populate : '*';
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const getDynamicSectionsPopulate = (strapi) => {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const populate = {};
|
|
29
|
+
const components = strapi.components;
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
for (const [uid, schema] of Object.entries(components)) {
|
|
32
|
+
if (uid.startsWith('velox.')) {
|
|
33
|
+
const attributes = schema.attributes || {};
|
|
34
|
+
const populateMap = {};
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
for (const [attrName, attrDef] of Object.entries(attributes)) {
|
|
37
|
+
const type = attrDef.type;
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
39
|
+
if (type === 'media') {
|
|
40
|
+
populateMap[attrName] = true;
|
|
41
|
+
} else if (type === 'component') {
|
|
42
|
+
const targetComp = attrDef.component;
|
|
43
|
+
populateMap[attrName] = {
|
|
44
|
+
populate: getComponentPopulate(strapi, targetComp)
|
|
45
|
+
};
|
|
46
|
+
} else if (type === 'dynamiczone') {
|
|
47
|
+
populateMap[attrName] = { populate: '*' };
|
|
48
|
+
} else if (type === 'relation' && attrDef.target) {
|
|
49
|
+
const targetUid = attrDef.target;
|
|
50
|
+
const targetModel = strapi.contentTypes[targetUid];
|
|
51
|
+
|
|
52
|
+
if (targetModel) {
|
|
53
|
+
const targetAttributes = targetModel.attributes || {};
|
|
54
|
+
const targetPopulate = {};
|
|
55
|
+
let hasComplexFields = false;
|
|
56
|
+
|
|
57
|
+
for (const [targetAttrName, targetAttrDef] of Object.entries(targetAttributes)) {
|
|
58
|
+
if (targetAttrDef.type === 'component') {
|
|
59
|
+
const targetComp = targetAttrDef.component;
|
|
60
|
+
targetPopulate[targetAttrName] = {
|
|
61
|
+
populate: getComponentPopulate(strapi, targetComp)
|
|
62
|
+
};
|
|
63
|
+
hasComplexFields = true;
|
|
64
|
+
} else if (targetAttrDef.type === 'dynamiczone') {
|
|
65
|
+
targetPopulate[targetAttrName] = { populate: '*' };
|
|
66
|
+
hasComplexFields = true;
|
|
67
|
+
} else if (targetAttrDef.type === 'media') {
|
|
68
|
+
targetPopulate[targetAttrName] = true;
|
|
69
|
+
hasComplexFields = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (hasComplexFields) {
|
|
74
|
+
populateMap[attrName] = { populate: targetPopulate };
|
|
75
|
+
} else {
|
|
76
|
+
populateMap[attrName] = { populate: '*' };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (Object.keys(populateMap).length > 0) {
|
|
83
|
+
populate[uid] = { populate: populateMap };
|
|
84
|
+
} else {
|
|
85
|
+
populate[uid] = { populate: '*' };
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (Object.keys(populateMap).length > 0) {
|
|
83
|
-
populate[uid] = { populate: populateMap };
|
|
84
|
-
} else {
|
|
85
|
-
populate[uid] = { populate: '*' };
|
|
86
|
-
}
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
-
return populate;
|
|
89
|
+
return populate;
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
module.exports = ({ strapi }) => ({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
93
|
+
async getLayout(ctx) {
|
|
94
|
+
const { slug } = ctx.params;
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const requestedLocale = ctx.query.locale || 'en';
|
|
98
|
+
let availableLocales = [];
|
|
99
|
+
try {
|
|
100
|
+
if (strapi.plugin('i18n')) {
|
|
101
|
+
availableLocales = await strapi.plugin('i18n').service('locales').find();
|
|
102
|
+
}
|
|
103
|
+
} catch (e) {
|
|
104
|
+
console.warn('Layout Plugin: Could not fetch locales', e);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log('Layout Plugin: Processing slug:', slug);
|
|
108
|
+
|
|
109
|
+
let slugVariations = [
|
|
110
|
+
slug,
|
|
111
|
+
slug.startsWith('/') ? slug.substring(1) : `/${slug}`,
|
|
112
|
+
slug.endsWith('/') ? slug.slice(0, -1) : slug
|
|
113
|
+
].filter(Boolean);
|
|
114
|
+
|
|
115
|
+
let page = null;
|
|
116
|
+
const pageModel = strapi.contentTypes['api::page.page'];
|
|
117
|
+
const pagePopulate = {
|
|
118
|
+
sections: {
|
|
119
|
+
on: getDynamicSectionsPopulate(strapi)
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
if (pageModel && pageModel.attributes && pageModel.attributes.seo) {
|
|
123
|
+
pagePopulate.seo = { populate: '*' };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const pages = await strapi.entityService.findMany('api::page.page', {
|
|
127
|
+
locale: requestedLocale,
|
|
128
|
+
filters: {
|
|
129
|
+
slug: {
|
|
130
|
+
$in: slugVariations
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
populate: pagePopulate,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (pages && pages.length > 0) {
|
|
137
|
+
page = pages[0];
|
|
121
138
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (!allowedContentType) {
|
|
176
|
-
for (const [uid, ct] of Object.entries(strapi.contentTypes)) {
|
|
177
|
-
if (!uid.startsWith('api::')) continue;
|
|
178
|
-
const info = ct.info || {};
|
|
179
|
-
if (info.pluralName === parentSlug || ct.collectionName === parentSlug || info.singularName === parentSlug) {
|
|
180
|
-
allowedContentType = uid;
|
|
181
|
-
break;
|
|
139
|
+
|
|
140
|
+
if (!page) {
|
|
141
|
+
let childSlug = slug;
|
|
142
|
+
let parentSlug = '';
|
|
143
|
+
|
|
144
|
+
if (slug.includes('/')) {
|
|
145
|
+
const parts = slug.split('/');
|
|
146
|
+
childSlug = parts.pop();
|
|
147
|
+
parentSlug = parts.join('/');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let allowedContentType = null;
|
|
151
|
+
|
|
152
|
+
if (parentSlug) {
|
|
153
|
+
const parentPage = await strapi.entityService.findMany('api::page.page', {
|
|
154
|
+
filters: { slug: parentSlug },
|
|
155
|
+
limit: 1,
|
|
156
|
+
populate: { sections: true }
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
if (parentPage && parentPage.length > 0) {
|
|
160
|
+
const p = parentPage[0];
|
|
161
|
+
if (p.relatedContentType) {
|
|
162
|
+
allowedContentType = p.relatedContentType;
|
|
163
|
+
} else if (p.sections && Array.isArray(p.sections)) {
|
|
164
|
+
for (const section of p.sections) {
|
|
165
|
+
const compName = section.__component;
|
|
166
|
+
if (compName && compName.endsWith('-list')) {
|
|
167
|
+
const parts = compName.split('.');
|
|
168
|
+
if (parts.length > 1) {
|
|
169
|
+
const featureName = parts[1].replace(/-list$/, '');
|
|
170
|
+
const candidateUid = `api::${featureName}.${featureName}`;
|
|
171
|
+
if (strapi.contentTypes[candidateUid]) {
|
|
172
|
+
allowedContentType = candidateUid;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!allowedContentType) {
|
|
181
|
+
for (const [uid, ct] of Object.entries(strapi.contentTypes)) {
|
|
182
|
+
if (!uid.startsWith('api::')) continue;
|
|
183
|
+
const info = ct.info || {};
|
|
184
|
+
if (info.pluralName === parentSlug || ct.collectionName === parentSlug || info.singularName === parentSlug) {
|
|
185
|
+
allowedContentType = uid;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
182
189
|
}
|
|
183
190
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let routableTypes = [];
|
|
194
|
+
if (allowedContentType) {
|
|
195
|
+
routableTypes = [allowedContentType];
|
|
196
|
+
} else if (parentSlug) {
|
|
197
|
+
routableTypes = [];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for (const uid of routableTypes) {
|
|
201
|
+
if (!strapi.contentTypes[uid]) continue;
|
|
202
|
+
|
|
203
|
+
const entities = await strapi.entityService.findMany(uid, {
|
|
204
|
+
locale: requestedLocale,
|
|
205
|
+
filters: { slug: childSlug },
|
|
206
|
+
populate: (function () {
|
|
207
|
+
const model = strapi.contentTypes[uid];
|
|
208
|
+
const attributes = model?.attributes || {};
|
|
209
|
+
const populate = {};
|
|
210
|
+
const candidates = ['section', 'sections', 'seo', 'image', 'banner', 'blocks'];
|
|
211
|
+
for (const candidate of candidates) {
|
|
212
|
+
if (attributes[candidate]) {
|
|
213
|
+
if (attributes[candidate].type === 'dynamiczone' || attributes[candidate].type === 'component') {
|
|
214
|
+
populate[candidate] = { populate: '*' };
|
|
215
|
+
} else if (attributes[candidate].type === 'media') {
|
|
216
|
+
populate[candidate] = true;
|
|
217
|
+
} else if (attributes[candidate].type === 'relation') {
|
|
218
|
+
populate[candidate] = { populate: '*' };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return populate;
|
|
223
|
+
})()
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
if (entities && entities.length > 0) {
|
|
227
|
+
const entity = entities[0];
|
|
228
|
+
const typeName = uid.split('.')[1];
|
|
229
|
+
|
|
230
|
+
let pageSections = [];
|
|
231
|
+
if (Array.isArray(entity.section)) {
|
|
232
|
+
pageSections = entity.section;
|
|
233
|
+
} else if (Array.isArray(entity.sections)) {
|
|
234
|
+
pageSections = entity.sections;
|
|
235
|
+
} else if (Array.isArray(entity.blocks)) {
|
|
236
|
+
pageSections = entity.blocks;
|
|
237
|
+
} else {
|
|
238
|
+
pageSections = [{
|
|
239
|
+
__component: `velox.${typeName}-detail`,
|
|
240
|
+
id: 0,
|
|
241
|
+
...entity
|
|
242
|
+
}];
|
|
215
243
|
}
|
|
244
|
+
|
|
245
|
+
page = {
|
|
246
|
+
id: `${typeName}-${entity.id}`,
|
|
247
|
+
title: entity.title || entity.name || 'Untitled',
|
|
248
|
+
slug: slug,
|
|
249
|
+
sections: pageSections
|
|
250
|
+
};
|
|
251
|
+
break;
|
|
216
252
|
}
|
|
217
|
-
|
|
218
|
-
})()
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
if (entities && entities.length > 0) {
|
|
222
|
-
const entity = entities[0];
|
|
223
|
-
const typeName = uid.split('.')[1];
|
|
224
|
-
|
|
225
|
-
let pageSections = [];
|
|
226
|
-
if (Array.isArray(entity.section)) {
|
|
227
|
-
pageSections = entity.section;
|
|
228
|
-
} else if (Array.isArray(entity.sections)) {
|
|
229
|
-
pageSections = entity.sections;
|
|
230
|
-
} else if (Array.isArray(entity.blocks)) {
|
|
231
|
-
pageSections = entity.blocks;
|
|
232
|
-
} else {
|
|
233
|
-
pageSections = [{
|
|
234
|
-
__component: `velox.${typeName}-detail`,
|
|
235
|
-
id: 0,
|
|
236
|
-
...entity
|
|
237
|
-
}];
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
page = {
|
|
241
|
-
id: `${typeName}-${entity.id}`,
|
|
242
|
-
title: entity.title || entity.name || 'Untitled',
|
|
243
|
-
slug: slug,
|
|
244
|
-
sections: pageSections
|
|
245
|
-
};
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (!page) {
|
|
252
|
-
return ctx.notFound('Page/Article not found');
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const globalLayout = await strapi.entityService.findMany('api::layout.layout', {
|
|
256
|
-
locale: requestedLocale,
|
|
257
|
-
populate: {
|
|
258
|
-
defaultSeo: { populate: '*' },
|
|
259
|
-
header: { on: getDynamicSectionsPopulate(strapi) },
|
|
260
|
-
footer: { on: getDynamicSectionsPopulate(strapi) }
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
const siteName = globalLayout?.siteName || "Velox";
|
|
265
|
-
const language = page.locale || requestedLocale;
|
|
266
|
-
const { sections } = page;
|
|
267
|
-
|
|
268
|
-
ctx.body = {
|
|
269
|
-
strapi: {
|
|
270
|
-
context: {
|
|
271
|
-
pageEditing: false,
|
|
272
|
-
site: { name: siteName },
|
|
273
|
-
language: language,
|
|
274
|
-
locales: availableLocales
|
|
275
|
-
},
|
|
276
|
-
route: {
|
|
277
|
-
name: slug,
|
|
278
|
-
displayName: page.title,
|
|
279
|
-
placeholders: {
|
|
280
|
-
header: globalLayout?.header || [],
|
|
281
|
-
main: sections || [],
|
|
282
|
-
footer: globalLayout?.footer || []
|
|
253
|
+
}
|
|
283
254
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
255
|
+
|
|
256
|
+
if (!page) {
|
|
257
|
+
return ctx.notFound('Page/Article not found');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const globalLayout = await strapi.entityService.findMany('api::layout.layout', {
|
|
261
|
+
locale: requestedLocale,
|
|
262
|
+
populate: {
|
|
263
|
+
defaultSeo: { populate: '*' },
|
|
264
|
+
header: { on: getDynamicSectionsPopulate(strapi) },
|
|
265
|
+
footer: { on: getDynamicSectionsPopulate(strapi) }
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const siteName = globalLayout?.siteName || "Velox";
|
|
270
|
+
const language = page.locale || requestedLocale;
|
|
271
|
+
const { sections } = page;
|
|
272
|
+
|
|
273
|
+
ctx.body = {
|
|
274
|
+
strapi: {
|
|
275
|
+
context: {
|
|
276
|
+
pageEditing: false,
|
|
277
|
+
site: { name: siteName },
|
|
278
|
+
language: language,
|
|
279
|
+
locales: availableLocales
|
|
280
|
+
},
|
|
281
|
+
route: {
|
|
282
|
+
name: slug,
|
|
283
|
+
displayName: page.title,
|
|
284
|
+
placeholders: {
|
|
285
|
+
header: globalLayout?.header || [],
|
|
286
|
+
main: sections || [],
|
|
287
|
+
footer: globalLayout?.footer || []
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
} catch (err) {
|
|
293
|
+
console.error('Layout Plugin Error:', err);
|
|
294
|
+
return ctx.internalServerError('Internal Server Error', err);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
292
297
|
});
|
package/server/register.js
CHANGED
|
@@ -62,6 +62,36 @@ module.exports = ({ strapi }) => {
|
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
+
// 3. Scaffold Page API if it doesn't exist
|
|
66
|
+
const apiPageDir = path.join(strapi.dirs.app.src, 'api', 'page');
|
|
67
|
+
const apiPageContentTypesDir = path.join(apiPageDir, 'content-types', 'page');
|
|
68
|
+
const apiPageRoutesDir = path.join(apiPageDir, 'routes');
|
|
69
|
+
const apiPageControllersDir = path.join(apiPageDir, 'controllers');
|
|
70
|
+
const apiPageServicesDir = path.join(apiPageDir, 'services');
|
|
71
|
+
|
|
72
|
+
if (!fs.existsSync(apiPageDir)) {
|
|
73
|
+
fs.mkdirSync(apiPageContentTypesDir, { recursive: true });
|
|
74
|
+
fs.mkdirSync(apiPageRoutesDir, { recursive: true });
|
|
75
|
+
fs.mkdirSync(apiPageControllersDir, { recursive: true });
|
|
76
|
+
fs.mkdirSync(apiPageServicesDir, { recursive: true });
|
|
77
|
+
|
|
78
|
+
const templatesDir = path.join(__dirname, 'templates', 'page');
|
|
79
|
+
|
|
80
|
+
const pageFilesToCopy = [
|
|
81
|
+
{ src: path.join(templatesDir, 'schema.json'), dest: path.join(apiPageContentTypesDir, 'schema.json') },
|
|
82
|
+
{ src: path.join(templatesDir, 'route.js'), dest: path.join(apiPageRoutesDir, 'page.js') },
|
|
83
|
+
{ src: path.join(templatesDir, 'controller.js'), dest: path.join(apiPageControllersDir, 'page.js') },
|
|
84
|
+
{ src: path.join(templatesDir, 'service.js'), dest: path.join(apiPageServicesDir, 'page.js') }
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
pageFilesToCopy.forEach(({ src, dest }) => {
|
|
88
|
+
if (!fs.existsSync(dest) && fs.existsSync(src)) {
|
|
89
|
+
fs.copyFileSync(src, dest);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
strapi.log.info('[strapi-layout-plugin] Scaffolded base page API.');
|
|
93
|
+
}
|
|
94
|
+
|
|
65
95
|
strapi.log.info('[strapi-layout-plugin] Injected and seeded layout components during register phase.');
|
|
66
96
|
} catch (error) {
|
|
67
97
|
strapi.log.error('[strapi-layout-plugin] Failed to auto-seed components:', error);
|
package/server/routes/index.js
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "collectionType",
|
|
3
|
+
"collectionName": "pages",
|
|
4
|
+
"info": {
|
|
5
|
+
"singularName": "page",
|
|
6
|
+
"pluralName": "pages",
|
|
7
|
+
"displayName": "Page",
|
|
8
|
+
"description": "Generic page for Layout Service"
|
|
9
|
+
},
|
|
10
|
+
"options": {
|
|
11
|
+
"draftAndPublish": true
|
|
12
|
+
},
|
|
13
|
+
"pluginOptions": {
|
|
14
|
+
"i18n": {
|
|
15
|
+
"localized": true
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"attributes": {
|
|
19
|
+
"slug": {
|
|
20
|
+
"type": "uid",
|
|
21
|
+
"targetField": "title",
|
|
22
|
+
"required": true
|
|
23
|
+
},
|
|
24
|
+
"title": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"required": true
|
|
27
|
+
},
|
|
28
|
+
"seo": {
|
|
29
|
+
"type": "component",
|
|
30
|
+
"component": "shared.seo",
|
|
31
|
+
"repeatable": false
|
|
32
|
+
},
|
|
33
|
+
"template": {
|
|
34
|
+
"type": "enumeration",
|
|
35
|
+
"default": "default",
|
|
36
|
+
"enum": [
|
|
37
|
+
"default",
|
|
38
|
+
"sidebar-left"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"sections": {
|
|
42
|
+
"type": "dynamiczone",
|
|
43
|
+
"pluginOptions": {
|
|
44
|
+
"i18n": {
|
|
45
|
+
"localized": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"components": []
|
|
49
|
+
},
|
|
50
|
+
"relatedContentType": {
|
|
51
|
+
"type": "string"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|