Skip to content

Commit

Permalink
process: download playground runners
Browse files Browse the repository at this point in the history
Close #891
  • Loading branch information
myfreeer committed Jul 16, 2023
1 parent 48239ec commit d83c617
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/mdn/process-url/redirect-download-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ export const redirectDownloadLink = (res: Resource): Resource => {
.toString();
return res;
}
// https://github.com/website-local/mdn-local/issues/891
// 20230716
if (path.startsWith('/live.mdnplay.dev/')) {
res.downloadLink = uri.search('')
.host('live.mdnplay.dev')
.path(path.slice('/live.mdnplay.dev'.length))
.toString();
return res;
}
}
return res;
};
14 changes: 14 additions & 0 deletions src/mdn/process-url/redirect-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export function redirectUrl(
case 'developer-stage.mdn.mozit.cloud':
case 'developer-prod.mdn.mozit.cloud':
case 'developer.mozilla.org':
// https://github.com/website-local/mdn-local/issues/890
case 'bcd.developer.mozilla.org':

Check failure on line 105 in src/mdn/process-url/redirect-url.ts

View workflow job for this annotation

GitHub Actions / build (12.x)

Expected a 'break' statement before 'case'

Check failure on line 105 in src/mdn/process-url/redirect-url.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected a 'break' statement before 'case'
case 'bcd.developer.allizom.org':
case mdnHost:
u = u.host(mdnHost);
needToRebuildUrl = true;
Expand Down Expand Up @@ -149,6 +152,17 @@ export function redirectUrl(
shouldReturnEarly = true;
break;
}
// https://github.com/website-local/mdn-local/issues/891
if (host.endsWith('.mdnplay.dev')) {
if (u.protocol() === 'http') {
u.protocol('https');
}
// fake url, redirected back in redirectDownloadLink
u = u.host(mdnHost)
.path('/live.mdnplay.dev' + u.path());
shouldReturnEarly = true;
break;
}
if (hardCodedRedirectUrl[url]) {
return hardCodedRedirectUrl[url];
}
Expand Down
20 changes: 20 additions & 0 deletions test/mdn/process-url/redirect-download-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,24 @@ describe('redirect-download-link', function () {
}
});

// https://github.com/website-local/mdn-local/issues/891
// 20230716
test('live.mdnplay.dev', () => {
const urls = [
'https://3b2c6cbd-0e90-4934-8c02-8e8c4b08e767.mdnplay.dev/runner.html',
'https://live.mdnplay.dev/en-US/docs/Web/CSS/grid/runner.html?id=creating_a_grid_layout'
];
const expected = [
'https://live.mdnplay.dev/runner.html',
'https://live.mdnplay.dev/en-US/docs/Web/CSS/grid/runner.html'
];
for (let i = 0; i < urls.length; i++){
const url = urls[i];
const resource = res(url);
redirectDownloadLink(resource);
expect(resource.uri?.host()).toBe('developer.mozilla.org');
expect(resource.downloadLink).toBe(expected[i]);
}
});

});

0 comments on commit d83c617

Please sign in to comment.