Skip to content

Commit 87cf8ae

Browse files
zaerladamziel
andauthored
[Website] Default demo content (#2412)
## Motivation for the change, related issues See #2236 Set new default demo page if no other options are provided by the user and Playground is not running inside an `<iframe>`. Set to https://raw.githubusercontent.com/fellyph/blueprints-demos/refs/heads/main/demos/blueprint-import-wxr.json for testing. ## Implementation details ## Testing Instructions (or ideally a Blueprint) 1. `npm run dev` 2. Open http://127.0.0.1:5400/website-server/ 3. The new page should open 4. Try to add a blueprint, a `import-*`, a theme, a plugin on the URL. It should not open Try in an `iframe` ```html <!DOCTYPE html> <html lang="en"> <body> <iframe style="width: 600px; height: 600px; border: none;" src="http://127.0.0.1:5400/website-server/" title="WordPress Playground"></iframe> </body> </html> ``` <img width="1298" height="633" alt="immagine" src="https://github.com/user-attachments/assets/bda97f14-9650-4b24-8aab-c76530c9cec9" /> <img width="629" height="581" alt="immagine" src="https://github.com/user-attachments/assets/c3745baa-3bd2-4e22-91ca-433673cc37f3" /> --------- Co-authored-by: Adam Zieliński <[email protected]>
1 parent 554a2e5 commit 87cf8ae

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

packages/playground/website/src/components/ensure-playground-site/ensure-playground-site-is-selected.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ function parseSearchParams(searchParams: URLSearchParams) {
159159
}
160160
return params;
161161
}
162-
163162
async function createNewTemporarySite(
164163
dispatch: ReturnType<typeof useAppDispatch>,
165164
requestedSiteSlug?: string
@@ -168,9 +167,15 @@ async function createNewTemporarySite(
168167
// Lean on the Query API parameters and the Blueprint API to
169168
// create the new site.
170169
const newUrl = new URL(window.location.href);
170+
const defaultBlueprint =
171+
'https://raw.githubusercontent.com/WordPress/blueprints/refs/heads/trunk/blueprints/welcome/blueprint.json';
171172
let resolvedBlueprint: ResolvedBlueprint | undefined = undefined;
173+
172174
try {
173-
resolvedBlueprint = await resolveBlueprintFromURL(newUrl);
175+
resolvedBlueprint = await resolveBlueprintFromURL(
176+
newUrl,
177+
defaultBlueprint
178+
);
174179
} catch (e) {
175180
logger.error('Error resolving blueprint:', e);
176181
}

packages/playground/website/src/lib/state/url/resolve-blueprint-from-url.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,35 @@ export type ResolvedBlueprint = {
3131
};
3232

3333
export async function resolveBlueprintFromURL(
34-
url: URL
34+
url: URL,
35+
defaultBlueprint?: string
3536
): Promise<ResolvedBlueprint> {
3637
const query = url.searchParams;
3738
const fragment = decodeURI(url.hash || '#').substring(1);
3839

3940
let blueprint: BlueprintDeclaration | BlueprintBundle;
4041
let source: BlueprintSource;
41-
/*
42-
* Support passing blueprints via query parameter, e.g.:
43-
* ?blueprint-url=https://example.com/blueprint.json
42+
43+
/**
44+
* If the URL has no parameters or fragment, and a default blueprint is provided,
45+
* use the default blueprint.
4446
*/
45-
if (query.has('blueprint-url')) {
47+
if (
48+
window.self === window.top &&
49+
!query.size &&
50+
!fragment.length &&
51+
defaultBlueprint
52+
) {
53+
blueprint = await resolveRemoteBlueprint(defaultBlueprint);
54+
source = {
55+
type: 'remote-url',
56+
url: defaultBlueprint,
57+
};
58+
} else if (query.has('blueprint-url')) {
59+
/*
60+
* Support passing blueprints via query parameter, e.g.:
61+
* ?blueprint-url=https://example.com/blueprint.json
62+
*/
4663
blueprint = await resolveRemoteBlueprint(query.get('blueprint-url')!);
4764
source = {
4865
type: 'remote-url',

0 commit comments

Comments
 (0)