File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed
packages/playground/website/src
components/ensure-playground-site Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,6 @@ function parseSearchParams(searchParams: URLSearchParams) {
159
159
}
160
160
return params ;
161
161
}
162
-
163
162
async function createNewTemporarySite (
164
163
dispatch : ReturnType < typeof useAppDispatch > ,
165
164
requestedSiteSlug ?: string
@@ -168,9 +167,15 @@ async function createNewTemporarySite(
168
167
// Lean on the Query API parameters and the Blueprint API to
169
168
// create the new site.
170
169
const newUrl = new URL ( window . location . href ) ;
170
+ const defaultBlueprint =
171
+ 'https://raw.githubusercontent.com/WordPress/blueprints/refs/heads/trunk/blueprints/welcome/blueprint.json' ;
171
172
let resolvedBlueprint : ResolvedBlueprint | undefined = undefined ;
173
+
172
174
try {
173
- resolvedBlueprint = await resolveBlueprintFromURL ( newUrl ) ;
175
+ resolvedBlueprint = await resolveBlueprintFromURL (
176
+ newUrl ,
177
+ defaultBlueprint
178
+ ) ;
174
179
} catch ( e ) {
175
180
logger . error ( 'Error resolving blueprint:' , e ) ;
176
181
}
Original file line number Diff line number Diff line change @@ -31,18 +31,35 @@ export type ResolvedBlueprint = {
31
31
} ;
32
32
33
33
export async function resolveBlueprintFromURL (
34
- url : URL
34
+ url : URL ,
35
+ defaultBlueprint ?: string
35
36
) : Promise < ResolvedBlueprint > {
36
37
const query = url . searchParams ;
37
38
const fragment = decodeURI ( url . hash || '#' ) . substring ( 1 ) ;
38
39
39
40
let blueprint : BlueprintDeclaration | BlueprintBundle ;
40
41
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.
44
46
*/
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
+ */
46
63
blueprint = await resolveRemoteBlueprint ( query . get ( 'blueprint-url' ) ! ) ;
47
64
source = {
48
65
type : 'remote-url' ,
You can’t perform that action at this time.
0 commit comments