2026-03-25 10:08:46 +07:00
|
|
|
/**
|
|
|
|
|
* SSR entry point for prerendering SEO pages at build time.
|
|
|
|
|
*
|
|
|
|
|
* Used by scripts/prerender-seo.mjs via Vite's ssrLoadModule.
|
|
|
|
|
* Renders each page component to an HTML string so the prerender script
|
|
|
|
|
* can inject it into the static dist/index.html per route.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import { renderToString } from 'react-dom/server';
|
|
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
|
|
|
|
import { SEO_ROUTES } from './seoRoutes';
|
|
|
|
|
|
|
|
|
|
// ── SEO page components ─────────────────────────────────────────────────────
|
2026-04-14 01:22:08 +07:00
|
|
|
import { exampleProjects } from './data/examples';
|
2026-03-25 10:08:46 +07:00
|
|
|
import { ExamplesPage } from './pages/ExamplesPage';
|
2026-04-14 01:22:08 +07:00
|
|
|
import { ExampleDetailPage } from './pages/ExampleDetailPage';
|
2026-03-25 10:08:46 +07:00
|
|
|
|
refactor(routes): OSS is the editor; marketing moves to the overlay
The open-source build now ships exactly its product surface: /editor, the
examples gallery (/examples, /examples/:id) and the per-example editor
(/example/:id). Landing, about, pricing, docs, the 14 keyword-targeted
simulator landings and the v2/v2.5/v3 showcases move to the private
overlay, registered through the same registerProRoutes seam that already
carries login/admin/classroom.
Root behaves per build: an overlay that registers an index route claims
'/' (velxio.dev keeps its landing); otherwise '/' redirects to /editor.
The redirect waits for the overlay import to settle — same contract as
markProExamplesSettled — so a velxio.dev visitor is never bounced into
the editor because the landing was 300ms away from registering.
Prerender and sitemap follow the split: entry-server pulls the marketing
page map from '@pro/pages/marketing' behind a VITE_PRO_BUILD-gated dynamic
import (the proven main.tsx pattern, with an OSS stub for tsc), and
generate-sitemap lists only served routes in OSS builds (2 URLs) while
pro builds stay byte-identical — verified against a pre-migration
baseline: sitemap (37 URLs) and prerendered /, /about, /docs,
/arduino-simulator, /esp32-simulator, /v3 all identical modulo hashed
asset names. OSS prerender drops exactly the 32 marketing pages (348→316).
The OSS header slims down to match: Editor, Examples, GitHub, Discord —
the marketing links only render in pro builds, where their routes exist.
The editor Help menu links those pages absolutely (velxio.dev) in OSS,
exactly like the desktop app's Help menu.
2026-07-30 22:50:14 +07:00
|
|
|
// Map route paths to their React component. The OSS build prerenders only
|
|
|
|
|
// what it ships (the examples gallery); the marketing surface lives in the
|
|
|
|
|
// pro overlay and is merged in by loadRouteComponents() below.
|
|
|
|
|
const OSS_ROUTE_COMPONENTS: Record<string, React.FC> = {
|
2026-03-25 10:08:46 +07:00
|
|
|
'/examples': ExamplesPage,
|
|
|
|
|
};
|
|
|
|
|
|
refactor(routes): OSS is the editor; marketing moves to the overlay
The open-source build now ships exactly its product surface: /editor, the
examples gallery (/examples, /examples/:id) and the per-example editor
(/example/:id). Landing, about, pricing, docs, the 14 keyword-targeted
simulator landings and the v2/v2.5/v3 showcases move to the private
overlay, registered through the same registerProRoutes seam that already
carries login/admin/classroom.
Root behaves per build: an overlay that registers an index route claims
'/' (velxio.dev keeps its landing); otherwise '/' redirects to /editor.
The redirect waits for the overlay import to settle — same contract as
markProExamplesSettled — so a velxio.dev visitor is never bounced into
the editor because the landing was 300ms away from registering.
Prerender and sitemap follow the split: entry-server pulls the marketing
page map from '@pro/pages/marketing' behind a VITE_PRO_BUILD-gated dynamic
import (the proven main.tsx pattern, with an OSS stub for tsc), and
generate-sitemap lists only served routes in OSS builds (2 URLs) while
pro builds stay byte-identical — verified against a pre-migration
baseline: sitemap (37 URLs) and prerendered /, /about, /docs,
/arduino-simulator, /esp32-simulator, /v3 all identical modulo hashed
asset names. OSS prerender drops exactly the 32 marketing pages (348→316).
The OSS header slims down to match: Editor, Examples, GitHub, Discord —
the marketing links only render in pro builds, where their routes exist.
The editor Help menu links those pages absolutely (velxio.dev) in OSS,
exactly like the desktop app's Help menu.
2026-07-30 22:50:14 +07:00
|
|
|
let routeComponents: Record<string, React.FC> = OSS_ROUTE_COMPONENTS;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Merge in the overlay's marketing pages (landing, about, docs, the SEO
|
|
|
|
|
* simulator landings). Pro-gated dynamic import — the never-taken branch
|
|
|
|
|
* keeps the OSS build from ever referencing files it does not have, the
|
|
|
|
|
* same pattern main.tsx uses for mountPro. The prerender script awaits
|
|
|
|
|
* this before asking for routes.
|
|
|
|
|
*/
|
|
|
|
|
export async function loadRouteComponents(): Promise<Record<string, React.FC>> {
|
|
|
|
|
if (import.meta.env.VITE_PRO_BUILD) {
|
|
|
|
|
const m = await import('@pro/pages/marketing');
|
|
|
|
|
routeComponents = { ...OSS_ROUTE_COMPONENTS, ...m.MARKETING_ROUTE_COMPONENTS };
|
|
|
|
|
}
|
|
|
|
|
return routeComponents;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 10:08:46 +07:00
|
|
|
/**
|
|
|
|
|
* Returns all routes that have both seoMeta and a renderable component.
|
|
|
|
|
*/
|
|
|
|
|
export function getPrerenderedRoutes() {
|
refactor(routes): OSS is the editor; marketing moves to the overlay
The open-source build now ships exactly its product surface: /editor, the
examples gallery (/examples, /examples/:id) and the per-example editor
(/example/:id). Landing, about, pricing, docs, the 14 keyword-targeted
simulator landings and the v2/v2.5/v3 showcases move to the private
overlay, registered through the same registerProRoutes seam that already
carries login/admin/classroom.
Root behaves per build: an overlay that registers an index route claims
'/' (velxio.dev keeps its landing); otherwise '/' redirects to /editor.
The redirect waits for the overlay import to settle — same contract as
markProExamplesSettled — so a velxio.dev visitor is never bounced into
the editor because the landing was 300ms away from registering.
Prerender and sitemap follow the split: entry-server pulls the marketing
page map from '@pro/pages/marketing' behind a VITE_PRO_BUILD-gated dynamic
import (the proven main.tsx pattern, with an OSS stub for tsc), and
generate-sitemap lists only served routes in OSS builds (2 URLs) while
pro builds stay byte-identical — verified against a pre-migration
baseline: sitemap (37 URLs) and prerendered /, /about, /docs,
/arduino-simulator, /esp32-simulator, /v3 all identical modulo hashed
asset names. OSS prerender drops exactly the 32 marketing pages (348→316).
The OSS header slims down to match: Editor, Examples, GitHub, Discord —
the marketing links only render in pro builds, where their routes exist.
The editor Help menu links those pages absolutely (velxio.dev) in OSS,
exactly like the desktop app's Help menu.
2026-07-30 22:50:14 +07:00
|
|
|
return SEO_ROUTES.filter((r) => r.seoMeta && routeComponents[r.path]);
|
2026-03-25 10:08:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Render a route's page component to an HTML string.
|
|
|
|
|
*/
|
|
|
|
|
export function render(path: string): string {
|
refactor(routes): OSS is the editor; marketing moves to the overlay
The open-source build now ships exactly its product surface: /editor, the
examples gallery (/examples, /examples/:id) and the per-example editor
(/example/:id). Landing, about, pricing, docs, the 14 keyword-targeted
simulator landings and the v2/v2.5/v3 showcases move to the private
overlay, registered through the same registerProRoutes seam that already
carries login/admin/classroom.
Root behaves per build: an overlay that registers an index route claims
'/' (velxio.dev keeps its landing); otherwise '/' redirects to /editor.
The redirect waits for the overlay import to settle — same contract as
markProExamplesSettled — so a velxio.dev visitor is never bounced into
the editor because the landing was 300ms away from registering.
Prerender and sitemap follow the split: entry-server pulls the marketing
page map from '@pro/pages/marketing' behind a VITE_PRO_BUILD-gated dynamic
import (the proven main.tsx pattern, with an OSS stub for tsc), and
generate-sitemap lists only served routes in OSS builds (2 URLs) while
pro builds stay byte-identical — verified against a pre-migration
baseline: sitemap (37 URLs) and prerendered /, /about, /docs,
/arduino-simulator, /esp32-simulator, /v3 all identical modulo hashed
asset names. OSS prerender drops exactly the 32 marketing pages (348→316).
The OSS header slims down to match: Editor, Examples, GitHub, Discord —
the marketing links only render in pro builds, where their routes exist.
The editor Help menu links those pages absolutely (velxio.dev) in OSS,
exactly like the desktop app's Help menu.
2026-07-30 22:50:14 +07:00
|
|
|
const Component = routeComponents[path];
|
2026-03-25 10:08:46 +07:00
|
|
|
if (!Component) return '';
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return renderToString(
|
|
|
|
|
<MemoryRouter initialEntries={[path]}>
|
|
|
|
|
<Component />
|
2026-04-22 02:45:45 +07:00
|
|
|
</MemoryRouter>,
|
2026-03-25 10:08:46 +07:00
|
|
|
);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.warn(` ⚠ SSR render failed for ${path}:`, (err as Error).message);
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-14 01:22:08 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns all example routes to prerender, one per example project.
|
|
|
|
|
*/
|
|
|
|
|
export function getPrerenderedExampleRoutes() {
|
|
|
|
|
return exampleProjects.map((e) => ({
|
|
|
|
|
path: `/examples/${e.id}`,
|
|
|
|
|
title: `${e.title} — Free Arduino Simulator Example | Velxio`,
|
|
|
|
|
description: `${e.description}. Run this example free in your browser — no install, no account required.`,
|
|
|
|
|
url: `https://velxio.dev/examples/${e.id}`,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Render an example detail page to an HTML string.
|
|
|
|
|
*/
|
|
|
|
|
export function renderExample(exampleId: string): string {
|
|
|
|
|
try {
|
|
|
|
|
return renderToString(
|
|
|
|
|
<MemoryRouter initialEntries={[`/examples/${exampleId}`]}>
|
|
|
|
|
<ExampleDetailPage />
|
2026-04-22 02:45:45 +07:00
|
|
|
</MemoryRouter>,
|
2026-04-14 01:22:08 +07:00
|
|
|
);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.warn(` ⚠ SSR render failed for /examples/${exampleId}:`, (err as Error).message);
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|