@forgewp/compiler 0.1.8 → 0.2.0
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/bin/add.js +19 -1
- package/bin/cli.js +10 -0
- package/bin/fresh.js +476 -0
- package/bin/repair.js +7 -0
- package/bin/sync-routes.js +260 -0
- package/lib/add-component.js +15 -3
- package/lib/blueprints.js +501 -497
- package/lib/generate-theme.js +359 -12
- package/lib/render-static.js +4 -0
- package/lib/render-theme.mts +32 -0
- package/package.json +2 -2
package/lib/blueprints.js
CHANGED
|
@@ -1,497 +1,501 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* System File Blueprints — ForgeWP Compiler
|
|
3
|
-
*
|
|
4
|
-
* These are fallback templates used by the compiler's self-healing preflight check.
|
|
5
|
-
* If a developer accidentally deletes a system-critical library file,
|
|
6
|
-
* the compiler will automatically recreate it to prevent compilation and runtime errors.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const SYSTEM_BLUEPRINTS = {
|
|
10
|
-
"wordpress/
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
121
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
export function
|
|
194
|
-
if (IS_DEV)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
|
|
346
|
-
/** Open Graph
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
{
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
{
|
|
406
|
-
<meta
|
|
407
|
-
<
|
|
408
|
-
|
|
409
|
-
{
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
<meta
|
|
413
|
-
<meta
|
|
414
|
-
|
|
415
|
-
{
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
--
|
|
449
|
-
--
|
|
450
|
-
--
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
\${
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
--
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
--
|
|
484
|
-
--
|
|
485
|
-
--
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
|
|
1
|
+
/**
|
|
2
|
+
* System File Blueprints — ForgeWP Compiler
|
|
3
|
+
*
|
|
4
|
+
* These are fallback templates used by the compiler's self-healing preflight check.
|
|
5
|
+
* If a developer accidentally deletes a system-critical library file,
|
|
6
|
+
* the compiler will automatically recreate it to prevent compilation and runtime errors.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const SYSTEM_BLUEPRINTS = {
|
|
10
|
+
"wordpress/menus.json": `{
|
|
11
|
+
"_comment": "⚡ ForgeWP Navigation Menus — Edit this file to add/remove links in local dev. Run 'pnpm forgewp sync:routes' to auto-scaffold corresponding React pages!",
|
|
12
|
+
"primary": [
|
|
13
|
+
{ "title": "Home", "url": "/" },
|
|
14
|
+
{ "title": "New", "url": "/new" },
|
|
15
|
+
{ "title": "Men", "url": "/men" },
|
|
16
|
+
{ "title": "Women", "url": "/women" }
|
|
17
|
+
],
|
|
18
|
+
"utility": [
|
|
19
|
+
{ "title": "Help", "url": "/help" },
|
|
20
|
+
{ "title": "Sign In", "url": "/login" }
|
|
21
|
+
]
|
|
22
|
+
}`,
|
|
23
|
+
|
|
24
|
+
"wordpress/mock-data.json": `{
|
|
25
|
+
"post": [
|
|
26
|
+
{
|
|
27
|
+
"id": 1,
|
|
28
|
+
"title": "Welcome to ForgeWP: The Headless Revolution",
|
|
29
|
+
"excerpt": "Discover how ForgeWP bridges standard WordPress themes with blistering fast React architectures.",
|
|
30
|
+
"content": "<p>This is the first mock post. In local dev, you can modify <code>wordpress/mock-data.json</code> to test layout content changes.</p>",
|
|
31
|
+
"date": "May 10, 2026",
|
|
32
|
+
"author": "Antigravity",
|
|
33
|
+
"featuredImage": "https://picsum.photos/seed/forgewp/1200/630",
|
|
34
|
+
"customFields": {}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": 2,
|
|
38
|
+
"title": "Unlocking Brutalist Web Design Aesthetics",
|
|
39
|
+
"excerpt": "A deep dive into high-contrast grids, sharp corners, and premium flat shadows in modern interfaces.",
|
|
40
|
+
"content": "<p>This is the second mock post. Style these grids using beautiful Tailwind utilities.</p>",
|
|
41
|
+
"date": "May 12, 2026",
|
|
42
|
+
"author": "DeepMind Partner",
|
|
43
|
+
"featuredImage": "https://picsum.photos/seed/brutalist/1200/630",
|
|
44
|
+
"customFields": {}
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"project": [
|
|
48
|
+
{
|
|
49
|
+
"id": 1,
|
|
50
|
+
"title": "ForgeWP Scaffolding Platform",
|
|
51
|
+
"excerpt": "Building a custom compiler framework to transpile React elements into standard PHP themes.",
|
|
52
|
+
"content": "<p>Detailed description of the ForgeWP compiler pipeline project.</p>",
|
|
53
|
+
"date": "May 15, 2026",
|
|
54
|
+
"author": "Lead Architect",
|
|
55
|
+
"featuredImage": "https://picsum.photos/seed/platform/1200/630",
|
|
56
|
+
"customFields": {
|
|
57
|
+
"client_name": "El Dorado",
|
|
58
|
+
"project_budget": "$45,000"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"id": 2,
|
|
63
|
+
"title": "Brutalist Starter Theme",
|
|
64
|
+
"excerpt": "A clean, responsive, and robust high-contrast interface leveraging Tailwind CSS v4.",
|
|
65
|
+
"content": "<p>A brutalist theme showcasing raw black borders and vivid accent colors.</p>",
|
|
66
|
+
"date": "May 16, 2026",
|
|
67
|
+
"author": "Theme Engineer",
|
|
68
|
+
"featuredImage": "https://picsum.photos/seed/starter/1200/630",
|
|
69
|
+
"customFields": {
|
|
70
|
+
"client_name": "ForgeWP Community",
|
|
71
|
+
"project_budget": "Open Source"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}`,
|
|
76
|
+
|
|
77
|
+
"src/.forgewp/forgewp-config.ts": `export interface ColorPreset {
|
|
78
|
+
name: string;
|
|
79
|
+
slug: string;
|
|
80
|
+
color: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface FontSizePreset {
|
|
84
|
+
name: string;
|
|
85
|
+
slug: string;
|
|
86
|
+
size: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface FontFamilyPreset {
|
|
90
|
+
name: string;
|
|
91
|
+
slug: string;
|
|
92
|
+
fontFamily: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface ForgeWPThemeConfig {
|
|
96
|
+
name: string;
|
|
97
|
+
slug: string;
|
|
98
|
+
version: string;
|
|
99
|
+
description: string;
|
|
100
|
+
textDomain: string;
|
|
101
|
+
/** Design aesthetic style — "forgewp" (sharp edges, high-contrast) or "shadcn" (smooth rounded modern) */
|
|
102
|
+
style?: "forgewp" | "shadcn";
|
|
103
|
+
// Design Tokens (Phase 5)
|
|
104
|
+
settings?: {
|
|
105
|
+
layout?: {
|
|
106
|
+
contentSize?: string;
|
|
107
|
+
wideSize?: string;
|
|
108
|
+
};
|
|
109
|
+
color?: {
|
|
110
|
+
palette?: ColorPreset[];
|
|
111
|
+
custom?: boolean;
|
|
112
|
+
};
|
|
113
|
+
typography?: {
|
|
114
|
+
fontSizes?: FontSizePreset[];
|
|
115
|
+
fontFamilies?: FontFamilyPreset[];
|
|
116
|
+
googleFonts?: string[];
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
`,
|
|
121
|
+
|
|
122
|
+
"src/.forgewp/wordpress.tsx": `/**
|
|
123
|
+
* ForgeWP WordPress Data Hooks
|
|
124
|
+
*
|
|
125
|
+
* These hooks provide mock data during local development (Vite dev server).
|
|
126
|
+
* When the theme is exported, the ForgeWP compiler replaces every token
|
|
127
|
+
* with the equivalent WordPress PHP function call.
|
|
128
|
+
*/
|
|
129
|
+
import React from "react";
|
|
130
|
+
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
import mockData from "../../wordpress/mock-data.json";
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
import menusData from "../../wordpress/menus.json";
|
|
135
|
+
|
|
136
|
+
import {
|
|
137
|
+
WpQueryLoop as _WpQueryLoop,
|
|
138
|
+
WpMenu as _WpMenu,
|
|
139
|
+
WpShortcode,
|
|
140
|
+
useWpTitle as _useWpTitle,
|
|
141
|
+
useWpContent as _useWpContent,
|
|
142
|
+
useWpExcerpt as _useWpExcerpt,
|
|
143
|
+
useWpPermalink as _useWpPermalink,
|
|
144
|
+
useWpDate as _useWpDate,
|
|
145
|
+
useWpAuthor as _useWpAuthor,
|
|
146
|
+
useWpFeaturedImage as _useWpFeaturedImage,
|
|
147
|
+
useWpCustomField as _useWpCustomField,
|
|
148
|
+
} from "@forgewp/react";
|
|
149
|
+
import type { WpQueryLoopProps, WpMenuProps } from "@forgewp/react";
|
|
150
|
+
|
|
151
|
+
const IS_DEV =
|
|
152
|
+
typeof import.meta !== "undefined" &&
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
import.meta.env?.DEV === true;
|
|
155
|
+
|
|
156
|
+
// ── Re-export pure hooks with compiler token fallbacks ────────────────────────
|
|
157
|
+
// In dev: @forgewp/react hook returns the mock value from WpPostContext.
|
|
158
|
+
// In prod: compiler replaces the call with the PHP equivalent below.
|
|
159
|
+
|
|
160
|
+
export function useWpTitle(): string {
|
|
161
|
+
if (IS_DEV) return _useWpTitle();
|
|
162
|
+
return "__FORGEWP_THE_TITLE__";
|
|
163
|
+
}
|
|
164
|
+
export function useWpContent(): string {
|
|
165
|
+
if (IS_DEV) return _useWpContent();
|
|
166
|
+
return "__FORGEWP_THE_CONTENT__";
|
|
167
|
+
}
|
|
168
|
+
export function useWpExcerpt(): string {
|
|
169
|
+
if (IS_DEV) return _useWpExcerpt();
|
|
170
|
+
return "__FORGEWP_THE_EXCERPT__";
|
|
171
|
+
}
|
|
172
|
+
export function useWpPermalink(): string {
|
|
173
|
+
if (IS_DEV) return _useWpPermalink();
|
|
174
|
+
return "__FORGEWP_THE_PERMALINK__";
|
|
175
|
+
}
|
|
176
|
+
export function useWpDate(): string {
|
|
177
|
+
if (IS_DEV) return _useWpDate();
|
|
178
|
+
return "__FORGEWP_THE_DATE__";
|
|
179
|
+
}
|
|
180
|
+
export function useWpAuthor(): string {
|
|
181
|
+
if (IS_DEV) return _useWpAuthor();
|
|
182
|
+
return "__FORGEWP_THE_AUTHOR__";
|
|
183
|
+
}
|
|
184
|
+
export function useWpFeaturedImage(): string {
|
|
185
|
+
if (IS_DEV) return _useWpFeaturedImage();
|
|
186
|
+
return "__FORGEWP_THE_POST_THUMBNAIL_URL__";
|
|
187
|
+
}
|
|
188
|
+
export function useWpCustomField(fieldName: string, defaultValue = ""): string {
|
|
189
|
+
if (IS_DEV) return _useWpCustomField(fieldName, defaultValue);
|
|
190
|
+
return "__FORGEWP_CUSTOM_FIELD__" + fieldName + "__";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function useWpCategories(): string {
|
|
194
|
+
if (IS_DEV) return '<a href="#">Technology</a>, <a href="#">Design</a>';
|
|
195
|
+
return "__FORGEWP_THE_CATEGORY_LIST__";
|
|
196
|
+
}
|
|
197
|
+
export function useWpArchiveTitle(): string {
|
|
198
|
+
if (IS_DEV) return "Category: Technology";
|
|
199
|
+
return "__FORGEWP_THE_ARCHIVE_TITLE__";
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ── WpQueryLoop — data bridge wraps @forgewp/react with mock data ─────────────
|
|
203
|
+
|
|
204
|
+
export function WpQueryLoop({
|
|
205
|
+
postType = "post",
|
|
206
|
+
postsPerPage = 3,
|
|
207
|
+
categoryName = "",
|
|
208
|
+
children,
|
|
209
|
+
}: WpQueryLoopProps) {
|
|
210
|
+
if (IS_DEV) {
|
|
211
|
+
const posts = (mockData as any)?.[postType] || [];
|
|
212
|
+
return (
|
|
213
|
+
<_WpQueryLoop posts={posts} postType={postType} postsPerPage={postsPerPage} categoryName={categoryName}>
|
|
214
|
+
{children}
|
|
215
|
+
</_WpQueryLoop>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Production: compiler transforms these custom elements into WordPress loop PHP
|
|
220
|
+
return (
|
|
221
|
+
<>
|
|
222
|
+
{/* @ts-ignore */}
|
|
223
|
+
<forgewp-query-loop-start postType={postType} postsPerPage={postsPerPage} categoryName={categoryName} />
|
|
224
|
+
{children}
|
|
225
|
+
{/* @ts-ignore */}
|
|
226
|
+
<forgewp-query-loop-end />
|
|
227
|
+
</>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ── WpLoop — simple all-posts loop (no postType arg) ─────────────────────────
|
|
232
|
+
|
|
233
|
+
export function WpLoop({ children }: { children: React.ReactNode }) {
|
|
234
|
+
if (IS_DEV) {
|
|
235
|
+
const posts = (mockData as any)?.post || [];
|
|
236
|
+
return (
|
|
237
|
+
<_WpQueryLoop posts={posts}>
|
|
238
|
+
{children}
|
|
239
|
+
</_WpQueryLoop>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return (
|
|
243
|
+
<>
|
|
244
|
+
{/* @ts-ignore */}
|
|
245
|
+
<forgewp-loop-start />
|
|
246
|
+
{children}
|
|
247
|
+
{/* @ts-ignore */}
|
|
248
|
+
<forgewp-loop-end />
|
|
249
|
+
</>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ── WpMenu — data bridge wraps @forgewp/react with menus.json ────────────────
|
|
254
|
+
|
|
255
|
+
export function WpMenu({ location = "primary", className = "", linkClassName = "" }: WpMenuProps) {
|
|
256
|
+
if (IS_DEV) {
|
|
257
|
+
const items =
|
|
258
|
+
(menusData as any)?.[location] ||
|
|
259
|
+
(mockData as any).menu?.[location] ||
|
|
260
|
+
[{ title: "Home", url: "/" }, { title: "Blog", url: "/post" }];
|
|
261
|
+
return <_WpMenu items={items} location={location} className={className} linkClassName={linkClassName} />;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Production: compiler transforms this into wp_nav_menu()
|
|
265
|
+
return (
|
|
266
|
+
// @ts-ignore
|
|
267
|
+
<forgewp-menu location={location} className={className} linkClassName={linkClassName} />
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ── WpShortcode — pass-through, no data bridging needed ──────────────────────
|
|
272
|
+
export { WpShortcode };
|
|
273
|
+
|
|
274
|
+
// ── Compiler custom element JSX declarations ──────────────────────────────────
|
|
275
|
+
|
|
276
|
+
declare global {
|
|
277
|
+
namespace React {
|
|
278
|
+
namespace JSX {
|
|
279
|
+
interface IntrinsicElements {
|
|
280
|
+
"forgewp-menu": React.DetailedHTMLProps<
|
|
281
|
+
React.HTMLAttributes<HTMLElement> & {
|
|
282
|
+
location?: "primary" | "footer" | "sidebar";
|
|
283
|
+
linkClassName?: string;
|
|
284
|
+
},
|
|
285
|
+
HTMLElement
|
|
286
|
+
>;
|
|
287
|
+
"forgewp-query-loop-start": React.DetailedHTMLProps<
|
|
288
|
+
React.HTMLAttributes<HTMLElement> & {
|
|
289
|
+
postType?: string;
|
|
290
|
+
postsPerPage?: number;
|
|
291
|
+
categoryName?: string;
|
|
292
|
+
},
|
|
293
|
+
HTMLElement
|
|
294
|
+
>;
|
|
295
|
+
"forgewp-query-loop-end": React.DetailedHTMLProps<
|
|
296
|
+
React.HTMLAttributes<HTMLElement>,
|
|
297
|
+
HTMLElement
|
|
298
|
+
>;
|
|
299
|
+
"forgewp-loop-start": React.DetailedHTMLProps<
|
|
300
|
+
React.HTMLAttributes<HTMLElement>,
|
|
301
|
+
HTMLElement
|
|
302
|
+
>;
|
|
303
|
+
"forgewp-loop-end": React.DetailedHTMLProps<
|
|
304
|
+
React.HTMLAttributes<HTMLElement>,
|
|
305
|
+
HTMLElement
|
|
306
|
+
>;
|
|
307
|
+
"forgewp-shortcode": React.DetailedHTMLProps<
|
|
308
|
+
React.HTMLAttributes<HTMLElement> & {
|
|
309
|
+
code?: string;
|
|
310
|
+
},
|
|
311
|
+
HTMLElement
|
|
312
|
+
>;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
`,
|
|
318
|
+
|
|
319
|
+
"src/.forgewp/SEO.tsx": `import * as ReactHelmetAsync from "react-helmet-async";
|
|
320
|
+
import { useWpTitle } from "./wordpress";
|
|
321
|
+
|
|
322
|
+
// Support both ESM and CommonJS exports of react-helmet-async across Vite and TSX compiler
|
|
323
|
+
const Helmet = (ReactHelmetAsync.Helmet || (ReactHelmetAsync as any)["default"]?.Helmet || ReactHelmetAsync) as any;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* ForgeWP SEO — Internal system file. Do not delete.
|
|
327
|
+
*
|
|
328
|
+
* Use this component in \`src/app/layout.tsx\` to set global SEO defaults,
|
|
329
|
+
* and in individual page files to override them per-page.
|
|
330
|
+
*
|
|
331
|
+
* The ForgeWP compiler reads the props you pass here and injects them
|
|
332
|
+
* directly into the WordPress theme's <head> as native meta tags.
|
|
333
|
+
*
|
|
334
|
+
* @see https://forgewp.dev/docs/seo
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
export interface SEOProps {
|
|
338
|
+
/** Page title — defaults to the WordPress post title via useWpTitle() */
|
|
339
|
+
title?: string;
|
|
340
|
+
/** Meta description for search engines and social cards */
|
|
341
|
+
description?: string;
|
|
342
|
+
/** Comma-separated keywords */
|
|
343
|
+
keywords?: string;
|
|
344
|
+
/** Open Graph title (falls back to title if omitted) */
|
|
345
|
+
ogTitle?: string;
|
|
346
|
+
/** Open Graph description (falls back to description if omitted) */
|
|
347
|
+
ogDescription?: string;
|
|
348
|
+
/** Absolute URL to the Open Graph image */
|
|
349
|
+
ogImage?: string;
|
|
350
|
+
/** Open Graph type — "website" for homepages, "article" for posts */
|
|
351
|
+
ogType?: string;
|
|
352
|
+
/** Twitter card type */
|
|
353
|
+
twitterCard?: string;
|
|
354
|
+
/** Twitter creator handle, e.g. "@username" */
|
|
355
|
+
twitterCreator?: string;
|
|
356
|
+
/** Canonical URL — tells search engines the preferred version of this page */
|
|
357
|
+
canonical?: string;
|
|
358
|
+
/** Set to true to prevent this page from being indexed by search engines */
|
|
359
|
+
noIndex?: boolean;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* \`<SEO>\` — ForgeWP SEO manager.
|
|
364
|
+
*
|
|
365
|
+
* Drop this into your **layout.tsx** to set site-wide defaults.
|
|
366
|
+
* Then drop it into any **page file** to override for that specific template.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* // layout.tsx — global defaults (the compiler reads these for all pages)
|
|
370
|
+
* <SEO
|
|
371
|
+
* description="Your site tagline or description."
|
|
372
|
+
* keywords="WordPress, React, Tailwind"
|
|
373
|
+
* ogImage="https://yoursite.com/og-default.png"
|
|
374
|
+
* />
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* // single.tsx — per-page override (article-specific metadata)
|
|
378
|
+
* <SEO
|
|
379
|
+
* ogType="article"
|
|
380
|
+
* ogImage="https://yoursite.com/og-post.png"
|
|
381
|
+
* twitterCreator="@yourhandle"
|
|
382
|
+
* />
|
|
383
|
+
*/
|
|
384
|
+
export function SEO({
|
|
385
|
+
title,
|
|
386
|
+
description = "A WordPress theme built with ForgeWP — React & Tailwind CSS.",
|
|
387
|
+
keywords = "WordPress, React, Tailwind CSS, ForgeWP",
|
|
388
|
+
ogTitle,
|
|
389
|
+
ogDescription,
|
|
390
|
+
ogImage,
|
|
391
|
+
ogType = "website",
|
|
392
|
+
twitterCard = "summary_large_image",
|
|
393
|
+
twitterCreator,
|
|
394
|
+
canonical,
|
|
395
|
+
noIndex = false,
|
|
396
|
+
}: SEOProps) {
|
|
397
|
+
const wpTitle = useWpTitle();
|
|
398
|
+
const resolvedTitle = title ?? wpTitle;
|
|
399
|
+
|
|
400
|
+
return (
|
|
401
|
+
<Helmet>
|
|
402
|
+
{/* ── Primary ── */}
|
|
403
|
+
<title>{resolvedTitle}</title>
|
|
404
|
+
<meta name="description" content={description} />
|
|
405
|
+
{keywords && <meta name="keywords" content={keywords} />}
|
|
406
|
+
{noIndex && <meta name="robots" content="noindex, nofollow" />}
|
|
407
|
+
{canonical && <link rel="canonical" href={canonical} />}
|
|
408
|
+
|
|
409
|
+
{/* ── Open Graph ── */}
|
|
410
|
+
<meta property="og:type" content={ogType} />
|
|
411
|
+
<meta property="og:title" content={ogTitle ?? resolvedTitle} />
|
|
412
|
+
<meta property="og:description" content={ogDescription ?? description} />
|
|
413
|
+
{ogImage && <meta property="og:image" content={ogImage} />}
|
|
414
|
+
|
|
415
|
+
{/* ── Twitter ── */}
|
|
416
|
+
<meta name="twitter:card" content={twitterCard} />
|
|
417
|
+
<meta name="twitter:title" content={ogTitle ?? resolvedTitle} />
|
|
418
|
+
<meta name="twitter:description" content={ogDescription ?? description} />
|
|
419
|
+
{ogImage && <meta name="twitter:image" content={ogImage} />}
|
|
420
|
+
{twitterCreator && <meta name="twitter:creator" content={twitterCreator} />}
|
|
421
|
+
</Helmet>
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
`,
|
|
425
|
+
|
|
426
|
+
"src/.forgewp/PresetsStyle.tsx": `import wpConfig from "../../wp.config";
|
|
427
|
+
|
|
428
|
+
const IS_DEV =
|
|
429
|
+
typeof import.meta !== "undefined" &&
|
|
430
|
+
// @ts-ignore
|
|
431
|
+
import.meta.env?.DEV === true;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* PresetsStyle component — Internal system component.
|
|
435
|
+
*
|
|
436
|
+
* Dynamically injects WordPress-preset CSS Custom Properties and enqueues Google Fonts
|
|
437
|
+
* during local Vite development, keeping your styles perfectly in sync with WordPress.
|
|
438
|
+
* In production builds, this returns only the registry-aesthetic design tokens (like --radius)
|
|
439
|
+
* to keep shadcn components and theme variables responsive to your config.
|
|
440
|
+
*/
|
|
441
|
+
export function PresetsStyle() {
|
|
442
|
+
const themeStyle = wpConfig.style || "forgewp";
|
|
443
|
+
|
|
444
|
+
// Production build: only inject custom registry-aesthetic design properties
|
|
445
|
+
if (!IS_DEV) {
|
|
446
|
+
const prodCss = \`
|
|
447
|
+
:root {
|
|
448
|
+
--radius: \${themeStyle === "forgewp" ? "0px" : "0.5rem"};
|
|
449
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
450
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
451
|
+
--radius-lg: var(--radius);
|
|
452
|
+
--border-width: \${themeStyle === "forgewp" ? "2px" : "1px"};
|
|
453
|
+
--border-color: \${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
|
|
454
|
+
--shadow-offset: \${themeStyle === "forgewp" ? "4px" : "0px"};
|
|
455
|
+
}
|
|
456
|
+
\`;
|
|
457
|
+
return <style dangerouslySetInnerHTML={{ __html: prodCss }} />;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Local development fallbacks for WordPress CSS presets
|
|
461
|
+
const colors = wpConfig.settings?.color?.palette || [];
|
|
462
|
+
const fontSizes = wpConfig.settings?.typography?.fontSizes || [];
|
|
463
|
+
const fontFamilies = wpConfig.settings?.typography?.fontFamilies || [];
|
|
464
|
+
const layout = wpConfig.settings?.layout || {};
|
|
465
|
+
const googleFonts = wpConfig.settings?.typography?.googleFonts || [];
|
|
466
|
+
|
|
467
|
+
// Parse and build Google Fonts href for dev injection
|
|
468
|
+
const fontsHtml = googleFonts.length > 0
|
|
469
|
+
? \`<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
470
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
471
|
+
<link href="https://fonts.googleapis.com/css2?family=\&{googleFonts.map(f => encodeURIComponent(f)).join("&family=")}&display=swap" rel="stylesheet">\`
|
|
472
|
+
: "";
|
|
473
|
+
|
|
474
|
+
const devCss = \`
|
|
475
|
+
:root {
|
|
476
|
+
\${colors.map((c) => "--wp--preset--color--" + c.slug + ": " + c.color + ";").join("\\n ")}
|
|
477
|
+
\${fontSizes.map((f) => "--wp--preset--font-size--" + f.slug + ": " + f.size + ";").join("\\n ")}
|
|
478
|
+
\${fontFamilies.map((f) => "--wp--preset--font-family--" + f.slug + ": " + f.fontFamily + ";").join("\\n ")}
|
|
479
|
+
\${layout.contentSize ? "--wp--style--global--content-size: " + layout.contentSize + ";" : ""}
|
|
480
|
+
\${layout.wideSize ? "--wp--style--global--wide-size: " + layout.wideSize + ";" : ""}
|
|
481
|
+
|
|
482
|
+
/* Registry Aesthetic Mode Custom Properties */
|
|
483
|
+
--radius: \${themeStyle === "forgewp" ? "0px" : "0.5rem"};
|
|
484
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
485
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
486
|
+
--radius-lg: var(--radius);
|
|
487
|
+
--border-width: \${themeStyle === "forgewp" ? "2px" : "1px"};
|
|
488
|
+
--border-color: \${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
|
|
489
|
+
--shadow-offset: \${themeStyle === "forgewp" ? "4px" : "0px"};
|
|
490
|
+
}
|
|
491
|
+
\`;
|
|
492
|
+
|
|
493
|
+
return (
|
|
494
|
+
<>
|
|
495
|
+
{fontsHtml && <span dangerouslySetInnerHTML={{ __html: fontsHtml }} />}
|
|
496
|
+
<style dangerouslySetInnerHTML={{ __html: devCss }} />
|
|
497
|
+
</>
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
`
|
|
501
|
+
};
|