Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(livesamples): use correct legacy url #9158

Merged
merged 4 commits into from
Jun 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions kumascript/macros/LiveSampleURL.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
//
// Parameters:
//
// $0 The ID of the sample's section or containing block.
// $1 The URL from which to pull the sample; if not provided,
// $0 - The ID of the sample's section or containing block.
// $1 - (Deprecated) The URL from which to pull the sample; if not provided,
// the current page is assumed.

var pagePath = env.url;
let pagePath = env.url;
let baseUrl = env.live_samples.base_url;
let samplePath = `${pagePath}/runner.html`.replace(/\/\/+/g, "/");

if ($1 && $1.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're cleaning up the macro anyways, can you assign $0 and $1 to variables id and url or similar to avoid referencing $0 and $1 below?

mdn.deprecatedParams("The second parameter of 'LiveSampleURL' is deprecated");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the message would have an actionable suggestion on how to proceed. I guess in this case the original example has to be copied into the page, right?

pagePath = $1;
baseUrl = env.live_samples.legacy_url;
samplePath = `${pagePath}/_sample_.${web.slugify(web.safeDecodeURIComponent($0))}.html`.replace(/\/\/+/g, "/");
}

const searchParams = new URLSearchParams([["id", $0], ["url", $1]].filter(([_,v]) => Boolean(v)));
wiki.ensureExistence(pagePath);
const samplePath = $1 ?
`${pagePath}/_sample_.${web.slugify(web.safeDecodeURIComponent($0))}.html`.replace(/\/\/+/g, "/")
: `${pagePath}/runner.html`.replace(/\/\/+/g, "/");
const searchParams = new URLSearchParams([["id", $0], ["url", $1]].filter(([_,v]) => Boolean(v)));

let url;
if (env.live_samples.base_url.includes('://')) {
url = new URL($1 ? env.live_samples.legacy_url : env.live_samples.base_url);
if (baseUrl.includes('://')) {
url = new URL(baseUrl);
url.pathname = samplePath;
url.search = searchParams.toString();
} else {
Expand Down