1- import { getDefaultVersion } from './scripts/helpers.mjs' ;
1+ import { expandVersionsConfig , getDefaultVersion } from './scripts/helpers.mjs' ;
22import fm from 'front-matter' ;
33import { JSDOM } from 'jsdom' ;
44import { Marked } from 'marked' ;
@@ -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 . label ;
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 ) ) ;
@@ -273,15 +274,17 @@ async function createDocsIndexes(versions) {
273274async function getVersions ( ) {
274275 if ( BRANCH ) {
275276 return [ {
276- label : BRANCH ,
277- default : true ,
278277 branch : BRANCH ,
278+ default : true ,
279+ label : BRANCH ,
280+ path : BRANCH ,
279281 } ] ;
280282 }
283+
281284 const versions = await readJson ( config . versionsFile ) ;
282285 echo ( chalk . green ( 'Got versions from file' ) ) ;
283286
284- return versions ;
287+ return expandVersionsConfig ( versions ) ;
285288}
286289
287290function getTitle ( content ) {
@@ -294,7 +297,8 @@ async function build() {
294297 await buildBlogMenu ( ) ;
295298 const mdFiles = await getAllMdFiles ( config . docsDir ) ;
296299 const versions = await getVersions ( ) ;
297- const bundlesPath = `${ config . bundlesPath } /${ await getDefaultVersionTarget ( config . versionsFile , BRANCH ) } ` ;
300+ const defaultVersion = versions . find ( v => v . default ) ;
301+ const bundlesPath = getBundlesPath ( defaultVersion ) ;
298302 const bundleScript = `<script nomodule src="${ bundlesPath } /${ config . bundleName } "></script>` ;
299303 const bundleESModulesScript = `<script type="module" src="${ bundlesPath } /${ config . bundleNameESModules } "></script>` ;
300304
0 commit comments