@forgewp/compiler 0.4.1 → 0.4.3
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/README.md +11 -3
- package/bin/add.js +15 -6
- package/bin/analyze.js +66 -1
- package/bin/cli.js +20 -12
- package/bin/fresh.js +1 -1
- package/bin/make-block.js +11 -0
- package/bin/make-island.js +11 -0
- package/bin/{make-template.js → make-loop.js} +24 -19
- package/bin/make-page.js +83 -0
- package/bin/make-post-type.js +11 -0
- package/bin/make-sandbox.js +558 -0
- package/bin/sync-hooks.js +221 -0
- package/lib/adapters/html-adapter.js +8 -3
- package/lib/adapters/stub-adapter.js +6 -2
- package/lib/asset-loader.js +22 -0
- package/lib/blueprints.js +122 -1434
- package/lib/functions-builder.js +1172 -3
- package/lib/generate-theme.js +340 -23
- package/lib/hydration-scanner.js +170 -11
- package/lib/index.d.ts +38 -1
- package/lib/index.js +1 -1
- package/lib/load-config.js +98 -0
- package/lib/markup-processor.js +110 -0
- package/lib/page-config-plugin.js +40 -0
- package/lib/php-builders.js +4 -2
- package/lib/react-adapter.js +82 -23
- package/lib/render-theme.mts +115 -25
- package/lib/validate-export.js +49 -0
- package/package.json +4 -2
- package/templates/PresetsStyle.tsx +74 -0
- package/templates/SEO.tsx +109 -0
- package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +133 -0
- package/templates/auth/components/login-form-wrapper.tsx +203 -0
- package/templates/auth/components/reset-password-form-wrapper.tsx +182 -0
- package/templates/auth/components/signup-form-wrapper.tsx +257 -0
- package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
- package/templates/auth/pages/DashboardPage.tsx +15 -0
- package/templates/auth/pages/ForgotPasswordPage.tsx +14 -0
- package/templates/auth/pages/LoginPage.tsx +14 -0
- package/templates/auth/pages/ResetPasswordPage.tsx +14 -0
- package/templates/auth/pages/SignUpPage.tsx +14 -0
- package/templates/auth/pages/VerifyEmailPage.tsx +14 -0
- package/templates/forgewp-config.ts +110 -0
- package/templates/menus.json +11 -0
- package/templates/mock-data.json +123 -0
- package/templates/products.json +5 -0
- package/templates/roles.json +7 -0
- package/templates/sessions.json +1 -0
- package/templates/users.json +34 -0
- package/templates/wordpress.tsx +1390 -0
package/lib/render-theme.mts
CHANGED
|
@@ -45,14 +45,12 @@ if (typeof globalThis.window === "undefined") {
|
|
|
45
45
|
querySelector: () => null,
|
|
46
46
|
querySelectorAll: () => [],
|
|
47
47
|
} as any;
|
|
48
|
+
globalThis.SVGElement = class SVGElement {} as any;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
const { renderToStaticMarkup } = require("react-dom/server");
|
|
51
52
|
|
|
52
53
|
const appUrl = pathToFileURL(path.join(themeRoot, "src", "app", "page.tsx")).href;
|
|
53
|
-
const headerPath = path.join(themeRoot, "src", "components", "SiteHeader.tsx");
|
|
54
|
-
const headerUrl = pathToFileURL(headerPath).href;
|
|
55
|
-
const footerUrl = pathToFileURL(path.join(themeRoot, "src", "components", "SiteFooter.tsx")).href;
|
|
56
54
|
const layoutUrl = pathToFileURL(path.join(themeRoot, "src", "app", "layout.tsx")).href;
|
|
57
55
|
const layoutPath = path.join(themeRoot, "src", "app", "layout.tsx");
|
|
58
56
|
|
|
@@ -106,16 +104,30 @@ function renderPage(PageComponent: any): string {
|
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
let textDomain = "forgewp";
|
|
107
|
+
let themeConfig: any = {};
|
|
109
108
|
try {
|
|
110
109
|
const wpConfigPath = path.join(themeRoot, "wp.config.ts");
|
|
111
110
|
if (existsSync(wpConfigPath)) {
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
const wpConfigUrl = pathToFileURL(wpConfigPath).href;
|
|
112
|
+
const configModule = await import(wpConfigUrl);
|
|
113
|
+
themeConfig = configModule.default || configModule;
|
|
114
|
+
if (themeConfig.textDomain) {
|
|
115
|
+
textDomain = themeConfig.textDomain;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
} catch (e) {
|
|
118
|
+
} catch (e) {
|
|
119
|
+
// fallback if import fails
|
|
120
|
+
try {
|
|
121
|
+
const wpConfigPath = path.join(themeRoot, "wp.config.ts");
|
|
122
|
+
if (existsSync(wpConfigPath)) {
|
|
123
|
+
const configContent = readFileSync(wpConfigPath, "utf8");
|
|
124
|
+
const domainMatch = configContent.match(/textDomain\s*:\s*['"]([^'"]+)['"]/);
|
|
125
|
+
if (domainMatch) {
|
|
126
|
+
textDomain = domainMatch[1];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} catch (e2) {}
|
|
130
|
+
}
|
|
119
131
|
|
|
120
132
|
function translateExpressionToPhp(expression: string, propName: string): string {
|
|
121
133
|
expression = expression.trim();
|
|
@@ -367,42 +379,97 @@ function buildHeadHtml(
|
|
|
367
379
|
}
|
|
368
380
|
|
|
369
381
|
// ── Render header / footer fragments ─────────────────────────────────────────
|
|
370
|
-
|
|
382
|
+
let headerFile = "";
|
|
383
|
+
let headerCompName = "";
|
|
384
|
+
|
|
385
|
+
if (themeConfig.headerPath) {
|
|
386
|
+
const absolutePath = path.isAbsolute(themeConfig.headerPath) ? themeConfig.headerPath : path.join(themeRoot, themeConfig.headerPath);
|
|
387
|
+
if (existsSync(absolutePath)) {
|
|
388
|
+
headerFile = absolutePath;
|
|
389
|
+
headerCompName = path.basename(absolutePath, path.extname(absolutePath));
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (!headerFile) {
|
|
394
|
+
const headerFallbacks = [
|
|
395
|
+
"src/components/SiteHeader.tsx",
|
|
396
|
+
"src/components/Header.tsx",
|
|
397
|
+
"src/components/Navbar.tsx",
|
|
398
|
+
"src/components/NavBar.tsx",
|
|
399
|
+
"src/components/Navigation.tsx"
|
|
400
|
+
];
|
|
401
|
+
for (const relPath of headerFallbacks) {
|
|
402
|
+
const p = path.join(themeRoot, relPath);
|
|
403
|
+
if (existsSync(p)) {
|
|
404
|
+
headerFile = p;
|
|
405
|
+
headerCompName = path.basename(p, path.extname(p));
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
371
410
|
|
|
372
411
|
let headerHtml = "";
|
|
373
|
-
if (
|
|
412
|
+
if (headerFile) {
|
|
374
413
|
try {
|
|
414
|
+
const headerUrl = pathToFileURL(headerFile).href;
|
|
375
415
|
const module = await import(headerUrl);
|
|
376
|
-
const
|
|
377
|
-
if (!
|
|
378
|
-
throw new Error(
|
|
416
|
+
const HeaderComponent = module[headerCompName] || module.default;
|
|
417
|
+
if (!HeaderComponent) {
|
|
418
|
+
throw new Error(`${headerCompName} component not found in export (expects named export '${headerCompName}' or default export).`);
|
|
379
419
|
}
|
|
380
|
-
headerHtml = renderToStaticMarkup(React.createElement(
|
|
420
|
+
headerHtml = renderToStaticMarkup(React.createElement(HeaderComponent));
|
|
381
421
|
} catch (err: any) {
|
|
382
|
-
console.error(`\n[ForgeWP Compiler Error] Failed to load or render the
|
|
422
|
+
console.error(`\n[ForgeWP Compiler Error] Failed to load or render the Header component (${headerFile}).`);
|
|
383
423
|
console.error(`Error details: ${err.stack || err.message || err}\n`);
|
|
384
424
|
process.exit(1);
|
|
385
425
|
}
|
|
386
426
|
} else {
|
|
387
|
-
console.warn("
|
|
427
|
+
console.warn("No separate Header component found, skipping separate header render");
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
let footerFile = "";
|
|
431
|
+
let footerCompName = "";
|
|
432
|
+
|
|
433
|
+
if (themeConfig.footerPath) {
|
|
434
|
+
const absolutePath = path.isAbsolute(themeConfig.footerPath) ? themeConfig.footerPath : path.join(themeRoot, themeConfig.footerPath);
|
|
435
|
+
if (existsSync(absolutePath)) {
|
|
436
|
+
footerFile = absolutePath;
|
|
437
|
+
footerCompName = path.basename(absolutePath, path.extname(absolutePath));
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (!footerFile) {
|
|
442
|
+
const footerFallbacks = [
|
|
443
|
+
"src/components/SiteFooter.tsx",
|
|
444
|
+
"src/components/Footer.tsx"
|
|
445
|
+
];
|
|
446
|
+
for (const relPath of footerFallbacks) {
|
|
447
|
+
const p = path.join(themeRoot, relPath);
|
|
448
|
+
if (existsSync(p)) {
|
|
449
|
+
footerFile = p;
|
|
450
|
+
footerCompName = path.basename(p, path.extname(p));
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
388
454
|
}
|
|
389
455
|
|
|
390
456
|
let footerHtml = "";
|
|
391
|
-
if (
|
|
457
|
+
if (footerFile) {
|
|
392
458
|
try {
|
|
459
|
+
const footerUrl = pathToFileURL(footerFile).href;
|
|
393
460
|
const module = await import(footerUrl);
|
|
394
|
-
const
|
|
395
|
-
if (!
|
|
396
|
-
throw new Error(
|
|
461
|
+
const FooterComponent = module[footerCompName] || module.default;
|
|
462
|
+
if (!FooterComponent) {
|
|
463
|
+
throw new Error(`${footerCompName} component not found in export (expects named export '${footerCompName}' or default export).`);
|
|
397
464
|
}
|
|
398
|
-
footerHtml = renderToStaticMarkup(React.createElement(
|
|
465
|
+
footerHtml = renderToStaticMarkup(React.createElement(FooterComponent));
|
|
399
466
|
} catch (err: any) {
|
|
400
|
-
console.error(`\n[ForgeWP Compiler Error] Failed to load or render the
|
|
467
|
+
console.error(`\n[ForgeWP Compiler Error] Failed to load or render the Footer component (${footerFile}).`);
|
|
401
468
|
console.error(`Error details: ${err.stack || err.message || err}\n`);
|
|
402
469
|
process.exit(1);
|
|
403
470
|
}
|
|
404
471
|
} else {
|
|
405
|
-
console.warn("
|
|
472
|
+
console.warn("No separate Footer component found, skipping separate footer render");
|
|
406
473
|
}
|
|
407
474
|
|
|
408
475
|
// ── Render pages ──────────────────────────────────────────────────────────────
|
|
@@ -442,17 +509,25 @@ if (existsSync(appDir)) {
|
|
|
442
509
|
const module = await import(pathToFileURL(filePath).href);
|
|
443
510
|
const TemplateComponent = module.default;
|
|
444
511
|
if (TemplateComponent) {
|
|
512
|
+
globalThis.__forgewpSsrQueries = {};
|
|
445
513
|
const html = name === "404"
|
|
446
514
|
? renderToStaticMarkup(React.createElement(TemplateComponent))
|
|
447
515
|
: renderPage(TemplateComponent);
|
|
448
516
|
|
|
517
|
+
const ssrState = globalThis.__forgewpSsrQueries || {};
|
|
518
|
+
let stateScript = "";
|
|
519
|
+
if (Object.keys(ssrState).length > 0) {
|
|
520
|
+
stateScript = `\n<script id="forgewp-initial-state" type="application/json">${JSON.stringify({ queries: ssrState })}</script>`;
|
|
521
|
+
}
|
|
522
|
+
|
|
449
523
|
let extraHeadTags = "";
|
|
450
524
|
const cleanHtml = html.replace(/<forgewp-head\b[^>]*>(.*?)<\/forgewp-head>/gs, (match, childrenHtml) => {
|
|
451
525
|
extraHeadTags += "\n" + childrenHtml;
|
|
452
526
|
return "";
|
|
453
527
|
});
|
|
454
528
|
|
|
455
|
-
|
|
529
|
+
const finalHtml = cleanHtml + stateScript;
|
|
530
|
+
writeFileSync(path.join(outDir, `${name}.html`), finalHtml, "utf8");
|
|
456
531
|
console.warn(`[ForgeWP Compiler] WROTE ${name}.html to ${outDir}`);
|
|
457
532
|
|
|
458
533
|
const seoProps = extractSeoPropsFromSource(filePath);
|
|
@@ -498,7 +573,14 @@ if (existsSync(pagesDir)) {
|
|
|
498
573
|
const module = await import(pathToFileURL(pagePath).href);
|
|
499
574
|
const CustomPage = module.default || Object.values(module)[0];
|
|
500
575
|
if (CustomPage) {
|
|
576
|
+
globalThis.__forgewpSsrQueries = {};
|
|
501
577
|
const customHtml = renderPage(CustomPage);
|
|
578
|
+
const ssrState = globalThis.__forgewpSsrQueries || {};
|
|
579
|
+
let stateScript = "";
|
|
580
|
+
if (Object.keys(ssrState).length > 0) {
|
|
581
|
+
stateScript = `\n<script id="forgewp-initial-state" type="application/json">${JSON.stringify({ queries: ssrState })}</script>`;
|
|
582
|
+
}
|
|
583
|
+
|
|
502
584
|
let customExtraHeadTags = "";
|
|
503
585
|
const cleanCustomHtml = customHtml.replace(/<forgewp-head\b[^>]*>(.*?)<\/forgewp-head>/gs, (match, childrenHtml) => {
|
|
504
586
|
customExtraHeadTags += "\n" + childrenHtml;
|
|
@@ -506,7 +588,15 @@ if (existsSync(pagesDir)) {
|
|
|
506
588
|
});
|
|
507
589
|
const pageName = pageFile.replace(".tsx", "");
|
|
508
590
|
const slug = pageName.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
509
|
-
|
|
591
|
+
|
|
592
|
+
let finalHtml = cleanCustomHtml + stateScript;
|
|
593
|
+
if (module.pageConfig && typeof module.pageConfig === "object" && module.pageConfig.protected) {
|
|
594
|
+
const allowedAttr = module.pageConfig.allowed ? ` allowed="${module.pageConfig.allowed}"` : "";
|
|
595
|
+
const redirectAttr = module.pageConfig.redirect ? ` redirect="${module.pageConfig.redirect}"` : "";
|
|
596
|
+
finalHtml = `<forgewp-require-auth${allowedAttr}${redirectAttr}></forgewp-require-auth>` + finalHtml;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
writeFileSync(path.join(outDir, `template-${slug}.html`), finalHtml, "utf8");
|
|
510
600
|
console.warn(`WROTE template-${slug}.html to ${outDir}`);
|
|
511
601
|
|
|
512
602
|
const customSeo = extractSeoPropsFromSource(pagePath);
|
package/lib/validate-export.js
CHANGED
|
@@ -173,6 +173,55 @@ export async function validateExport({ themeRoot, outDir, assets, config, strict
|
|
|
173
173
|
if (!fs.existsSync(screenshotOut)) summary.missing.push(screenshotOut.replace(process.cwd() + path.sep, ''));
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
// WooCommerce Specific Audits
|
|
177
|
+
const packageJsonPath = path.join(themeRoot, 'package.json');
|
|
178
|
+
let isWooCommerce = false;
|
|
179
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
180
|
+
try {
|
|
181
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
182
|
+
isWooCommerce = !!(pkg.dependencies?.['@forgewp/woocommerce'] || pkg.devDependencies?.['@forgewp/woocommerce']);
|
|
183
|
+
} catch (e) {}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (isWooCommerce) {
|
|
187
|
+
if (fs.existsSync(outDir)) {
|
|
188
|
+
const phpFiles = fs.readdirSync(outDir)
|
|
189
|
+
.filter((file) => file.endsWith('.php'))
|
|
190
|
+
.map((file) => path.join(outDir, file));
|
|
191
|
+
|
|
192
|
+
for (const phpFile of phpFiles) {
|
|
193
|
+
const content = fs.readFileSync(phpFile, 'utf8');
|
|
194
|
+
|
|
195
|
+
// 1. XSS / Escaping Audits: Look for unescaped get_price_html()
|
|
196
|
+
if (content.includes('get_price_html()') && !content.includes('wp_kses_post')) {
|
|
197
|
+
summary.warnings.push(`${path.basename(phpFile)}: Found unescaped get_price_html(). Wrap with wp_kses_post() for XSS safety.`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Look for unescaped wc_get_rating_html()
|
|
201
|
+
if (content.includes('wc_get_rating_html') && !content.includes('wp_kses_post')) {
|
|
202
|
+
summary.warnings.push(`${path.basename(phpFile)}: Found unescaped wc_get_rating_html(). Wrap with wp_kses_post() for XSS safety.`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 2. Loop optimization checks
|
|
206
|
+
if (content.includes("post_type' => 'product'") && !content.includes('wc_get_products')) {
|
|
207
|
+
summary.warnings.push(`${path.basename(phpFile)}: Catalog loop should use wc_get_products() pagination wrappers instead of raw post_type => product query.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 3. Hydrator Resource Hygiene check
|
|
213
|
+
const islands = scanForHydrationIslands(themeRoot);
|
|
214
|
+
if (islands.length === 0) {
|
|
215
|
+
const functionsPhpPath = path.join(outDir, 'functions.php');
|
|
216
|
+
if (fs.existsSync(functionsPhpPath)) {
|
|
217
|
+
const functionsPhp = fs.readFileSync(functionsPhpPath, 'utf8');
|
|
218
|
+
if (functionsPhp.includes('forgewp-hydrator.js') || functionsPhp.includes('forgewp-woocommerce')) {
|
|
219
|
+
summary.warnings.push('functions.php: Enqueuing forgewp-hydrator.js or registering woocommerce scripts even though no hydration islands were detected.');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
176
225
|
// If strict, treat warnings as missing
|
|
177
226
|
if (strict && summary.warnings.length > 0) {
|
|
178
227
|
summary.missing.push(...summary.warnings);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgewp/compiler",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Compile ForgeWP React themes into installable WordPress themes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"bin",
|
|
22
22
|
"lib",
|
|
23
|
+
"templates",
|
|
23
24
|
"define-config.js",
|
|
24
25
|
"define-config.d.ts"
|
|
25
26
|
],
|
|
@@ -31,13 +32,14 @@
|
|
|
31
32
|
"jiti": "^2.6.1",
|
|
32
33
|
"picocolors": "^1.1.1",
|
|
33
34
|
"react-helmet-async": "^3.0.0",
|
|
34
|
-
"@forgewp/ui": "0.4.
|
|
35
|
+
"@forgewp/ui": "0.4.2"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/node": "^22.19.19"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"test:export-fixture": "node test/export-fixture/run-export-fixture.js",
|
|
42
|
+
"test:auth-transpilation": "node test/auth-transpilation.js",
|
|
41
43
|
"test:adapter-runtime": "node test/adapter-loader.js",
|
|
42
44
|
"test:adapter-types": "pnpm exec tsc --noEmit -p tsconfig.test.json"
|
|
43
45
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import wpConfig from "../../wp.config";
|
|
2
|
+
|
|
3
|
+
const IS_DEV =
|
|
4
|
+
typeof import.meta !== "undefined" &&
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import.meta.env?.DEV === true;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* PresetsStyle component — Internal system component.
|
|
10
|
+
*
|
|
11
|
+
* Dynamically injects WordPress-preset CSS Custom Properties and enqueues Google Fonts
|
|
12
|
+
* during local Vite development, keeping your styles perfectly in sync with WordPress.
|
|
13
|
+
* In production builds, this returns only the registry-aesthetic design tokens (like --radius)
|
|
14
|
+
* to keep shadcn components and theme variables responsive to your config.
|
|
15
|
+
*/
|
|
16
|
+
export function PresetsStyle() {
|
|
17
|
+
const themeStyle = wpConfig.style || "forgewp";
|
|
18
|
+
|
|
19
|
+
// Production build: only inject custom registry-aesthetic design properties
|
|
20
|
+
if (!IS_DEV) {
|
|
21
|
+
const prodCss = `
|
|
22
|
+
:root {
|
|
23
|
+
--radius: ${themeStyle === "forgewp" ? "0px" : "0.5rem"};
|
|
24
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
25
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
26
|
+
--radius-lg: var(--radius);
|
|
27
|
+
--border-width: ${themeStyle === "forgewp" ? "2px" : "1px"};
|
|
28
|
+
--border-color: ${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
|
|
29
|
+
--shadow-offset: ${themeStyle === "forgewp" ? "4px" : "0px"};
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
return <style dangerouslySetInnerHTML={{ __html: prodCss }} />;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Local development fallbacks for WordPress CSS presets
|
|
36
|
+
const colors = wpConfig.settings?.color?.palette || [];
|
|
37
|
+
const fontSizes = wpConfig.settings?.typography?.fontSizes || [];
|
|
38
|
+
const fontFamilies = wpConfig.settings?.typography?.fontFamilies || [];
|
|
39
|
+
const layout = wpConfig.settings?.layout || {};
|
|
40
|
+
const googleFonts = wpConfig.settings?.typography?.googleFonts || [];
|
|
41
|
+
|
|
42
|
+
// Parse and build Google Fonts href for dev injection
|
|
43
|
+
const fontsHtml = googleFonts.length > 0
|
|
44
|
+
? `<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
45
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
46
|
+
<link href="https://fonts.googleapis.com/css2?family=${googleFonts.map((f: string) => encodeURIComponent(f)).join("&family=")}&display=swap" rel="stylesheet">`
|
|
47
|
+
: "";
|
|
48
|
+
|
|
49
|
+
const devCss = `
|
|
50
|
+
:root {
|
|
51
|
+
${colors.map((c) => "--wp--preset--color--" + c.slug + ": " + c.color + ";").join("\n ")}
|
|
52
|
+
${fontSizes.map((f) => "--wp--preset--font-size--" + f.slug + ": " + f.size + ";").join("\n ")}
|
|
53
|
+
${fontFamilies.map((f) => "--wp--preset--font-family--" + f.slug + ": " + f.fontFamily + ";").join("\n ")}
|
|
54
|
+
${layout.contentSize ? "--wp--style--global--content-size: " + layout.contentSize + ";" : ""}
|
|
55
|
+
${layout.wideSize ? "--wp--style--global--wide-size: " + layout.wideSize + ";" : ""}
|
|
56
|
+
|
|
57
|
+
/* Registry Aesthetic Mode Custom Properties */
|
|
58
|
+
--radius: ${themeStyle === "forgewp" ? "0px" : "0.5rem"};
|
|
59
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
60
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
61
|
+
--radius-lg: var(--radius);
|
|
62
|
+
--border-width: ${themeStyle === "forgewp" ? "2px" : "1px"};
|
|
63
|
+
--border-color: ${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
|
|
64
|
+
--shadow-offset: ${themeStyle === "forgewp" ? "4px" : "0px"};
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
{fontsHtml && <span dangerouslySetInnerHTML={{ __html: fontsHtml }} />}
|
|
71
|
+
<style dangerouslySetInnerHTML={{ __html: devCss }} />
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as ReactHelmetAsync from "react-helmet-async";
|
|
3
|
+
import { useWpTitle } from "./wordpress";
|
|
4
|
+
|
|
5
|
+
const defaultKey = "default";
|
|
6
|
+
const ReactHelmetLib = (ReactHelmetAsync as any).Helmet
|
|
7
|
+
? ReactHelmetAsync
|
|
8
|
+
: (ReactHelmetAsync as any)[defaultKey] ?? ReactHelmetAsync;
|
|
9
|
+
const Helmet = (ReactHelmetLib as any).Helmet || React.Fragment;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* ForgeWP SEO — Internal system file. Do not delete.
|
|
13
|
+
*
|
|
14
|
+
* Use this component in `src/app/layout.tsx` to set global SEO defaults,
|
|
15
|
+
* and in individual page files to override them per-page.
|
|
16
|
+
*
|
|
17
|
+
* The ForgeWP compiler reads the props you pass here and injects them
|
|
18
|
+
* directly into the WordPress theme's <head> as native meta tags.
|
|
19
|
+
*
|
|
20
|
+
* @see https://forgewp.dev/docs/seo
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export interface SEOProps {
|
|
24
|
+
/** Page title — defaults to the WordPress post title via useWpTitle() */
|
|
25
|
+
title?: string;
|
|
26
|
+
/** Meta description for search engines and social cards */
|
|
27
|
+
description?: string;
|
|
28
|
+
/** Comma-separated keywords */
|
|
29
|
+
keywords?: string;
|
|
30
|
+
/** Open Graph title (falls back to title if omitted) */
|
|
31
|
+
ogTitle?: string;
|
|
32
|
+
/** Open Graph description (falls back to description if omitted) */
|
|
33
|
+
ogDescription?: string;
|
|
34
|
+
/** Absolute URL to the Open Graph image */
|
|
35
|
+
ogImage?: string;
|
|
36
|
+
/** Open Graph type — "website" for homepages, "article" for posts */
|
|
37
|
+
ogType?: string;
|
|
38
|
+
/** Twitter card type */
|
|
39
|
+
twitterCard?: string;
|
|
40
|
+
/** Twitter creator handle, e.g. "@username" */
|
|
41
|
+
twitterCreator?: string;
|
|
42
|
+
/** Canonical URL — tells search engines the preferred version of this page */
|
|
43
|
+
canonical?: string;
|
|
44
|
+
/** Set to true to prevent this page from being indexed by search engines */
|
|
45
|
+
noIndex?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* `<SEO>` — ForgeWP SEO manager.
|
|
50
|
+
*
|
|
51
|
+
* Drop this into your **layout.tsx** to set site-wide defaults.
|
|
52
|
+
* Then drop it into any **page file** to override for that specific template.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // layout.tsx — global defaults (the compiler reads these for all pages)
|
|
56
|
+
* <SEO
|
|
57
|
+
* description="Your site tagline or description."
|
|
58
|
+
* keywords="WordPress, React, Tailwind"
|
|
59
|
+
* ogImage="https://yoursite.com/og-default.png"
|
|
60
|
+
* />
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // single.tsx — per-page override (article-specific metadata)
|
|
64
|
+
* <SEO
|
|
65
|
+
* ogType="article"
|
|
66
|
+
* ogImage="https://yoursite.com/og-post.png"
|
|
67
|
+
* twitterCreator="@yourhandle"
|
|
68
|
+
* />
|
|
69
|
+
*/
|
|
70
|
+
export function SEO({
|
|
71
|
+
title,
|
|
72
|
+
description = "A WordPress theme built with ForgeWP — React & Tailwind CSS.",
|
|
73
|
+
keywords = "WordPress, React, Tailwind CSS, ForgeWP",
|
|
74
|
+
ogTitle,
|
|
75
|
+
ogDescription,
|
|
76
|
+
ogImage,
|
|
77
|
+
ogType = "website",
|
|
78
|
+
twitterCard = "summary_large_image",
|
|
79
|
+
twitterCreator,
|
|
80
|
+
canonical,
|
|
81
|
+
noIndex = false,
|
|
82
|
+
}: SEOProps) {
|
|
83
|
+
const wpTitle = useWpTitle();
|
|
84
|
+
const resolvedTitle = title ?? wpTitle;
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Helmet>
|
|
88
|
+
{/* ── Primary ── */}
|
|
89
|
+
<title>{resolvedTitle}</title>
|
|
90
|
+
<meta name="description" content={description} />
|
|
91
|
+
{keywords && <meta name="keywords" content={keywords} />}
|
|
92
|
+
{noIndex && <meta name="robots" content="noindex, nofollow" />}
|
|
93
|
+
{canonical && <link rel="canonical" href={canonical} />}
|
|
94
|
+
|
|
95
|
+
{/* ── Open Graph ── */}
|
|
96
|
+
<meta property="og:type" content={ogType} />
|
|
97
|
+
<meta property="og:title" content={ogTitle ?? resolvedTitle} />
|
|
98
|
+
<meta property="og:description" content={ogDescription ?? description} />
|
|
99
|
+
{ogImage && <meta property="og:image" content={ogImage} />}
|
|
100
|
+
|
|
101
|
+
{/* ── Twitter ── */}
|
|
102
|
+
<meta name="twitter:card" content={twitterCard} />
|
|
103
|
+
<meta name="twitter:title" content={ogTitle ?? resolvedTitle} />
|
|
104
|
+
<meta name="twitter:description" content={ogDescription ?? description} />
|
|
105
|
+
{ogImage && <meta name="twitter:image" content={ogImage} />}
|
|
106
|
+
{twitterCreator && <meta name="twitter:creator" content={twitterCreator} />}
|
|
107
|
+
</Helmet>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useWpUser, useWpAuth } from '@forgewp/auth';
|
|
3
|
+
import { LogOut, User, Mail, Shield, CheckCircle2, XCircle, Code, Key } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
export default function DashboardViewWrapper() {
|
|
6
|
+
const user = useWpUser();
|
|
7
|
+
const { logout, initializing } = useWpAuth();
|
|
8
|
+
const [showRawJson, setShowRawJson] = React.useState(false);
|
|
9
|
+
|
|
10
|
+
if (initializing || !user) {
|
|
11
|
+
return (
|
|
12
|
+
<div className='min-h-screen bg-[#fafafa] flex items-center justify-center font-sans'>
|
|
13
|
+
<div className='flex flex-col items-center gap-4'>
|
|
14
|
+
<div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
|
|
15
|
+
<p className='text-slate-500 font-mono text-sm'>
|
|
16
|
+
Loading your account...
|
|
17
|
+
</p>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const capabilities = user.capabilities || [];
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<main className='min-h-screen bg-[#fafafa] text-slate-900 font-sans py-12 px-6 flex items-center justify-center'>
|
|
27
|
+
<div className='w-full max-w-2xl bg-white border border-slate-200/80 shadow-xs p-8 sm:p-12 relative'>
|
|
28
|
+
|
|
29
|
+
{/* Header Profile Info */}
|
|
30
|
+
<div className='flex flex-col items-center text-center pb-8 border-b border-slate-100'>
|
|
31
|
+
<div className='relative mb-4'>
|
|
32
|
+
<img
|
|
33
|
+
src={user.avatarUrl || `https://picsum.photos/seed/${user.username}/150/150`}
|
|
34
|
+
alt={user.displayName}
|
|
35
|
+
className='w-24 h-24 rounded-full border-4 border-slate-100 object-cover shadow-xs'
|
|
36
|
+
/>
|
|
37
|
+
<div className='absolute bottom-0 right-0 bg-primary border-2 border-white p-1.5 rounded-full text-white shadow-md'>
|
|
38
|
+
<User className='w-3.5 h-3.5' />
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
<h1 className='text-2xl font-heading font-black tracking-tight uppercase text-slate-900'>
|
|
42
|
+
{user.displayName}
|
|
43
|
+
</h1>
|
|
44
|
+
<p className='text-slate-400 font-mono text-xs mt-0.5'>
|
|
45
|
+
@{user.username}
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<div className='flex flex-wrap justify-center gap-1.5 mt-3'>
|
|
49
|
+
{user.roles.map((role) => (
|
|
50
|
+
<span
|
|
51
|
+
key={role}
|
|
52
|
+
className='bg-primary/5 text-primary border border-primary/10 text-[10px] font-mono font-bold uppercase tracking-wider px-2 py-0.5 rounded-sm'
|
|
53
|
+
>
|
|
54
|
+
{role}
|
|
55
|
+
</span>
|
|
56
|
+
))}
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
{/* Detailed Account Grid */}
|
|
61
|
+
<div className='py-8 border-b border-slate-100 grid grid-cols-1 sm:grid-cols-2 gap-6'>
|
|
62
|
+
<div className='flex items-start gap-3'>
|
|
63
|
+
<Shield className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
|
|
64
|
+
<div>
|
|
65
|
+
<p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
|
|
66
|
+
User ID (WordPress)
|
|
67
|
+
</p>
|
|
68
|
+
<p className='text-sm font-mono text-slate-700 font-semibold mt-0.5'>
|
|
69
|
+
#{user.id}
|
|
70
|
+
</p>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<div className='flex items-start gap-3'>
|
|
75
|
+
<Mail className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
|
|
76
|
+
<div className='overflow-hidden'>
|
|
77
|
+
<p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
|
|
78
|
+
Email Address
|
|
79
|
+
</p>
|
|
80
|
+
<p className='text-sm font-semibold text-slate-700 truncate mt-0.5'>
|
|
81
|
+
{user.email}
|
|
82
|
+
</p>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div className='flex items-start gap-3'>
|
|
87
|
+
{user.emailVerified ? (
|
|
88
|
+
<CheckCircle2 className='w-4.5 h-4.5 text-emerald-500 shrink-0 mt-0.5' />
|
|
89
|
+
) : (
|
|
90
|
+
<XCircle className='w-4.5 h-4.5 text-amber-500 shrink-0 mt-0.5' />
|
|
91
|
+
)}
|
|
92
|
+
<div>
|
|
93
|
+
<p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
|
|
94
|
+
Verification Status
|
|
95
|
+
</p>
|
|
96
|
+
<p className={`text-sm font-semibold mt-0.5 ${user.emailVerified ? 'text-emerald-600' : 'text-amber-600'}`}>
|
|
97
|
+
{user.emailVerified ? 'Verified Account' : 'Unverified Account'}
|
|
98
|
+
</p>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div className='flex items-start gap-3'>
|
|
103
|
+
<Key className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
|
|
104
|
+
<div>
|
|
105
|
+
<p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
|
|
106
|
+
Session State
|
|
107
|
+
</p>
|
|
108
|
+
<p className='text-sm font-semibold text-slate-700 mt-0.5'>
|
|
109
|
+
Active
|
|
110
|
+
</p>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
{/* Capabilities Section */}
|
|
116
|
+
{capabilities.length > 0 && (
|
|
117
|
+
<div className='py-8 border-b border-slate-100'>
|
|
118
|
+
<h2 className='text-xs font-mono font-bold uppercase text-slate-400 tracking-wider mb-3'>
|
|
119
|
+
Granted Session Capabilities
|
|
120
|
+
</h2>
|
|
121
|
+
<div className='flex flex-wrap gap-1.5'>
|
|
122
|
+
{capabilities.map((cap) => (
|
|
123
|
+
<span
|
|
124
|
+
key={cap}
|
|
125
|
+
className='bg-slate-50 border border-slate-150 text-slate-600 font-mono text-[11px] px-2.5 py-1 rounded-sm'
|
|
126
|
+
>
|
|
127
|
+
{cap}
|
|
128
|
+
</span>
|
|
129
|
+
))}
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
|
|
134
|
+
{/* Toggleable Raw User JSON explorer */}
|
|
135
|
+
<div className='py-8'>
|
|
136
|
+
<button
|
|
137
|
+
onClick={() => setShowRawJson(!showRawJson)}
|
|
138
|
+
className='flex items-center gap-2 text-slate-500 hover:text-slate-900 text-xs font-mono font-bold uppercase tracking-wider cursor-pointer'
|
|
139
|
+
>
|
|
140
|
+
<Code className='w-4 h-4' />
|
|
141
|
+
{showRawJson ? 'Hide Raw User Object' : 'Show Raw User Object'}
|
|
142
|
+
</button>
|
|
143
|
+
|
|
144
|
+
{showRawJson && (
|
|
145
|
+
<div className='mt-4 bg-slate-50 border border-slate-200 p-4 font-mono text-xs text-slate-600 overflow-x-auto max-h-60 rounded-none leading-relaxed'>
|
|
146
|
+
<pre>{JSON.stringify(user, null, 2)}</pre>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
{/* Footer actions */}
|
|
152
|
+
<div className='pt-6 border-t border-slate-100 flex flex-col sm:flex-row gap-4 items-center justify-between'>
|
|
153
|
+
<p className='text-[11px] text-slate-400 font-mono'>
|
|
154
|
+
Note: Avatars are fetched natively via Gravatar in production.
|
|
155
|
+
</p>
|
|
156
|
+
<button
|
|
157
|
+
onClick={() => logout()}
|
|
158
|
+
className='group inline-flex items-center justify-center bg-white text-slate-900 border border-slate-200 hover:bg-red-50 hover:text-red-600 hover:border-red-200 font-mono font-bold text-xs uppercase tracking-widest px-5 py-3 transition-all duration-200 rounded-none cursor-pointer w-full sm:w-auto'
|
|
159
|
+
>
|
|
160
|
+
<LogOut className='w-4 h-4 mr-2 group-hover:-translate-x-0.5 transition-transform' />
|
|
161
|
+
Log Out
|
|
162
|
+
</button>
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
</div>
|
|
166
|
+
</main>
|
|
167
|
+
);
|
|
168
|
+
}
|