@@ -20,14 +20,6 @@ let docsMenu = '';
2020let isBlog = false ;
2121let 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-
3123async 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+
9292async 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
229229async 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
258259async 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
0 commit comments