Skip to content

Commit

Permalink
Remove old PR preview HTML files and add redirects to new preview mod…
Browse files Browse the repository at this point in the history
…als (#2081)

## Motivation for the change, related issues

This PR removes old PR preview pages, adds relevant redirects, and
updates old PR preview redirects.

Fixes #1969

## Implementation details

In addition to the removals and redirects, this PR:
- Removes some more complicated redirect-related logic because it is
awkward and no longer needed.
- Adjust old UI links to wordpress.html to link to the new modal instead

## Testing Instructions (or ideally a Blueprint)

- Tested manually on a staging site.
- Use `php -l` to ensure there are no syntax errors in
custom-redirects-lib.php
- Deploy and confirm the following paths redirect to the new PR preview
modals
  - /wordpress
  - /wordpress.html
  - /gutenberg
  - /gutenberg.html
  • Loading branch information
brandonpayton authored Dec 14, 2024
1 parent 85c5d30 commit a67f08f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 864 deletions.
77 changes: 33 additions & 44 deletions packages/playground/website-deployment/custom-redirects-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,10 @@ function playground_handle_request() {
// Note: Using the header `Vary: Referer` does not seem to affect cacheability.
$may_edge_cache = false;

if ( isset( $redirect['internal' ] ) && $redirect['internal'] ) {
$requested_path = $redirect['location'];
} else {
$should_redirect = true;
if ( isset( $redirect['condition']['referers'] ) ) {
$should_redirect = false;
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
foreach ( $redirect['condition']['referers'] as $referer ) {
if ( str_starts_with( $_SERVER['HTTP_REFERER'], $referer ) ) {
$should_redirect = true;
break;
}
}
}
}

if ( $should_redirect ) {
$log( "Redirecting to '{$redirect['location']}' with status '{$redirect['status']}'" );
header( "Location: {$redirect['location']}" );
http_response_code( $redirect['status'] );
die();
}
}
$log( "Redirecting to '{$redirect['location']}' with status '{$redirect['status']}'" );
header( "Location: {$redirect['location']}" );
http_response_code( $redirect['status'] );
die();
}

//
Expand Down Expand Up @@ -207,20 +188,6 @@ function playground_maybe_redirect( $requested_path ) {
);
}

if ( str_ends_with( $requested_path, '/wordpress' ) ) {
return array(
'location' => 'wordpress.html',
'status' => 301
);
}

if ( str_ends_with( $requested_path, '/gutenberg' ) ) {
return array(
'location' => 'gutenberg.html',
'status' => 301
);
}

if ( str_ends_with( $requested_path, '/proxy' ) ) {
return array(
'location' => 'https://github-proxy.com/',
Expand Down Expand Up @@ -249,19 +216,41 @@ function playground_maybe_redirect( $requested_path ) {
);
}

if ( str_ends_with( $requested_path, '/wordpress.html' ) ) {
if (
str_ends_with( $requested_path, '/wordpress.html' ) &&
isset( $_SERVER['HTTP_REFERER'] ) &&
(
str_starts_with( $_SERVER['HTTP_REFERER'], 'https://developer.wordpress.org/') ||
str_starts_with( $_SERVER['HTTP_REFERER'], 'https://wordpress.org/')
)
) {
return array(
'condition' => array(
'referers' => array(
'https://developer.wordpress.org/',
'https://wordpress.org/',
),
),
'location' => '/index.html',
'status' => 302,
);
}

if (
str_ends_with( $requested_path, '/wordpress' ) ||
str_ends_with( $requested_path, '/wordpress.html' )
) {
error_log( 'redir wp' );
return array(
'location' => '/?modal=preview-pr-wordpress',
'status' => 301
);
}

if (
str_ends_with( $requested_path, '/gutenberg' ) ||
str_ends_with( $requested_path, '/gutenberg.html' )
) {
return array(
'location' => '/?modal=preview-pr-gutenberg',
'status' => 301
);
}

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/playground/website/demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h2>WordPress Playground demos</h2>
<a href="time-traveling.html" target="_blank">Time Travel</a>
</li>
<li>
<a href="../wordpress.html" target="_blank"
<a href="../?modal=preview-pr-wordpress" target="_blank"
>WordPress Pull Request Previewer</a
>
</li>
Expand Down
190 changes: 0 additions & 190 deletions packages/playground/website/public/gutenberg.css

This file was deleted.

Loading

0 comments on commit a67f08f

Please sign in to comment.