Skip to content

Commit

Permalink
Revert "Remove old PR preview HTML files and add redirects to new pre…
Browse files Browse the repository at this point in the history
…view modals" (#2082)

Reverts #2081

The change broke PR preview links. The modal does not yet have feature
parity with the separate HTML pages. It needs to support all the same
user flows and query params before it can replace the existing
previewers. Cc @brandonpayton @ajotka
  • Loading branch information
adamziel authored Dec 14, 2024
1 parent beb4d29 commit b9df604
Show file tree
Hide file tree
Showing 7 changed files with 864 additions and 35 deletions.
77 changes: 44 additions & 33 deletions packages/playground/website-deployment/custom-redirects-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,29 @@ function playground_handle_request() {
// Note: Using the header `Vary: Referer` does not seem to affect cacheability.
$may_edge_cache = false;

$log( "Redirecting to '{$redirect['location']}' with status '{$redirect['status']}'" );
header( "Location: {$redirect['location']}" );
http_response_code( $redirect['status'] );
die();
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();
}
}
}

//
Expand Down Expand Up @@ -188,6 +207,20 @@ 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 @@ -216,41 +249,19 @@ function playground_maybe_redirect( $requested_path ) {
);
}

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/')
)
) {
if ( str_ends_with( $requested_path, '/wordpress.html' ) ) {
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="../?modal=preview-pr-wordpress" target="_blank"
<a href="../wordpress.html" target="_blank"
>WordPress Pull Request Previewer</a
>
</li>
Expand Down
190 changes: 190 additions & 0 deletions packages/playground/website/public/gutenberg.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
body,
html {
height: 100%;
}
html {
font-size: 16px;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,
Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif;
line-height: 1.8;
color: #191e23;
display: flex;
flex-direction: column;
justify-content: center;
}
svg {
fill: currentColor;
}
label {
margin-bottom: 4px;
font-size: 16px;
}
input[type='text'] {
appearance: none;
-webkit-appearance: none;
-moz-appearance: textfield;
border: 1px solid #8d96a0;
border-radius: 4px;
padding: 5px 8px;
outline: 0;
font-size: 26px;
}
input[type='text']::-webkit-inner-spin-button,
input[type='text']::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type='text']:focus {
border-color: #00a0d2;
box-shadow: 0 0 0 1px #00a0d2;
color: #191e23;
outline: 2px solid transparent;
outline-offset: -2px;
}
button {
border-radius: 3px;
vertical-align: top;
height: 40px;
line-height: 38px;
padding: 0 12px;
webkit-appearance: none;
border: 0;
cursor: pointer;
display: inline-flex;
font-size: 30px;
margin: 0;
background: #0085ba;
border-color: #006a95 #00648c #00648c;
box-shadow: inset 0 -1px 0 #00648c;
color: #fff;
text-shadow: 0 -1px 1px #005d82, 1px 0 1px #005d82, 0 1px 1px #005d82,
-1px 0 1px #005d82;
}
button:hover {
box-shadow: inset 0 -1px 0 #00435d;
background: #007eb1;
border-color: #00435d;
}
button:active {
background: #006a95;
border-color: #00435d;
box-shadow: inset 0 1px 0 #00435d;
vertical-align: top;
}
button:focus {
outline: 2px solid transparent;
outline-offset: -2px;
box-shadow: inset 0 -1px 0 #00435d, 0 0 0 2px #bfe7f3;
background: #007eb1;
border-color: #00435d;
}
#main {
display: flex;
flex-direction: column;
align-items: center;
height: 50vh;
width: 100%;
margin: 0 auto;
}
#logo {
flex-shrink: 1;
flex-grow: 0;
flex-basis: 100%;
}
#create,
#run {
height: 60px;
margin: 5vh 0;
flex-shrink: 0;
}
#createFields {
display: flex;
align-items: center;
}
#gutenberg-pr {
width: 280px;
margin-right: 4px;
}
#run {
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
#status {
display: block;
font-weight: 400;
font-size: 1.4rem;
text-align: center;
font-family: 'Noto Serif', serif;
}
#progress {
max-width: 360px;
width: 90%;
margin: 0 auto;
height: 5px;
background: #eaeaea;
padding: 3px;
}
#progressFill {
height: 5px;
background: #191e23;
transition: width 0.6s ease-in-out;
}
#links {
text-align: center;
padding: 0 10px;
}
#error {
text-align: center;
padding: 0 10px;
margin-bottom: 5vh;
color: #8b0000;
font-weight: bold;
font-size: 1.5em;
}

#submit {
display: flex;
align-items: center;
justify-content: center;
}

#submit:not(.loading) .verifying {
display: none;
}
#submit.loading .go {
display: none;
}

#submit.loading {
position: relative;
background: #00435d;
border-color: #00435d;
cursor: default;
}

#submit.loading:before {
content: '';
/* position: absolute;
top: 0;
left: 0; */
margin-right: 5px;
margin-left: -5px;
width: 15px;
height: 15px;
border-radius: 50%;
border: 2px solid #fff;
border-top-color: transparent;
border-right-color: transparent;
animation: spin 1s linear infinite;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}
Loading

0 comments on commit b9df604

Please sign in to comment.