Skip to content

Commit 1f1224d

Browse files
committed
Fix default playground version menu
1 parent 70f91f3 commit 1f1224d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

website/build.mjs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,13 @@ async function buildDocsMenuForVersion(version) {
8888
}
8989

9090
async function buildPlaygroundMenuForVersion(versions, currentVersion) {
91+
let defaultVersionTag = `<a href="./playground">${ DEFAULT_VERSION } (default)</a>`;
92+
if (currentVersion === '') {
93+
currentVersion = `${ DEFAULT_VERSION } (default)`;
94+
defaultVersionTag = `<a href="./playground" class="active">${ DEFAULT_VERSION } (default)</a>`;
95+
}
9196
let versionsMenuHtml = `<div class="dropdown versions-menu"><div class="dropdown-wrapper"><a href="#" class="current">${
92-
currentVersion }</a><div class="dropdown-block"><a href="./playground">${ DEFAULT_VERSION } (default)</a>`;
97+
currentVersion }</a><div class="dropdown-block">${ defaultVersionTag }`;
9398
if (versions.length >= 1) {
9499
for (const v of versions) {
95100
const activityClass = v === currentVersion ? ' class="active"' : '';
@@ -268,13 +273,15 @@ async function buildPlayground(template, version, versions) {
268273
playground = playground.replace('{base}', `${ BASE }`);
269274
playground = playground.replace('{core-js-bundle}', `${ bundleScript }`);
270275
playground = playground.replace('{core-js-bundle-esmodules}', `${ bundleESModulesScript }`);
271-
playground = playground.replace('{versions-menu}', `${ versionsMenu }`);
276+
const playgroundWithVersion = playground.replace('{versions-menu}', `${ versionsMenu }`);
272277
const playgroundFilePath = path.join(RESULT_DIR, version, 'playground.html');
273278
await fs.mkdir(path.dirname(playgroundFilePath), { recursive: true });
274-
await fs.writeFile(playgroundFilePath, playground, 'utf8');
279+
await fs.writeFile(playgroundFilePath, playgroundWithVersion, 'utf8');
275280
if (version === DEFAULT_VERSION) {
281+
const defaultVersionsMenu = await buildPlaygroundMenuForVersion(versions, '');
282+
const defaultVersionPlayground = playground.replace('{versions-menu}', `${ defaultVersionsMenu }`);
276283
const defaultPlaygroundPath = path.join(RESULT_DIR, 'playground.html');
277-
await fs.writeFile(defaultPlaygroundPath, playground, 'utf8');
284+
await fs.writeFile(defaultPlaygroundPath, defaultVersionPlayground, 'utf8');
278285
echo(chalk.green(`File created: ${ defaultPlaygroundPath }`));
279286
}
280287

0 commit comments

Comments
 (0)