Skip to content

Commit de9a153

Browse files
committed
Versions path fix
1 parent 1711d67 commit de9a153

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

website/build.mjs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ let docsMenu = '';
2020
let isBlog = false;
2121
let isDocs = false;
2222

23-
async function getDefaultVersionTarget(versionFile, defaultTarget = null) {
24-
if (defaultTarget) return defaultTarget;
25-
26-
const versions = await readJson(versionFile);
27-
const defaultVersion = versions.find(v => v.default);
28-
return defaultVersion?.branch ?? defaultVersion?.tag;
29-
}
30-
3123
async function getAllMdFiles(dir) {
3224
const entries = await readdir(dir, { withFileTypes: true });
3325
const files = [];
@@ -89,12 +81,20 @@ async function buildDocsMenuForVersion(version) {
8981
return menu;
9082
}
9183

84+
function getVersionPath(version) {
85+
return version.path ?? version.branch ?? version.tag;
86+
}
87+
88+
function getBundlesPath(version) {
89+
return path.join(config.bundlesPath, version.branch ?? version.tag);
90+
}
91+
9292
async function buildVersionsMenuList(versions, currentVersion, section) {
9393
let versionsMenuHtml = '<div class="dropdown-block">';
9494
for (const v of versions) {
9595
const activityClass = v.label === currentVersion && !v.default ? ' class="active"' : '';
9696
const defaultBadge = v.default ? ' (default)' : '';
97-
const versionPath = v.default ? '' : `${ v.path ?? v.label }/`;
97+
const versionPath = v.default ? '' : `${ getVersionPath(v) }/`;
9898
versionsMenuHtml += `<a href="./${ versionPath }${ section }"${ activityClass }>${ v.label }${ defaultBadge }</a>`;
9999
}
100100
versionsMenuHtml += '</div>';
@@ -227,9 +227,10 @@ async function buildPlaygrounds(template, versions) {
227227
}
228228

229229
async function buildPlayground(template, version, versions) {
230-
const versionPath = version.branch ?? version.tag;
231-
const bundleScript = `<script nomodule src="${ config.bundlesPath }/${ versionPath }/${ config.bundleName }"></script>`;
232-
const bundleESModulesScript = `<script type="module" src="${ config.bundlesPath }/${ versionPath }/${ config.bundleNameESModules }"></script>`;
230+
const versionPath = getVersionPath(version);
231+
const bundlesPath = getBundlesPath(version);
232+
const bundleScript = `<script nomodule src="${ bundlesPath }/${ config.bundleName }"></script>`;
233+
const bundleESModulesScript = `<script type="module" src="${ bundlesPath }/${ config.bundleNameESModules }"></script>`;
233234
const babelScript = '<script src="./babel.min.js"></script>';
234235
const playgroundContent = await readFileContent(`${ config.srcDir }playground.html`);
235236
const versionsMenu = await buildVersionsMenu(versions, version.label, 'playground');
@@ -256,11 +257,11 @@ async function buildPlayground(template, version, versions) {
256257
}
257258

258259
async function createDocsIndexes(versions) {
259-
if (BRANCH) versions = [{ label: '' }];
260+
if (BRANCH) versions = [{ path: '' }];
260261

261262
for (const version of versions) {
262263
if (version.default) continue;
263-
const versionPath = version.path ?? version.label;
264+
const versionPath = getVersionPath(version);
264265
const menuItems = await getDocsMenuItems(versionPath);
265266
const firstDocPath = path.join(config.resultDir,
266267
`${ menuItems[0].url }.html`.replace(`{docs-version}${ BRANCH ? '/' : '' }`, versionPath));
@@ -294,7 +295,8 @@ async function build() {
294295
await buildBlogMenu();
295296
const mdFiles = await getAllMdFiles(config.docsDir);
296297
const versions = await getVersions();
297-
const bundlesPath = `${ config.bundlesPath }/${ await getDefaultVersionTarget(config.versionsFile, BRANCH) }`;
298+
const defaultVersion = versions.find(v => v.default);
299+
const bundlesPath = getBundlesPath(defaultVersion);
298300
const bundleScript = `<script nomodule src="${ bundlesPath }/${ config.bundleName }"></script>`;
299301
const bundleESModulesScript = `<script type="module" src="${ bundlesPath }/${ config.bundleNameESModules }"></script>`;
300302

website/config/versions.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
{
33
"label": "v3",
44
"default": true,
5-
"branch": "master"
5+
"branch": "master",
6+
"path": "v3"
67
},
78
{
89
"label": "v3",
9-
"branch": "master"
10+
"branch": "master",
11+
"path": "v3"
1012
},
1113
{
1214
"label": "v4 (alpha)",
13-
"path": "v4",
14-
"branch": "v4"
15+
"branch": "v4",
16+
"path": "v4"
1517
}
1618
]

0 commit comments

Comments
 (0)