@forgewp/compiler 0.4.1 → 0.4.2
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/cli.js +4 -0
- package/bin/sync-hooks.js +221 -0
- package/lib/blueprints.js +12 -1456
- package/lib/functions-builder.js +244 -1
- package/lib/generate-theme.js +121 -0
- package/lib/hydration-scanner.js +147 -0
- package/lib/markup-processor.js +5 -0
- package/lib/render-theme.mts +19 -2
- package/package.json +3 -2
- package/templates/PresetsStyle.tsx +74 -0
- package/templates/SEO.tsx +109 -0
- package/templates/forgewp-config.ts +43 -0
- package/templates/menus.json +11 -0
- package/templates/mock-data.json +434 -0
- package/templates/wordpress.tsx +1297 -0
package/lib/blueprints.js
CHANGED
|
@@ -1,1459 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
*/
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
'cms/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>cms/mock-data.json</code> to test layout content changes.</p>",
|
|
31
|
-
"date": "2026-05-10T09:00:00Z",
|
|
32
|
-
"author": "Antigravity",
|
|
33
|
-
"featuredImage": {
|
|
34
|
-
"id": 101,
|
|
35
|
-
"url": "https://picsum.photos/seed/forgewp/1200/630",
|
|
36
|
-
"alt": "ForgeWP Logo and Brand Artwork",
|
|
37
|
-
"title": "ForgeWP Logo",
|
|
38
|
-
"caption": "A high-fidelity minimalist logo graphic.",
|
|
39
|
-
"width": 1200,
|
|
40
|
-
"height": 630,
|
|
41
|
-
"sizes": {
|
|
42
|
-
"thumbnail": { "url": "https://picsum.photos/seed/forgewp/150/150", "width": 150, "height": 150 },
|
|
43
|
-
"medium": { "url": "https://picsum.photos/seed/forgewp/300/300", "width": 300, "height": 300 },
|
|
44
|
-
"large": { "url": "https://picsum.photos/seed/forgewp/1024/768", "width": 1024, "height": 768 }
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"customFields": { "read_time": "5" },
|
|
48
|
-
"_terms": {
|
|
49
|
-
"category": [
|
|
50
|
-
{ "id": 1, "slug": "tutorials", "name": "Tutorials" },
|
|
51
|
-
{ "id": 2, "slug": "framework", "name": "Framework" }
|
|
52
|
-
],
|
|
53
|
-
"post_tag": [
|
|
54
|
-
{ "id": 10, "slug": "react", "name": "React" },
|
|
55
|
-
{ "id": 11, "slug": "wordpress", "name": "WordPress" }
|
|
56
|
-
]
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"id": 2,
|
|
61
|
-
"title": "Unlocking Brutalist Web Design Aesthetics",
|
|
62
|
-
"excerpt": "A deep dive into high-contrast grids, sharp corners, and premium flat shadows in modern interfaces.",
|
|
63
|
-
"content": "<p>This is the second mock post. Style these grids using beautiful Tailwind utilities.</p>",
|
|
64
|
-
"date": "2026-05-12T14:30:00Z",
|
|
65
|
-
"author": "DeepMind Partner",
|
|
66
|
-
"featuredImage": "https://picsum.photos/seed/brutalist/1200/630",
|
|
67
|
-
"customFields": { "read_time": "8" },
|
|
68
|
-
"_terms": {
|
|
69
|
-
"category": [
|
|
70
|
-
{ "id": 3, "slug": "design", "name": "Design" },
|
|
71
|
-
{ "id": 4, "slug": "css", "name": "CSS" }
|
|
72
|
-
],
|
|
73
|
-
"post_tag": [
|
|
74
|
-
{ "id": 12, "slug": "brutalism", "name": "Brutalism" },
|
|
75
|
-
{ "id": 13, "slug": "tailwind", "name": "Tailwind" }
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
],
|
|
80
|
-
"project": [
|
|
81
|
-
{
|
|
82
|
-
"id": 1,
|
|
83
|
-
"title": "ForgeWP Scaffolding Platform",
|
|
84
|
-
"excerpt": "Building a custom compiler framework to transpile React elements into standard PHP themes.",
|
|
85
|
-
"content": "<p>Detailed description of the ForgeWP compiler pipeline project.</p>",
|
|
86
|
-
"date": "2026-05-15T12:00:00Z",
|
|
87
|
-
"author": "Lead Architect",
|
|
88
|
-
"featuredImage": "https://picsum.photos/seed/platform/1200/630",
|
|
89
|
-
"customFields": {
|
|
90
|
-
"client_name": "El Dorado",
|
|
91
|
-
"project_budget": "45000",
|
|
92
|
-
"status": "active"
|
|
93
|
-
},
|
|
94
|
-
"_terms": {
|
|
95
|
-
"project_type": [{ "id": 20, "slug": "open-source", "name": "Open Source" }],
|
|
96
|
-
"technology": [{ "id": 30, "slug": "react", "name": "React" }]
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
"id": 2,
|
|
101
|
-
"title": "Brutalist Starter Theme",
|
|
102
|
-
"excerpt": "A clean, responsive, and robust high-contrast interface leveraging Tailwind CSS v4.",
|
|
103
|
-
"content": "<p>A brutalist theme showcasing raw black borders and vivid accent colors.</p>",
|
|
104
|
-
"date": "2026-05-16T16:00:00Z",
|
|
105
|
-
"author": "Theme Engineer",
|
|
106
|
-
"featuredImage": "https://picsum.photos/seed/starter/1200/630",
|
|
107
|
-
"customFields": {
|
|
108
|
-
"client_name": "ForgeWP Community",
|
|
109
|
-
"project_budget": "0",
|
|
110
|
-
"status": "completed"
|
|
111
|
-
},
|
|
112
|
-
"_terms": {
|
|
113
|
-
"project_type": [{ "id": 20, "slug": "open-source", "name": "Open Source" }],
|
|
114
|
-
"technology": [{ "id": 32, "slug": "tailwind", "name": "Tailwind CSS" }]
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
],
|
|
118
|
-
"attachment": [
|
|
119
|
-
{
|
|
120
|
-
"id": 101,
|
|
121
|
-
"url": "https://picsum.photos/seed/forgewp/1200/630",
|
|
122
|
-
"alt": "ForgeWP Logo and Brand Artwork",
|
|
123
|
-
"title": "ForgeWP Logo",
|
|
124
|
-
"caption": "A high-fidelity minimalist logo graphic.",
|
|
125
|
-
"width": 1200,
|
|
126
|
-
"height": 630,
|
|
127
|
-
"sizes": {
|
|
128
|
-
"thumbnail": { "url": "https://picsum.photos/seed/forgewp/150/150", "width": 150, "height": 150 },
|
|
129
|
-
"medium": { "url": "https://picsum.photos/seed/forgewp/300/300", "width": 300, "height": 300 },
|
|
130
|
-
"large": { "url": "https://picsum.photos/seed/forgewp/1024/768", "width": 1024, "height": 768 }
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
"id": 102,
|
|
135
|
-
"url": "https://picsum.photos/seed/layout/1200/800",
|
|
136
|
-
"alt": "Brutalist Layout Preview",
|
|
137
|
-
"title": "Layout Preview",
|
|
138
|
-
"width": 1200,
|
|
139
|
-
"height": 800,
|
|
140
|
-
"sizes": {
|
|
141
|
-
"thumbnail": { "url": "https://picsum.photos/seed/layout/150/150", "width": 150, "height": 150 },
|
|
142
|
-
"medium": { "url": "https://picsum.photos/seed/layout/300/300", "width": 300, "height": 300 }
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
]
|
|
146
|
-
}`,
|
|
147
|
-
|
|
148
|
-
'src/.forgewp/forgewp-config.ts': `export interface ColorPreset {
|
|
149
|
-
name: string;
|
|
150
|
-
slug: string;
|
|
151
|
-
color: string;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export interface FontSizePreset {
|
|
155
|
-
name: string;
|
|
156
|
-
slug: string;
|
|
157
|
-
size: string;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export interface FontFamilyPreset {
|
|
161
|
-
name: string;
|
|
162
|
-
slug: string;
|
|
163
|
-
fontFamily: string;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export interface ForgeWPI18nConfig {
|
|
167
|
-
locales: string[];
|
|
168
|
-
defaultLocale: string;
|
|
169
|
-
provider?: 'local' | 'deepl' | 'libretranslate' | 'google' | string;
|
|
170
|
-
cache?: string;
|
|
171
|
-
providerConfig?: {
|
|
172
|
-
apiKey?: string;
|
|
173
|
-
endpoint?: string;
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export interface ForgeWPThemeConfig {
|
|
178
|
-
name: string;
|
|
179
|
-
slug: string;
|
|
180
|
-
version: string;
|
|
181
|
-
description: string;
|
|
182
|
-
textDomain: string;
|
|
183
|
-
/** Design aesthetic style — "forgewp" (sharp edges, high-contrast) or "shadcn" (smooth rounded modern) */
|
|
184
|
-
style?: "forgewp" | "shadcn";
|
|
185
|
-
i18n?: ForgeWPI18nConfig;
|
|
186
|
-
// Design Tokens (Phase 5)
|
|
187
|
-
settings?: {
|
|
188
|
-
layout?: {
|
|
189
|
-
contentSize?: string;
|
|
190
|
-
wideSize?: string;
|
|
191
|
-
};
|
|
192
|
-
color?: {
|
|
193
|
-
palette?: ColorPreset[];
|
|
194
|
-
custom?: boolean;
|
|
195
|
-
};
|
|
196
|
-
typography?: {
|
|
197
|
-
fontSizes?: FontSizePreset[];
|
|
198
|
-
fontFamilies?: FontFamilyPreset[];
|
|
199
|
-
googleFonts?: string[];
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
`,
|
|
204
|
-
|
|
205
|
-
'src/.forgewp/wordpress.tsx': `/**
|
|
206
|
-
* ForgeWP WordPress Data Hooks
|
|
207
|
-
*
|
|
208
|
-
* These hooks provide mock data during local development (Vite dev server).
|
|
209
|
-
* When the theme is exported, the ForgeWP compiler replaces every token
|
|
210
|
-
* with the equivalent WordPress PHP function call.
|
|
211
|
-
*/
|
|
212
|
-
import React from 'react';
|
|
213
|
-
import { Link as WouterLink, useLocation as useWouterLocation, useSearch as useWouterSearch } from 'wouter';
|
|
214
|
-
|
|
215
|
-
// @ts-ignore
|
|
216
|
-
import mockData from '../../cms/mock-data.json';
|
|
217
|
-
// @ts-ignore
|
|
218
|
-
import menusData from '../../cms/menus.json';
|
|
219
|
-
// @ts-ignore
|
|
220
|
-
import siteSettings from '../../cms/site-settings.json';
|
|
221
|
-
// @ts-ignore
|
|
222
|
-
import translationsData from '../../cms/translations.json';
|
|
223
|
-
|
|
224
|
-
import {
|
|
225
|
-
WpQueryLoop as _WpQueryLoop,
|
|
226
|
-
WpMenu as _WpMenu,
|
|
227
|
-
WpShortcode as _WpShortcode,
|
|
228
|
-
useWpTitle as _useWpTitle,
|
|
229
|
-
useWpContent as _useWpContent,
|
|
230
|
-
useWpExcerpt as _useWpExcerpt,
|
|
231
|
-
useWpPermalink as _useWpPermalink,
|
|
232
|
-
useWpDate as _useWpDate,
|
|
233
|
-
useWpAuthor as _useWpAuthor,
|
|
234
|
-
useWpFeaturedImage as _useWpFeaturedImage,
|
|
235
|
-
useWpCustomField as _useWpCustomField,
|
|
236
|
-
useWpField as _useWpField,
|
|
237
|
-
useWpOption as _useWpOption,
|
|
238
|
-
useWpThemeMod as _useWpThemeMod,
|
|
239
|
-
useWpThemeUri as _useWpThemeUri,
|
|
240
|
-
useWpQuery as _useWpQuery,
|
|
241
|
-
WpHead as _WpHead,
|
|
242
|
-
WpImage as _WpImage,
|
|
243
|
-
WpPostContext,
|
|
244
|
-
useWpMeta as _useWpMeta,
|
|
245
|
-
useWpPageLink as _useWpPageLink,
|
|
246
|
-
BlockArea as _BlockArea,
|
|
247
|
-
defineEditable,
|
|
248
|
-
text,
|
|
249
|
-
richText,
|
|
250
|
-
image,
|
|
251
|
-
boolean,
|
|
252
|
-
repeater,
|
|
253
|
-
WpRepeater,
|
|
254
|
-
WpIcon,
|
|
255
|
-
} from '@forgewp/react';
|
|
256
|
-
|
|
257
|
-
export { WpPostContext, defineEditable, text, richText, image, boolean, repeater, WpRepeater, WpIcon };
|
|
258
|
-
|
|
259
|
-
import type {
|
|
260
|
-
WpQueryLoopProps,
|
|
261
|
-
WpMenuProps,
|
|
262
|
-
WpHeadProps,
|
|
263
|
-
WpImageProps,
|
|
264
|
-
WpAttachment,
|
|
265
|
-
WpQueryArgs,
|
|
266
|
-
WpQueryResults,
|
|
267
|
-
WpPost,
|
|
268
|
-
WpShortcodeProps,
|
|
269
|
-
BlockAreaProps,
|
|
270
|
-
WpRepeaterProps,
|
|
271
|
-
WpIconProps,
|
|
272
|
-
} from '@forgewp/react';
|
|
273
|
-
|
|
274
|
-
const IS_DEV =
|
|
275
|
-
typeof import.meta !== 'undefined' &&
|
|
276
|
-
// @ts-ignore
|
|
277
|
-
import.meta.env?.DEV === true;
|
|
278
|
-
|
|
279
|
-
export function decodeHtmlEntities(str: string): string {
|
|
280
|
-
if (!str) return '';
|
|
281
|
-
if (typeof window === 'undefined') {
|
|
282
|
-
return str
|
|
283
|
-
.replace(/&/g, '&')
|
|
284
|
-
.replace(/</g, '<')
|
|
285
|
-
.replace(/>/g, '>')
|
|
286
|
-
.replace(/"/g, '"')
|
|
287
|
-
.replace(/'/g, "'")
|
|
288
|
-
.replace(/'/g, "'");
|
|
289
|
-
}
|
|
290
|
-
const txt = document.createElement('textarea');
|
|
291
|
-
txt.innerHTML = str;
|
|
292
|
-
return txt.value;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (IS_DEV) {
|
|
296
|
-
if (typeof window !== 'undefined') {
|
|
297
|
-
(window as any)._forgeWpMockSiteSettings = siteSettings;
|
|
298
|
-
(window as any)._forgeWpMockPosts = mockData;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// ── Re-export pure hooks with compiler token fallbacks ────────────────────────
|
|
303
|
-
// In dev: @forgewp/react hook returns the mock value from WpPostContext.
|
|
304
|
-
// In prod: compiler replaces the call with the PHP equivalent below.
|
|
305
|
-
|
|
306
|
-
export function useWpTitle(): string {
|
|
307
|
-
if (IS_DEV) return _useWpTitle();
|
|
308
|
-
return '__FORGEWP_THE_TITLE__';
|
|
309
|
-
}
|
|
310
|
-
export function useWpContent(): string {
|
|
311
|
-
if (IS_DEV) return _useWpContent();
|
|
312
|
-
return '__FORGEWP_THE_CONTENT__';
|
|
313
|
-
}
|
|
314
|
-
export function useWpExcerpt(): string {
|
|
315
|
-
if (IS_DEV) return _useWpExcerpt();
|
|
316
|
-
return '__FORGEWP_THE_EXCERPT__';
|
|
317
|
-
}
|
|
318
|
-
export function useWpPermalink(): string {
|
|
319
|
-
if (IS_DEV) return _useWpPermalink();
|
|
320
|
-
return '__FORGEWP_THE_PERMALINK__';
|
|
321
|
-
}
|
|
322
|
-
export function useWpDate(): string {
|
|
323
|
-
if (IS_DEV) return _useWpDate();
|
|
324
|
-
return '__FORGEWP_THE_DATE__';
|
|
325
|
-
}
|
|
326
|
-
export function useWpAuthor(): string {
|
|
327
|
-
if (IS_DEV) return _useWpAuthor();
|
|
328
|
-
return '__FORGEWP_THE_AUTHOR__';
|
|
329
|
-
}
|
|
330
|
-
export function useWpFeaturedImage(): string {
|
|
331
|
-
if (IS_DEV) return _useWpFeaturedImage();
|
|
332
|
-
return '__FORGEWP_THE_POST_THUMBNAIL_URL__';
|
|
333
|
-
}
|
|
334
|
-
export function useWpCustomField(fieldName: string, defaultValue = ''): any {
|
|
335
|
-
if (IS_DEV) return _useWpCustomField(fieldName, defaultValue);
|
|
336
|
-
|
|
337
|
-
if (typeof window !== 'undefined') {
|
|
338
|
-
const win = window as any;
|
|
339
|
-
if (!win._forgeWpCompileTime) {
|
|
340
|
-
const post = React.useContext(WpPostContext);
|
|
341
|
-
const currentPost = post || win.forgeWpHydration?.post;
|
|
342
|
-
if (currentPost?.customFields && typeof currentPost.customFields[fieldName] !== 'undefined') {
|
|
343
|
-
return currentPost.customFields[fieldName];
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
return '__FORGEWP_CUSTOM_FIELD__' + fieldName + '__';
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
export function useWpField(fieldName: string, defaultValue = ''): any {
|
|
352
|
-
if (IS_DEV) return _useWpField(fieldName, defaultValue);
|
|
353
|
-
|
|
354
|
-
if (typeof window !== 'undefined') {
|
|
355
|
-
const win = window as any;
|
|
356
|
-
if (!win._forgeWpCompileTime) {
|
|
357
|
-
const post = React.useContext(WpPostContext);
|
|
358
|
-
const currentPost = post || win.forgeWpHydration?.post;
|
|
359
|
-
if (currentPost?.customFields && typeof currentPost.customFields[fieldName] !== 'undefined') {
|
|
360
|
-
return currentPost.customFields[fieldName];
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
return '__FORGEWP_CUSTOM_FIELD__' + fieldName + '__';
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
export function useWpMeta<T>(key: string, defaultValue: T): T {
|
|
369
|
-
if (IS_DEV) return _useWpMeta(key, defaultValue);
|
|
370
|
-
|
|
371
|
-
// Browser-side hydration: check for forgeWpHydration data first
|
|
372
|
-
if (typeof window !== 'undefined') {
|
|
373
|
-
const win = window as any;
|
|
374
|
-
if (win._forgeWpCompileTime) {
|
|
375
|
-
if (typeof defaultValue === 'string') {
|
|
376
|
-
return \`__FORGEWP_META_\${key}_DEFAULT_\${encodeURIComponent(defaultValue).replace(/_/g, '%5F')}__\` as any as T;
|
|
377
|
-
}
|
|
378
|
-
return defaultValue;
|
|
379
|
-
}
|
|
380
|
-
const post = React.useContext(WpPostContext);
|
|
381
|
-
const currentPost = post || win.forgeWpHydration?.post;
|
|
382
|
-
if (currentPost?.customFields && typeof currentPost.customFields[key] !== 'undefined') {
|
|
383
|
-
return currentPost.customFields[key] as T;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Fallback to token for compiler replacement
|
|
388
|
-
const defaultStr = typeof defaultValue === 'string' ? defaultValue : JSON.stringify(defaultValue);
|
|
389
|
-
return \`__FORGEWP_META_\${key}_DEFAULT_\${encodeURIComponent(defaultStr).replace(/_/g, '%5F')}__\` as any as T;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
export function useWpOption(optionName: string, defaultValue = ''): string {
|
|
393
|
-
if (IS_DEV) return _useWpOption(optionName, defaultValue);
|
|
394
|
-
|
|
395
|
-
// Browser-side hydration: check for forgeWpHydration data first
|
|
396
|
-
if (typeof window !== 'undefined') {
|
|
397
|
-
const win = window as any;
|
|
398
|
-
const siteSettings =
|
|
399
|
-
win._forgeWpMockSiteSettings || win.forgeWpHydration?.siteSettings;
|
|
400
|
-
if (siteSettings?.options?.[optionName] !== undefined) {
|
|
401
|
-
const value = siteSettings.options[optionName];
|
|
402
|
-
// Handle false/null values from WordPress
|
|
403
|
-
if (value === false || value === null) {
|
|
404
|
-
return defaultValue || \`[option: \${optionName}]\`;
|
|
405
|
-
}
|
|
406
|
-
return String(value);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// Fallback to token for compiler replacement
|
|
411
|
-
return defaultValue
|
|
412
|
-
? \`__FORGEWP_OPTION_\${optionName}_DEFAULT_\${encodeURIComponent(defaultValue)}__\`
|
|
413
|
-
: \`__FORGEWP_OPTION_\${optionName}__\`;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
export function useWpThemeMod(modName: string, defaultValue = ''): string {
|
|
417
|
-
if (IS_DEV) return _useWpThemeMod(modName, defaultValue);
|
|
418
|
-
|
|
419
|
-
// Browser-side hydration: check for forgeWpHydration data first
|
|
420
|
-
if (typeof window !== 'undefined') {
|
|
421
|
-
const win = window as any;
|
|
422
|
-
const siteSettings =
|
|
423
|
-
win._forgeWpMockSiteSettings || win.forgeWpHydration?.siteSettings;
|
|
424
|
-
if (siteSettings?.theme_mods?.[modName] !== undefined) {
|
|
425
|
-
const value = siteSettings.theme_mods[modName];
|
|
426
|
-
// Handle false/null values from WordPress
|
|
427
|
-
if (value === false || value === null) {
|
|
428
|
-
return defaultValue || \`[theme_mod: \${modName}]\`;
|
|
429
|
-
}
|
|
430
|
-
return String(value);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Fallback to token for compiler replacement
|
|
435
|
-
return defaultValue
|
|
436
|
-
? \`__FORGEWP_THEME_MOD_\${modName}_DEFAULT_\${encodeURIComponent(defaultValue)}__\`
|
|
437
|
-
: \`__FORGEWP_THEME_MOD_\${modName}__\`;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
export function useWpThemeUri(): string {
|
|
441
|
-
if (IS_DEV) return _useWpThemeUri();
|
|
442
|
-
if (typeof window !== 'undefined' && !(window as any)._forgeWpCompileTime) {
|
|
443
|
-
return (window as any).forgeWpHydration?.themeUri || '';
|
|
444
|
-
}
|
|
445
|
-
return '__FORGEWP_THEME_URI__';
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
export function useWpPageLink(name: string, fallback: string): string {
|
|
449
|
-
if (IS_DEV) return _useWpPageLink(name, fallback);
|
|
450
|
-
if (typeof window !== 'undefined' && !(window as any)._forgeWpCompileTime) {
|
|
451
|
-
const win = window as any;
|
|
452
|
-
if (win.forgeWpHydration?.pageLinks?.[name]) {
|
|
453
|
-
return win.forgeWpHydration.pageLinks[name];
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return fallback
|
|
457
|
-
? \`__FORGEWP_PAGELINK_\${name}_DEFAULT_\${encodeURIComponent(fallback)}__\`
|
|
458
|
-
: \`__FORGEWP_PAGELINK_\${name}__\`;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
export function useWpQuery(args: WpQueryArgs = {}): WpQueryResults {
|
|
462
|
-
if (IS_DEV) {
|
|
463
|
-
return _useWpQuery(args);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// Node SSR (Compile-time)
|
|
467
|
-
if (typeof window === 'undefined') {
|
|
468
|
-
const {
|
|
469
|
-
postType = 'post',
|
|
470
|
-
postsPerPage = 10,
|
|
471
|
-
categoryName = '',
|
|
472
|
-
s = '',
|
|
473
|
-
paged = 1,
|
|
474
|
-
orderby = 'date',
|
|
475
|
-
order = 'DESC',
|
|
476
|
-
} = args;
|
|
477
|
-
|
|
478
|
-
const mockDb = (mockData as any)?.[postType] || [];
|
|
479
|
-
let filtered = [...mockDb];
|
|
480
|
-
|
|
481
|
-
if (s) {
|
|
482
|
-
const query = s.toLowerCase();
|
|
483
|
-
filtered = filtered.filter(
|
|
484
|
-
(p) =>
|
|
485
|
-
(p.title && p.title.toLowerCase().includes(query)) ||
|
|
486
|
-
(p.content && p.content.toLowerCase().includes(query)) ||
|
|
487
|
-
(p.excerpt && p.excerpt.toLowerCase().includes(query)),
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (categoryName) {
|
|
492
|
-
const catLower = categoryName.toLowerCase();
|
|
493
|
-
filtered = filtered.filter((p) => {
|
|
494
|
-
const fields = JSON.stringify(p.customFields || {}).toLowerCase();
|
|
495
|
-
return (
|
|
496
|
-
fields.includes(catLower) ||
|
|
497
|
-
(p.excerpt && p.excerpt.toLowerCase().includes(catLower))
|
|
498
|
-
);
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
filtered.sort((a, b) => {
|
|
503
|
-
let valA = (a as any)[orderby] || '';
|
|
504
|
-
let valB = (b as any)[orderby] || '';
|
|
505
|
-
|
|
506
|
-
if (orderby === 'date') {
|
|
507
|
-
valA = new Date(a.date || 0).getTime();
|
|
508
|
-
valB = new Date(b.date || 0).getTime();
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
if (order === 'DESC') {
|
|
512
|
-
return valA < valB ? 1 : valA > valB ? -1 : 0;
|
|
513
|
-
} else {
|
|
514
|
-
return valA > valB ? 1 : valA < valB ? -1 : 0;
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
const start = 0;
|
|
519
|
-
const end = paged * postsPerPage;
|
|
520
|
-
const pageItems = filtered.slice(start, end);
|
|
521
|
-
|
|
522
|
-
return {
|
|
523
|
-
posts: pageItems,
|
|
524
|
-
loading: false,
|
|
525
|
-
error: null,
|
|
526
|
-
hasMore: end < filtered.length,
|
|
527
|
-
loadMore: async () => {},
|
|
528
|
-
refetch: async () => {},
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
// Browser (Hydration/Production Client)
|
|
533
|
-
const {
|
|
534
|
-
postType = 'post',
|
|
535
|
-
postsPerPage = 10,
|
|
536
|
-
categoryName = '',
|
|
537
|
-
s = '',
|
|
538
|
-
paged = 1,
|
|
539
|
-
orderby = 'date',
|
|
540
|
-
order = 'DESC',
|
|
541
|
-
} = args;
|
|
542
|
-
|
|
543
|
-
const [posts, setPosts] = React.useState<WpPost[]>([]);
|
|
544
|
-
const [loading, setLoading] = React.useState(false);
|
|
545
|
-
const [error, setError] = React.useState<string | null>(null);
|
|
546
|
-
const [currentPage, setCurrentPage] = React.useState(paged);
|
|
547
|
-
const [hasMore, setHasMore] = React.useState(true);
|
|
548
|
-
|
|
549
|
-
const executeProdQuery = React.useCallback(
|
|
550
|
-
async (page: number) => {
|
|
551
|
-
setLoading(true);
|
|
552
|
-
try {
|
|
553
|
-
const endpoint =
|
|
554
|
-
postType === 'post'
|
|
555
|
-
? 'posts'
|
|
556
|
-
: postType === 'page'
|
|
557
|
-
? 'pages'
|
|
558
|
-
: postType;
|
|
559
|
-
const params = new URLSearchParams();
|
|
560
|
-
params.append('per_page', String(postsPerPage));
|
|
561
|
-
params.append('page', String(page));
|
|
562
|
-
params.append('_embed', '1');
|
|
563
|
-
if (s) {
|
|
564
|
-
params.append('search', s);
|
|
565
|
-
}
|
|
566
|
-
if (orderby) {
|
|
567
|
-
params.append('orderby', orderby === 'date' ? 'date' : orderby);
|
|
568
|
-
}
|
|
569
|
-
if (order) {
|
|
570
|
-
params.append('order', order.toLowerCase());
|
|
571
|
-
}
|
|
572
|
-
if (categoryName) {
|
|
573
|
-
params.append('category_name', categoryName);
|
|
574
|
-
}
|
|
575
|
-
// Polylang multi-language query support
|
|
576
|
-
const currentLang = (window as any).forgeWpLocale || (window as any).forgeWpTranslations?.currentLanguage;
|
|
577
|
-
if (currentLang) {
|
|
578
|
-
params.append('lang', currentLang);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
const homeUrl = (window as any).forgeWpHydration?.siteSettings?.options?.home || '';
|
|
582
|
-
let apiBase = '';
|
|
583
|
-
if (homeUrl) {
|
|
584
|
-
try {
|
|
585
|
-
apiBase = new URL(homeUrl).pathname.replace(new RegExp('/$'), '');
|
|
586
|
-
} catch (e) {}
|
|
587
|
-
}
|
|
588
|
-
const fetchUrl = \`\${apiBase}/wp-json/wp/v2/\${endpoint}?\${params.toString()}\`;
|
|
589
|
-
console.log(\`[useWpQuery] Fetching CPT "\${postType}" from URL:\`, fetchUrl);
|
|
590
|
-
const response = await fetch(fetchUrl);
|
|
591
|
-
if (!response.ok) {
|
|
592
|
-
throw new Error(
|
|
593
|
-
\`WordPress API returned \${response.status}: \${response.statusText}\`,
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
const data = await response.json();
|
|
598
|
-
if (!Array.isArray(data)) {
|
|
599
|
-
throw new Error('Invalid response format from WordPress API');
|
|
600
|
-
}
|
|
601
|
-
console.log(\`[useWpQuery] Successfully loaded \${data.length} items for CPT "\${postType}"\`);
|
|
602
|
-
|
|
603
|
-
const cleanHtml = (html: string) => {
|
|
604
|
-
if (!html) return '';
|
|
605
|
-
return decodeHtmlEntities(html.replace(/<\\/?[^>]+(>|$)/g, '')).trim();
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
const mappedPosts: WpPost[] = data.map((wp: any) => {
|
|
609
|
-
let featuredImage = 'https://picsum.photos/seed/forgewp/1200/630';
|
|
610
|
-
if (
|
|
611
|
-
wp._embedded &&
|
|
612
|
-
wp._embedded['wp:featuredmedia'] &&
|
|
613
|
-
wp._embedded['wp:featuredmedia'][0]
|
|
614
|
-
) {
|
|
615
|
-
const media = wp._embedded['wp:featuredmedia'][0];
|
|
616
|
-
featuredImage = media.source_url || featuredImage;
|
|
617
|
-
} else if (wp.featured_media_src_url) {
|
|
618
|
-
featuredImage = wp.featured_media_src_url;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// Build _terms from embedded wp:term taxonomy groups
|
|
622
|
-
const _terms: Record<string, any[]> = {};
|
|
623
|
-
if (wp._embedded && wp._embedded['wp:term']) {
|
|
624
|
-
for (const termGroup of wp._embedded['wp:term']) {
|
|
625
|
-
if (Array.isArray(termGroup) && termGroup.length > 0) {
|
|
626
|
-
const taxonomy = termGroup[0].taxonomy;
|
|
627
|
-
if (taxonomy) {
|
|
628
|
-
_terms[taxonomy] = termGroup.map((t: any) => ({
|
|
629
|
-
id: t.id,
|
|
630
|
-
slug: t.slug,
|
|
631
|
-
name: typeof t.name === 'string' ? decodeHtmlEntities(t.name) : '',
|
|
632
|
-
}));
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
return {
|
|
639
|
-
id: wp.id,
|
|
640
|
-
title:
|
|
641
|
-
typeof wp.title === 'object' ? decodeHtmlEntities(wp.title.rendered) : decodeHtmlEntities(wp.title || ''),
|
|
642
|
-
excerpt:
|
|
643
|
-
typeof wp.excerpt === 'object'
|
|
644
|
-
? cleanHtml(wp.excerpt.rendered)
|
|
645
|
-
: cleanHtml(wp.excerpt || ''),
|
|
646
|
-
content:
|
|
647
|
-
typeof wp.content === 'object'
|
|
648
|
-
? wp.content.rendered
|
|
649
|
-
: wp.content || '',
|
|
650
|
-
date: wp.date
|
|
651
|
-
? new Date(wp.date).toLocaleDateString('en-US', {
|
|
652
|
-
year: 'numeric',
|
|
653
|
-
month: 'long',
|
|
654
|
-
day: 'numeric',
|
|
655
|
-
})
|
|
656
|
-
: '',
|
|
657
|
-
author:
|
|
658
|
-
wp._embedded &&
|
|
659
|
-
wp._embedded['author'] &&
|
|
660
|
-
wp._embedded['author'][0]
|
|
661
|
-
? wp._embedded['author'][0].name
|
|
662
|
-
: 'Admin',
|
|
663
|
-
featuredImage,
|
|
664
|
-
permalink: wp.link,
|
|
665
|
-
customFields: { ...(wp.acf || {}), ...(wp.meta || {}) },
|
|
666
|
-
_terms,
|
|
667
|
-
__postType: wp.type || postType,
|
|
668
|
-
};
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
const totalPagesHeader = response.headers.get('X-WP-TotalPages');
|
|
672
|
-
const totalPages = totalPagesHeader
|
|
673
|
-
? parseInt(totalPagesHeader, 10)
|
|
674
|
-
: 1;
|
|
675
|
-
|
|
676
|
-
if (page === 1) {
|
|
677
|
-
setPosts(mappedPosts);
|
|
678
|
-
} else {
|
|
679
|
-
setPosts((prev) => [...prev, ...mappedPosts]);
|
|
680
|
-
}
|
|
681
|
-
setHasMore(page < totalPages && mappedPosts.length > 0);
|
|
682
|
-
setError(null);
|
|
683
|
-
} catch (err: any) {
|
|
684
|
-
setError(err.message || 'Failed to fetch from WordPress API');
|
|
685
|
-
} finally {
|
|
686
|
-
setLoading(false);
|
|
687
|
-
}
|
|
688
|
-
},
|
|
689
|
-
[postType, postsPerPage, categoryName, s, orderby, order],
|
|
690
|
-
);
|
|
691
|
-
|
|
692
|
-
React.useEffect(() => {
|
|
693
|
-
executeProdQuery(currentPage);
|
|
694
|
-
}, [executeProdQuery, currentPage]);
|
|
695
|
-
|
|
696
|
-
const loadMore = React.useCallback(async () => {
|
|
697
|
-
if (loading || !hasMore) return;
|
|
698
|
-
const nextPage = currentPage + 1;
|
|
699
|
-
setCurrentPage(nextPage);
|
|
700
|
-
}, [currentPage, loading, hasMore]);
|
|
701
|
-
|
|
702
|
-
const refetch = React.useCallback(async () => {
|
|
703
|
-
setCurrentPage(1);
|
|
704
|
-
executeProdQuery(1);
|
|
705
|
-
}, [executeProdQuery]);
|
|
706
|
-
|
|
707
|
-
return {
|
|
708
|
-
posts,
|
|
709
|
-
loading,
|
|
710
|
-
error,
|
|
711
|
-
hasMore,
|
|
712
|
-
loadMore,
|
|
713
|
-
refetch,
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
export function useWpCategories(): string {
|
|
718
|
-
if (IS_DEV) return '<a href="#">Technology</a>, <a href="#">Design</a>';
|
|
719
|
-
return '__FORGEWP_THE_CATEGORY_LIST__';
|
|
720
|
-
}
|
|
721
|
-
export function useWpArchiveTitle(): string {
|
|
722
|
-
if (IS_DEV) return 'Category: Technology';
|
|
723
|
-
return '__FORGEWP_THE_ARCHIVE_TITLE__';
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
export function useWpTaxonomyList(taxonomy: string, defaultValue = ''): string {
|
|
727
|
-
if (IS_DEV) {
|
|
728
|
-
const post = React.useContext(WpPostContext);
|
|
729
|
-
const terms = (post as any)?._terms?.[taxonomy];
|
|
730
|
-
if (Array.isArray(terms) && terms.length > 0) {
|
|
731
|
-
return terms.map((t: any) => t.name).join(', ');
|
|
732
|
-
}
|
|
733
|
-
return defaultValue || \`[taxonomy: \${taxonomy}]\`;
|
|
734
|
-
}
|
|
735
|
-
return \`__FORGEWP_TAXONOMY_LIST_\${taxonomy}__\`;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// ── useWpTerms — fetch all terms for a given taxonomy ─────────────────────────
|
|
739
|
-
// Dev: reads \`_taxonomy_<name>\` key from mock-data.json
|
|
740
|
-
// SSR: returns [] synchronously (Hydrate island loads in browser)
|
|
741
|
-
// Prod: fetches /wp-json/wp/v2/<taxonomy>?per_page=100
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const readTemplate = (name) => fs.readFileSync(path.join(__dirname, '..', 'templates', name), 'utf8');
|
|
742
7
|
|
|
743
|
-
export
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
export function useWpTerms(taxonomy: string): { terms: WpTerm[]; loading: boolean; error: string | null } {
|
|
753
|
-
if (IS_DEV) {
|
|
754
|
-
const raw: any[] = (mockData as any)?.[\`_taxonomy_\${taxonomy}\`] || [];
|
|
755
|
-
const terms: WpTerm[] = raw.map((t: any) => ({
|
|
756
|
-
id: t.id ?? 0,
|
|
757
|
-
name: t.name ?? '',
|
|
758
|
-
slug: t.slug ?? '',
|
|
759
|
-
description: t.description ?? '',
|
|
760
|
-
count: t.count ?? 0,
|
|
761
|
-
meta: t.meta ?? {},
|
|
762
|
-
}));
|
|
763
|
-
return { terms, loading: false, error: null };
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
// Node SSR — return empty; Hydrate wrapper will load in browser
|
|
767
|
-
if (typeof window === 'undefined') {
|
|
768
|
-
return { terms: [], loading: false, error: null };
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
// Browser production — live WP REST API fetch
|
|
772
|
-
const [terms, setTerms] = React.useState<WpTerm[]>([]);
|
|
773
|
-
const [loading, setLoading] = React.useState(true);
|
|
774
|
-
const [error, setError] = React.useState<string | null>(null);
|
|
775
|
-
|
|
776
|
-
React.useEffect(() => {
|
|
777
|
-
let cancelled = false;
|
|
778
|
-
const endpoint = taxonomy === 'category' ? 'categories' : taxonomy === 'post_tag' ? 'tags' : taxonomy;
|
|
779
|
-
const homeUrl = (window as any).forgeWpHydration?.siteSettings?.options?.home || '';
|
|
780
|
-
let apiBase = '';
|
|
781
|
-
if (homeUrl) {
|
|
782
|
-
try {
|
|
783
|
-
apiBase = new URL(homeUrl).pathname.replace(new RegExp('/$'), '');
|
|
784
|
-
} catch (e) {}
|
|
785
|
-
}
|
|
786
|
-
const currentLang = (window as any).forgeWpLocale || (window as any).forgeWpTranslations?.currentLanguage;
|
|
787
|
-
const langParam = currentLang ? \`&lang=\${currentLang}\` : '';
|
|
788
|
-
const fetchUrl = \`\${apiBase}/wp-json/wp/v2/\${endpoint}?per_page=100&_fields=id,name,slug,description,count,acf,meta\${langParam}\`;
|
|
789
|
-
console.log(\`[useWpTerms] Fetching taxonomy "\${taxonomy}" from URL:\`, fetchUrl);
|
|
790
|
-
fetch(fetchUrl)
|
|
791
|
-
.then((res) => {
|
|
792
|
-
if (!res.ok) throw new Error(\`WP Terms API \${taxonomy}: \${res.status}\`);
|
|
793
|
-
return res.json();
|
|
794
|
-
})
|
|
795
|
-
.then((data: any[]) => {
|
|
796
|
-
if (cancelled) return;
|
|
797
|
-
console.log(\`[useWpTerms] Successfully loaded \${data.length} terms for taxonomy "\${taxonomy}"\`);
|
|
798
|
-
setTerms(
|
|
799
|
-
data.map((t) => ({
|
|
800
|
-
id: t.id,
|
|
801
|
-
name: typeof t.name === 'string' ? decodeHtmlEntities(t.name) : '',
|
|
802
|
-
slug: t.slug || '',
|
|
803
|
-
description: t.description || '',
|
|
804
|
-
count: t.count || 0,
|
|
805
|
-
meta: { ...(t.acf || {}), ...(t.meta || {}) },
|
|
806
|
-
}))
|
|
807
|
-
);
|
|
808
|
-
setError(null);
|
|
809
|
-
})
|
|
810
|
-
.catch((err: any) => {
|
|
811
|
-
if (!cancelled) {
|
|
812
|
-
console.error(\`[useWpTerms] Error loading taxonomy "\${taxonomy}":\`, err);
|
|
813
|
-
setError(err.message || \`Failed to load \${taxonomy} terms\`);
|
|
814
|
-
}
|
|
815
|
-
})
|
|
816
|
-
.finally(() => {
|
|
817
|
-
if (!cancelled) setLoading(false);
|
|
818
|
-
});
|
|
819
|
-
return () => { cancelled = true; };
|
|
820
|
-
}, [taxonomy]);
|
|
821
|
-
|
|
822
|
-
return { terms, loading, error };
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
// ── WpQueryLoop — data bridge wraps @forgewp/react with mock data ─────────────
|
|
828
|
-
|
|
829
|
-
export function WpQueryLoop({
|
|
830
|
-
postType = 'post',
|
|
831
|
-
postsPerPage = 3,
|
|
832
|
-
categoryName = '',
|
|
833
|
-
children,
|
|
834
|
-
}: WpQueryLoopProps) {
|
|
835
|
-
if (IS_DEV) {
|
|
836
|
-
const posts = (mockData as any)?.[postType] || [];
|
|
837
|
-
return (
|
|
838
|
-
<_WpQueryLoop
|
|
839
|
-
posts={posts}
|
|
840
|
-
postType={postType}
|
|
841
|
-
postsPerPage={postsPerPage}
|
|
842
|
-
categoryName={categoryName}
|
|
843
|
-
>
|
|
844
|
-
{children}
|
|
845
|
-
</_WpQueryLoop>
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
// Production: compiler transforms these custom elements into WordPress loop PHP
|
|
850
|
-
return (
|
|
851
|
-
<>
|
|
852
|
-
{/* @ts-ignore */}
|
|
853
|
-
<forgewp-query-loop-start
|
|
854
|
-
postType={postType}
|
|
855
|
-
postsPerPage={postsPerPage}
|
|
856
|
-
categoryName={categoryName}
|
|
857
|
-
/>
|
|
858
|
-
{children}
|
|
859
|
-
{/* @ts-ignore */}
|
|
860
|
-
<forgewp-query-loop-end />
|
|
861
|
-
</>
|
|
862
|
-
);
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
// ── WpLoop — simple all-posts loop (no postType arg) ─────────────────────────
|
|
866
|
-
|
|
867
|
-
export function WpLoop({ children }: { children: React.ReactNode }) {
|
|
868
|
-
if (IS_DEV) {
|
|
869
|
-
const posts = (mockData as any)?.post || [];
|
|
870
|
-
return <_WpQueryLoop posts={posts}>{children}</_WpQueryLoop>;
|
|
871
|
-
}
|
|
872
|
-
return (
|
|
873
|
-
<>
|
|
874
|
-
{/* @ts-ignore */}
|
|
875
|
-
<forgewp-loop-start />
|
|
876
|
-
{children}
|
|
877
|
-
{/* @ts-ignore */}
|
|
878
|
-
<forgewp-loop-end />
|
|
879
|
-
</>
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
// ── WpMenu — data bridge wraps @forgewp/react with menus.json ────────────────
|
|
884
|
-
|
|
885
|
-
export function WpMenu({
|
|
886
|
-
location = 'primary',
|
|
887
|
-
className = '',
|
|
888
|
-
linkClassName = '',
|
|
889
|
-
}: WpMenuProps) {
|
|
890
|
-
if (IS_DEV) {
|
|
891
|
-
const items = (menusData as any)?.[location] ||
|
|
892
|
-
(mockData as any).menu?.[location] || [
|
|
893
|
-
{ title: 'Home', url: '/' },
|
|
894
|
-
{ title: 'Blog', url: '/post' },
|
|
895
|
-
];
|
|
896
|
-
return (
|
|
897
|
-
<_WpMenu
|
|
898
|
-
items={items}
|
|
899
|
-
location={location}
|
|
900
|
-
className={className}
|
|
901
|
-
linkClassName={linkClassName}
|
|
902
|
-
/>
|
|
903
|
-
);
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
// Production browser hydration client: render menu items from localized PHP data
|
|
907
|
-
if (typeof window !== "undefined" && !(window as any)._forgeWpCompileTime) {
|
|
908
|
-
const items = (window as any).forgeWpHydration?.menus?.[location] || [];
|
|
909
|
-
if (items.length > 0) {
|
|
910
|
-
return (
|
|
911
|
-
<nav className={className}>
|
|
912
|
-
{items.map((item: any, idx: number) => (
|
|
913
|
-
<a key={idx} href={item.url} className={linkClassName}>
|
|
914
|
-
{item.title}
|
|
915
|
-
</a>
|
|
916
|
-
))}
|
|
917
|
-
</nav>
|
|
918
|
-
);
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
// Server-matching fallback nav to guarantee zero hydration mismatch
|
|
922
|
-
return (
|
|
923
|
-
<nav className={className}>
|
|
924
|
-
<a href="/" className={linkClassName}>
|
|
925
|
-
Home
|
|
926
|
-
</a>
|
|
927
|
-
</nav>
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
// Production: compiler transforms this into wp_nav_menu()
|
|
932
|
-
return (
|
|
933
|
-
// @ts-ignore
|
|
934
|
-
<forgewp-menu
|
|
935
|
-
location={location}
|
|
936
|
-
className={className}
|
|
937
|
-
linkClassName={linkClassName}
|
|
938
|
-
/>
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
// ── BlockArea ────────────────────────────────────────────────────────────────
|
|
943
|
-
export function BlockArea(props: BlockAreaProps) {
|
|
944
|
-
if (IS_DEV) {
|
|
945
|
-
return <_BlockArea {...props} />;
|
|
946
|
-
}
|
|
947
|
-
return (
|
|
948
|
-
// @ts-ignore
|
|
949
|
-
<forgewp-block-area name={props.name} />
|
|
950
|
-
);
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// ── WpShortcode ──────────────────────────────────────────────────────────────
|
|
954
|
-
export function WpShortcode({ code }: WpShortcodeProps) {
|
|
955
|
-
if (IS_DEV) {
|
|
956
|
-
return <_WpShortcode code={code} />;
|
|
957
|
-
}
|
|
958
|
-
return (
|
|
959
|
-
// @ts-ignore
|
|
960
|
-
<forgewp-shortcode code={code} />
|
|
961
|
-
);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
export function WpHead(props: WpHeadProps) {
|
|
965
|
-
if (IS_DEV) {
|
|
966
|
-
return <_WpHead {...props} />;
|
|
967
|
-
}
|
|
968
|
-
return (
|
|
969
|
-
// @ts-ignore
|
|
970
|
-
<forgewp-head
|
|
971
|
-
data-title={props.title}
|
|
972
|
-
data-description={props.description}
|
|
973
|
-
data-keywords={props.keywords}
|
|
974
|
-
data-og-title={props.ogTitle}
|
|
975
|
-
data-og-description={props.ogDescription}
|
|
976
|
-
data-og-image={props.ogImage}
|
|
977
|
-
data-og-type={props.ogType}
|
|
978
|
-
data-twitter-card={props.twitterCard}
|
|
979
|
-
data-twitter-creator={props.twitterCreator}
|
|
980
|
-
data-canonical={props.canonical}
|
|
981
|
-
/>
|
|
982
|
-
);
|
|
983
|
-
}
|
|
984
|
-
export type { WpHeadProps, WpImageProps, WpAttachment, WpRepeaterProps, WpIconProps };
|
|
985
|
-
|
|
986
|
-
export function WpImage(props: WpImageProps) {
|
|
987
|
-
if (IS_DEV) {
|
|
988
|
-
const attachments = (mockData as any)?.attachment || [];
|
|
989
|
-
return (
|
|
990
|
-
<_WpImage
|
|
991
|
-
{...props}
|
|
992
|
-
attachments={attachments}
|
|
993
|
-
/>
|
|
994
|
-
);
|
|
995
|
-
}
|
|
996
|
-
return <_WpImage {...props} />;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
// ── Routing Wrappers for Dev SPA vs Production Multi-Page WordPress ───────────
|
|
1000
|
-
|
|
1001
|
-
export function WpLink({ href, className, children, ...props }: any) {
|
|
1002
|
-
if (IS_DEV) {
|
|
1003
|
-
return (
|
|
1004
|
-
<WouterLink href={href} className={className} {...props}>
|
|
1005
|
-
{children}
|
|
1006
|
-
</WouterLink>
|
|
1007
|
-
);
|
|
1008
|
-
}
|
|
1009
|
-
return (
|
|
1010
|
-
<a href={href} className={className} {...props}>
|
|
1011
|
-
{children}
|
|
1012
|
-
</a>
|
|
1013
|
-
);
|
|
1014
|
-
}
|
|
1015
|
-
export { WpLink as Link };
|
|
1016
|
-
|
|
1017
|
-
export function useWpI18n() {
|
|
1018
|
-
const getTranslatedText = (text: string) => {
|
|
1019
|
-
if (typeof window === "undefined") {
|
|
1020
|
-
return text;
|
|
1021
|
-
}
|
|
1022
|
-
const currentLang = (window as any).forgeWpLocale || (window as any).forgeWpTranslations?.currentLanguage || 'de';
|
|
1023
|
-
const dict = (window as any).forgeWpTranslations?.translations;
|
|
1024
|
-
|
|
1025
|
-
if (dict) {
|
|
1026
|
-
// 1. Nested dictionary format: { de: { ... }, en: { ... } }
|
|
1027
|
-
if (dict[currentLang] && typeof dict[currentLang][text] !== "undefined") {
|
|
1028
|
-
return dict[currentLang][text];
|
|
1029
|
-
}
|
|
1030
|
-
// 2. Flat enqueued active locale format: { 'Kontakt': 'Kontakt' }
|
|
1031
|
-
if (typeof dict[text] !== "undefined") {
|
|
1032
|
-
return dict[text];
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
return text;
|
|
1036
|
-
};
|
|
1037
|
-
|
|
1038
|
-
if (IS_DEV) {
|
|
1039
|
-
return {
|
|
1040
|
-
__: (text: string) => {
|
|
1041
|
-
if (typeof window === "undefined") {
|
|
1042
|
-
return text;
|
|
1043
|
-
}
|
|
1044
|
-
const pathname = window.location.pathname;
|
|
1045
|
-
const translations = translationsData || {};
|
|
1046
|
-
const languages = Object.keys(translations).length > 0 ? Object.keys(translations) : ['de', 'en'];
|
|
1047
|
-
const defaultLanguage = languages[0] || 'de';
|
|
1048
|
-
|
|
1049
|
-
const matchedLang = languages.find(lang => {
|
|
1050
|
-
if (lang === defaultLanguage) return false;
|
|
1051
|
-
return pathname.startsWith(\`/\${lang}/\`) || pathname === \`/\${lang}\`;
|
|
1052
|
-
});
|
|
1053
|
-
const currentLang = matchedLang || defaultLanguage;
|
|
1054
|
-
|
|
1055
|
-
const dict = (translationsData as any)?.[currentLang];
|
|
1056
|
-
if (dict && typeof dict[text] !== "undefined") {
|
|
1057
|
-
return dict[text];
|
|
1058
|
-
}
|
|
1059
|
-
return text;
|
|
1060
|
-
}
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
// Node SSR (Compile-time): return the token so the compiler can perform string replacement
|
|
1064
|
-
if (typeof window === "undefined" || (window as any)._forgeWpCompileTime) {
|
|
1065
|
-
return {
|
|
1066
|
-
__: (text: string) => \`__FORGEWP_I18N_\${text}__\`,
|
|
1067
|
-
};
|
|
1068
|
-
}
|
|
1069
|
-
// Production Browser (Hydration & Client-side rendering):
|
|
1070
|
-
return {
|
|
1071
|
-
__: getTranslatedText,
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
export function useWpLocation() {
|
|
1076
|
-
if (IS_DEV) {
|
|
1077
|
-
return useWouterLocation();
|
|
1078
|
-
}
|
|
1079
|
-
const [loc] = React.useState(typeof window !== "undefined" ? window.location.pathname : "/");
|
|
1080
|
-
const navigate = React.useCallback((to: string) => {
|
|
1081
|
-
if (typeof window !== "undefined") {
|
|
1082
|
-
window.location.href = to;
|
|
1083
|
-
}
|
|
1084
|
-
}, []);
|
|
1085
|
-
return [loc, navigate] as const;
|
|
1086
|
-
}
|
|
1087
|
-
export { useWpLocation as useLocation };
|
|
1088
|
-
|
|
1089
|
-
export function useWpSearch() {
|
|
1090
|
-
if (IS_DEV) {
|
|
1091
|
-
return useWouterSearch();
|
|
1092
|
-
}
|
|
1093
|
-
if (typeof window === "undefined") {
|
|
1094
|
-
return "";
|
|
1095
|
-
}
|
|
1096
|
-
return window.location.search;
|
|
1097
|
-
}
|
|
1098
|
-
export { useWpSearch as useSearch };
|
|
1099
|
-
|
|
1100
|
-
export function useWpLanguage() {
|
|
1101
|
-
if (IS_DEV) {
|
|
1102
|
-
const translations = translationsData || {};
|
|
1103
|
-
const languages = Object.keys(translations).length > 0 ? Object.keys(translations) : ['de', 'en'];
|
|
1104
|
-
const defaultLanguage = languages[0] || 'de';
|
|
1105
|
-
|
|
1106
|
-
const pathname = typeof window !== 'undefined' ? window.location.pathname : '/';
|
|
1107
|
-
// Find if the path starts with one of the non-default languages, e.g. "/en" or "/en/"
|
|
1108
|
-
const matchedLang = languages.find(lang => {
|
|
1109
|
-
if (lang === defaultLanguage) return false;
|
|
1110
|
-
return pathname.startsWith(\`/\${lang}/\`) || pathname === \`/\${lang}\`;
|
|
1111
|
-
});
|
|
1112
|
-
const currentLanguage = matchedLang || defaultLanguage;
|
|
1113
|
-
|
|
1114
|
-
// Generate URLs dynamically
|
|
1115
|
-
const urls: Record<string, string> = {};
|
|
1116
|
-
const homeUrls: Record<string, string> = {};
|
|
1117
|
-
languages.forEach(lang => {
|
|
1118
|
-
const url = lang === defaultLanguage ? '/' : \`/\${lang}/\`;
|
|
1119
|
-
urls[lang] = url;
|
|
1120
|
-
homeUrls[lang] = url;
|
|
1121
|
-
});
|
|
1122
|
-
|
|
1123
|
-
const homeUrl = homeUrls[currentLanguage] || '/';
|
|
1124
|
-
|
|
1125
|
-
const switchLanguage = React.useCallback((lang: string) => {
|
|
1126
|
-
if (typeof window !== 'undefined') {
|
|
1127
|
-
window.location.href = urls[lang] || (lang === defaultLanguage ? '/' : \`/\${lang}/\`);
|
|
1128
|
-
}
|
|
1129
|
-
}, [urls, defaultLanguage]);
|
|
1130
|
-
|
|
1131
|
-
return {
|
|
1132
|
-
currentLanguage,
|
|
1133
|
-
languages,
|
|
1134
|
-
urls,
|
|
1135
|
-
homeUrls,
|
|
1136
|
-
homeUrl,
|
|
1137
|
-
switchLanguage,
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
const translations = typeof window !== 'undefined' ? (window as any).forgeWpTranslations : null;
|
|
1142
|
-
|
|
1143
|
-
// Dynamic current language slug enqueued by WordPress
|
|
1144
|
-
const currentLanguage = translations?.currentLanguage || 'de';
|
|
1145
|
-
|
|
1146
|
-
// Dynamic dictionary mapping active language slugs to translation counterpart URLs
|
|
1147
|
-
const urls: Record<string, string> = translations?.urls || { de: '/' };
|
|
1148
|
-
|
|
1149
|
-
// Dynamic dictionary mapping active language slugs to home page URLs
|
|
1150
|
-
const homeUrls: Record<string, string> = translations?.homeUrls || { de: '/' };
|
|
1151
|
-
const homeUrl = homeUrls[currentLanguage] || '/';
|
|
1152
|
-
|
|
1153
|
-
// Dynamic list of active language slugs enqueued on the site
|
|
1154
|
-
const languages = React.useMemo(() => Object.keys(urls), [urls]);
|
|
1155
|
-
|
|
1156
|
-
// Redirection helper to switch safely between languages
|
|
1157
|
-
const switchLanguage = React.useCallback((lang: string) => {
|
|
1158
|
-
if (typeof window !== 'undefined') {
|
|
1159
|
-
if (urls && urls[lang]) {
|
|
1160
|
-
window.location.href = urls[lang];
|
|
1161
|
-
} else {
|
|
1162
|
-
window.location.href = lang === 'de' ? '/' : \`/\${lang}/\`;
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
}, [urls]);
|
|
1166
|
-
|
|
1167
|
-
return {
|
|
1168
|
-
currentLanguage,
|
|
1169
|
-
languages,
|
|
1170
|
-
urls,
|
|
1171
|
-
homeUrls,
|
|
1172
|
-
homeUrl,
|
|
1173
|
-
switchLanguage,
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
// ── Compiler custom element JSX declarations ──────────────────────────────────
|
|
1179
|
-
|
|
1180
|
-
declare global {
|
|
1181
|
-
namespace React {
|
|
1182
|
-
namespace JSX {
|
|
1183
|
-
interface IntrinsicElements {
|
|
1184
|
-
'forgewp-menu': React.DetailedHTMLProps<
|
|
1185
|
-
React.HTMLAttributes<HTMLElement> & {
|
|
1186
|
-
location?: 'primary' | 'footer' | 'sidebar' | string;
|
|
1187
|
-
linkClassName?: string;
|
|
1188
|
-
},
|
|
1189
|
-
HTMLElement
|
|
1190
|
-
>;
|
|
1191
|
-
'forgewp-query-loop-start': React.DetailedHTMLProps<
|
|
1192
|
-
React.HTMLAttributes<HTMLElement> & {
|
|
1193
|
-
postType?: string;
|
|
1194
|
-
postsPerPage?: number;
|
|
1195
|
-
categoryName?: string;
|
|
1196
|
-
},
|
|
1197
|
-
HTMLElement
|
|
1198
|
-
>;
|
|
1199
|
-
'forgewp-query-loop-end': React.DetailedHTMLProps<
|
|
1200
|
-
React.HTMLAttributes<HTMLElement>,
|
|
1201
|
-
HTMLElement
|
|
1202
|
-
>;
|
|
1203
|
-
'forgewp-loop-start': React.DetailedHTMLProps<
|
|
1204
|
-
React.HTMLAttributes<HTMLElement>,
|
|
1205
|
-
HTMLElement
|
|
1206
|
-
>;
|
|
1207
|
-
'forgewp-loop-end': React.DetailedHTMLProps<
|
|
1208
|
-
React.HTMLAttributes<HTMLElement>,
|
|
1209
|
-
HTMLElement
|
|
1210
|
-
>;
|
|
1211
|
-
'forgewp-shortcode': React.DetailedHTMLProps<
|
|
1212
|
-
React.HTMLAttributes<HTMLElement> & {
|
|
1213
|
-
code?: string;
|
|
1214
|
-
},
|
|
1215
|
-
HTMLElement
|
|
1216
|
-
>;
|
|
1217
|
-
'forgewp-head': React.DetailedHTMLProps<
|
|
1218
|
-
React.HTMLAttributes<HTMLElement> & {
|
|
1219
|
-
'data-title'?: string;
|
|
1220
|
-
'data-description'?: string;
|
|
1221
|
-
'data-keywords'?: string;
|
|
1222
|
-
'data-og-title'?: string;
|
|
1223
|
-
'data-og-description'?: string;
|
|
1224
|
-
'data-og-image'?: string;
|
|
1225
|
-
'data-og-type'?: string;
|
|
1226
|
-
'data-twitter-card'?: string;
|
|
1227
|
-
'data-twitter-creator'?: string;
|
|
1228
|
-
'data-canonical'?: string;
|
|
1229
|
-
},
|
|
1230
|
-
HTMLElement
|
|
1231
|
-
>;
|
|
1232
|
-
'forgewp-image': React.DetailedHTMLProps<
|
|
1233
|
-
React.HTMLAttributes<HTMLElement> & {
|
|
1234
|
-
'data-id'?: string;
|
|
1235
|
-
'data-field'?: string;
|
|
1236
|
-
'data-size'?: string;
|
|
1237
|
-
'data-class-name'?: string;
|
|
1238
|
-
'data-alt'?: string;
|
|
1239
|
-
},
|
|
1240
|
-
HTMLElement
|
|
1241
|
-
>;
|
|
1242
|
-
'forgewp-block-area': React.DetailedHTMLProps<
|
|
1243
|
-
React.HTMLAttributes<HTMLElement> & {
|
|
1244
|
-
name?: string;
|
|
1245
|
-
},
|
|
1246
|
-
HTMLElement
|
|
1247
|
-
>;
|
|
1248
|
-
'forgewp-repeater-start': React.DetailedHTMLProps<
|
|
1249
|
-
React.HTMLAttributes<HTMLElement> & {
|
|
1250
|
-
name?: string;
|
|
1251
|
-
subfields?: string;
|
|
1252
|
-
},
|
|
1253
|
-
HTMLElement
|
|
1254
|
-
>;
|
|
1255
|
-
'forgewp-repeater-end': React.DetailedHTMLProps<
|
|
1256
|
-
React.HTMLAttributes<HTMLElement>,
|
|
1257
|
-
HTMLElement
|
|
1258
|
-
>;
|
|
1259
|
-
'forgewp-icon-placeholder': React.DetailedHTMLProps<
|
|
1260
|
-
React.HTMLAttributes<HTMLElement> & {
|
|
1261
|
-
name?: string;
|
|
1262
|
-
provider?: string;
|
|
1263
|
-
class?: string;
|
|
1264
|
-
},
|
|
1265
|
-
HTMLElement
|
|
1266
|
-
>;
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
`,
|
|
1272
|
-
|
|
1273
|
-
'src/.forgewp/SEO.tsx': `import * as React from "react";
|
|
1274
|
-
import * as ReactHelmetAsync from "react-helmet-async";
|
|
1275
|
-
import { useWpTitle } from "./wordpress";
|
|
1276
|
-
|
|
1277
|
-
const defaultKey = "default";
|
|
1278
|
-
const ReactHelmetLib = (ReactHelmetAsync as any).Helmet
|
|
1279
|
-
? ReactHelmetAsync
|
|
1280
|
-
: (ReactHelmetAsync as any)[defaultKey] ?? ReactHelmetAsync;
|
|
1281
|
-
const Helmet = (ReactHelmetLib as any).Helmet || React.Fragment;
|
|
1282
|
-
|
|
1283
|
-
/**
|
|
1284
|
-
* ForgeWP SEO — Internal system file. Do not delete.
|
|
1285
|
-
*
|
|
1286
|
-
* Use this component in \`src/app/layout.tsx\` to set global SEO defaults,
|
|
1287
|
-
* and in individual page files to override them per-page.
|
|
1288
|
-
*
|
|
1289
|
-
* The ForgeWP compiler reads the props you pass here and injects them
|
|
1290
|
-
* directly into the WordPress theme's <head> as native meta tags.
|
|
1291
|
-
*
|
|
1292
|
-
* @see https://forgewp.dev/docs/seo
|
|
1293
|
-
*/
|
|
1294
|
-
|
|
1295
|
-
export interface SEOProps {
|
|
1296
|
-
/** Page title — defaults to the WordPress post title via useWpTitle() */
|
|
1297
|
-
title?: string;
|
|
1298
|
-
/** Meta description for search engines and social cards */
|
|
1299
|
-
description?: string;
|
|
1300
|
-
/** Comma-separated keywords */
|
|
1301
|
-
keywords?: string;
|
|
1302
|
-
/** Open Graph title (falls back to title if omitted) */
|
|
1303
|
-
ogTitle?: string;
|
|
1304
|
-
/** Open Graph description (falls back to description if omitted) */
|
|
1305
|
-
ogDescription?: string;
|
|
1306
|
-
/** Absolute URL to the Open Graph image */
|
|
1307
|
-
ogImage?: string;
|
|
1308
|
-
/** Open Graph type — "website" for homepages, "article" for posts */
|
|
1309
|
-
ogType?: string;
|
|
1310
|
-
/** Twitter card type */
|
|
1311
|
-
twitterCard?: string;
|
|
1312
|
-
/** Twitter creator handle, e.g. "@username" */
|
|
1313
|
-
twitterCreator?: string;
|
|
1314
|
-
/** Canonical URL — tells search engines the preferred version of this page */
|
|
1315
|
-
canonical?: string;
|
|
1316
|
-
/** Set to true to prevent this page from being indexed by search engines */
|
|
1317
|
-
noIndex?: boolean;
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
/**
|
|
1321
|
-
* \`<SEO>\` — ForgeWP SEO manager.
|
|
1322
|
-
*
|
|
1323
|
-
* Drop this into your **layout.tsx** to set site-wide defaults.
|
|
1324
|
-
* Then drop it into any **page file** to override for that specific template.
|
|
1325
|
-
*
|
|
1326
|
-
* @example
|
|
1327
|
-
* // layout.tsx — global defaults (the compiler reads these for all pages)
|
|
1328
|
-
* <SEO
|
|
1329
|
-
* description="Your site tagline or description."
|
|
1330
|
-
* keywords="WordPress, React, Tailwind"
|
|
1331
|
-
* ogImage="https://yoursite.com/og-default.png"
|
|
1332
|
-
* />
|
|
1333
|
-
*
|
|
1334
|
-
* @example
|
|
1335
|
-
* // single.tsx — per-page override (article-specific metadata)
|
|
1336
|
-
* <SEO
|
|
1337
|
-
* ogType="article"
|
|
1338
|
-
* ogImage="https://yoursite.com/og-post.png"
|
|
1339
|
-
* twitterCreator="@yourhandle"
|
|
1340
|
-
* />
|
|
1341
|
-
*/
|
|
1342
|
-
export function SEO({
|
|
1343
|
-
title,
|
|
1344
|
-
description = "A WordPress theme built with ForgeWP — React & Tailwind CSS.",
|
|
1345
|
-
keywords = "WordPress, React, Tailwind CSS, ForgeWP",
|
|
1346
|
-
ogTitle,
|
|
1347
|
-
ogDescription,
|
|
1348
|
-
ogImage,
|
|
1349
|
-
ogType = "website",
|
|
1350
|
-
twitterCard = "summary_large_image",
|
|
1351
|
-
twitterCreator,
|
|
1352
|
-
canonical,
|
|
1353
|
-
noIndex = false,
|
|
1354
|
-
}: SEOProps) {
|
|
1355
|
-
const wpTitle = useWpTitle();
|
|
1356
|
-
const resolvedTitle = title ?? wpTitle;
|
|
1357
|
-
|
|
1358
|
-
return (
|
|
1359
|
-
<Helmet>
|
|
1360
|
-
{/* ── Primary ── */}
|
|
1361
|
-
<title>{resolvedTitle}</title>
|
|
1362
|
-
<meta name="description" content={description} />
|
|
1363
|
-
{keywords && <meta name="keywords" content={keywords} />}
|
|
1364
|
-
{noIndex && <meta name="robots" content="noindex, nofollow" />}
|
|
1365
|
-
{canonical && <link rel="canonical" href={canonical} />}
|
|
1366
|
-
|
|
1367
|
-
{/* ── Open Graph ── */}
|
|
1368
|
-
<meta property="og:type" content={ogType} />
|
|
1369
|
-
<meta property="og:title" content={ogTitle ?? resolvedTitle} />
|
|
1370
|
-
<meta property="og:description" content={ogDescription ?? description} />
|
|
1371
|
-
{ogImage && <meta property="og:image" content={ogImage} />}
|
|
1372
|
-
|
|
1373
|
-
{/* ── Twitter ── */}
|
|
1374
|
-
<meta name="twitter:card" content={twitterCard} />
|
|
1375
|
-
<meta name="twitter:title" content={ogTitle ?? resolvedTitle} />
|
|
1376
|
-
<meta name="twitter:description" content={ogDescription ?? description} />
|
|
1377
|
-
{ogImage && <meta name="twitter:image" content={ogImage} />}
|
|
1378
|
-
{twitterCreator && <meta name="twitter:creator" content={twitterCreator} />}
|
|
1379
|
-
</Helmet>
|
|
1380
|
-
);
|
|
1381
|
-
}
|
|
1382
|
-
`,
|
|
1383
|
-
|
|
1384
|
-
'src/.forgewp/PresetsStyle.tsx': `import wpConfig from "../../wp.config";
|
|
1385
|
-
|
|
1386
|
-
const IS_DEV =
|
|
1387
|
-
typeof import.meta !== "undefined" &&
|
|
1388
|
-
// @ts-ignore
|
|
1389
|
-
import.meta.env?.DEV === true;
|
|
1390
|
-
|
|
1391
|
-
/**
|
|
1392
|
-
* PresetsStyle component — Internal system component.
|
|
1393
|
-
*
|
|
1394
|
-
* Dynamically injects WordPress-preset CSS Custom Properties and enqueues Google Fonts
|
|
1395
|
-
* during local Vite development, keeping your styles perfectly in sync with WordPress.
|
|
1396
|
-
* In production builds, this returns only the registry-aesthetic design tokens (like --radius)
|
|
1397
|
-
* to keep shadcn components and theme variables responsive to your config.
|
|
1398
|
-
*/
|
|
1399
|
-
export function PresetsStyle() {
|
|
1400
|
-
const themeStyle = wpConfig.style || "forgewp";
|
|
1401
|
-
|
|
1402
|
-
// Production build: only inject custom registry-aesthetic design properties
|
|
1403
|
-
if (!IS_DEV) {
|
|
1404
|
-
const prodCss = \`
|
|
1405
|
-
:root {
|
|
1406
|
-
--radius: \${themeStyle === "forgewp" ? "0px" : "0.5rem"};
|
|
1407
|
-
--radius-sm: calc(var(--radius) - 4px);
|
|
1408
|
-
--radius-md: calc(var(--radius) - 2px);
|
|
1409
|
-
--radius-lg: var(--radius);
|
|
1410
|
-
--border-width: \${themeStyle === "forgewp" ? "2px" : "1px"};
|
|
1411
|
-
--border-color: \${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
|
|
1412
|
-
--shadow-offset: \${themeStyle === "forgewp" ? "4px" : "0px"};
|
|
1413
|
-
}
|
|
1414
|
-
\`;
|
|
1415
|
-
return <style dangerouslySetInnerHTML={{ __html: prodCss }} />;
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
|
-
// Local development fallbacks for WordPress CSS presets
|
|
1419
|
-
const colors = wpConfig.settings?.color?.palette || [];
|
|
1420
|
-
const fontSizes = wpConfig.settings?.typography?.fontSizes || [];
|
|
1421
|
-
const fontFamilies = wpConfig.settings?.typography?.fontFamilies || [];
|
|
1422
|
-
const layout = wpConfig.settings?.layout || {};
|
|
1423
|
-
const googleFonts = wpConfig.settings?.typography?.googleFonts || [];
|
|
1424
|
-
|
|
1425
|
-
// Parse and build Google Fonts href for dev injection
|
|
1426
|
-
const fontsHtml = googleFonts.length > 0
|
|
1427
|
-
? \`<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
1428
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
1429
|
-
<link href="https://fonts.googleapis.com/css2?family=\&{googleFonts.map(f => encodeURIComponent(f)).join("&family=")}&display=swap" rel="stylesheet">\`
|
|
1430
|
-
: "";
|
|
1431
|
-
|
|
1432
|
-
const devCss = \`
|
|
1433
|
-
:root {
|
|
1434
|
-
\${colors.map((c) => "--wp--preset--color--" + c.slug + ": " + c.color + ";").join("\\n ")}
|
|
1435
|
-
\${fontSizes.map((f) => "--wp--preset--font-size--" + f.slug + ": " + f.size + ";").join("\\n ")}
|
|
1436
|
-
\${fontFamilies.map((f) => "--wp--preset--font-family--" + f.slug + ": " + f.fontFamily + ";").join("\\n ")}
|
|
1437
|
-
\${layout.contentSize ? "--wp--style--global--content-size: " + layout.contentSize + ";" : ""}
|
|
1438
|
-
\${layout.wideSize ? "--wp--style--global--wide-size: " + layout.wideSize + ";" : ""}
|
|
1439
|
-
|
|
1440
|
-
/* Registry Aesthetic Mode Custom Properties */
|
|
1441
|
-
--radius: \${themeStyle === "forgewp" ? "0px" : "0.5rem"};
|
|
1442
|
-
--radius-sm: calc(var(--radius) - 4px);
|
|
1443
|
-
--radius-md: calc(var(--radius) - 2px);
|
|
1444
|
-
--radius-lg: var(--radius);
|
|
1445
|
-
--border-width: \${themeStyle === "forgewp" ? "2px" : "1px"};
|
|
1446
|
-
--border-color: \${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
|
|
1447
|
-
--shadow-offset: \${themeStyle === "forgewp" ? "4px" : "0px"};
|
|
1448
|
-
}
|
|
1449
|
-
\`;
|
|
1450
|
-
|
|
1451
|
-
return (
|
|
1452
|
-
<>
|
|
1453
|
-
{fontsHtml && <span dangerouslySetInnerHTML={{ __html: fontsHtml }} />}
|
|
1454
|
-
<style dangerouslySetInnerHTML={{ __html: devCss }} />
|
|
1455
|
-
</>
|
|
1456
|
-
);
|
|
1457
|
-
}
|
|
1458
|
-
`,
|
|
8
|
+
export const SYSTEM_BLUEPRINTS = {
|
|
9
|
+
'cms/menus.json': readTemplate('menus.json'),
|
|
10
|
+
'cms/mock-data.json': readTemplate('mock-data.json'),
|
|
11
|
+
'src/.forgewp/forgewp-config.ts': readTemplate('forgewp-config.ts'),
|
|
12
|
+
'src/.forgewp/wordpress.tsx': readTemplate('wordpress.tsx'),
|
|
13
|
+
'src/.forgewp/SEO.tsx': readTemplate('SEO.tsx'),
|
|
14
|
+
'src/.forgewp/PresetsStyle.tsx': readTemplate('PresetsStyle.tsx'),
|
|
1459
15
|
};
|