@@ -45,8 +45,9 @@ async function buildDocsMenu(item) {
45
45
result += '</ul></li>' ;
46
46
return result ;
47
47
}
48
+ const defaultVersion = BRANCH ? BRANCH : DEFAULT_VERSION ;
48
49
49
- return `<li><a href="${ item . url } " class="with-docs-version" data-default-version="${ DEFAULT_VERSION } ">${ item . title } </a></li>` ;
50
+ return `<li><a href="${ item . url } " class="with-docs-version" data-default-version="${ defaultVersion } ">${ item . title } </a></li>` ;
50
51
}
51
52
52
53
const docsMenus = [ ] ;
@@ -88,15 +89,17 @@ async function buildDocsMenuForVersion(version) {
88
89
}
89
90
90
91
async function buildPlaygroundMenuForVersion ( versions , currentVersion ) {
91
- let defaultVersionTag = `<a href="./playground">${ DEFAULT_VERSION } (default)</a>` ;
92
+ const defaultVersion = BRANCH ? BRANCH : DEFAULT_VERSION ;
93
+ let defaultVersionTag = `<a href="./playground">${ defaultVersion } (default)</a>` ;
92
94
if ( currentVersion === '' ) {
93
- currentVersion = `${ DEFAULT_VERSION } (default)` ;
94
- defaultVersionTag = `<a href="./playground" class="active">${ DEFAULT_VERSION } (default)</a>` ;
95
+ currentVersion = `${ defaultVersion } (default)` ;
96
+ defaultVersionTag = `<a href="./playground" class="active">${ defaultVersion } (default)</a>` ;
95
97
}
96
98
let versionsMenuHtml = `<div class="dropdown versions-menu"><div class="dropdown-wrapper"><a href="#" class="current">${
97
99
currentVersion } </a><div class="dropdown-block">${ defaultVersionTag } `;
98
100
if ( versions . length >= 1 ) {
99
101
for ( const v of versions ) {
102
+ if ( v === BRANCH ) continue ;
100
103
const activityClass = v === currentVersion ? ' class="active"' : '' ;
101
104
versionsMenuHtml += `<a href="./${ v } /playground"${ activityClass } >${ v } </a>` ;
102
105
}
@@ -107,9 +110,11 @@ async function buildPlaygroundMenuForVersion(versions, currentVersion) {
107
110
}
108
111
109
112
async function buildVersionsMenuList ( versions , currentVersion ) {
110
- let versionsMenuHtml = `<div class="dropdown-block"><a href="./docs/">${ DEFAULT_VERSION } (default)</a>` ;
113
+ const defaultVersion = BRANCH ? BRANCH : DEFAULT_VERSION ;
114
+ let versionsMenuHtml = `<div class="dropdown-block"><a href="./docs/">${ defaultVersion } (default)</a>` ;
111
115
if ( versions . length >= 1 ) {
112
116
for ( const v of versions ) {
117
+ if ( v === BRANCH ) continue ;
113
118
const activityClass = v === currentVersion ? ' class="active"' : '' ;
114
119
versionsMenuHtml += `<a href="./${ v } /docs/"${ activityClass } >${ v } </a>` ;
115
120
}
@@ -151,6 +156,7 @@ const linkRenderer = {
151
156
} ;
152
157
153
158
function buildMenus ( html ) {
159
+ const defaultVersion = BRANCH ? BRANCH : DEFAULT_VERSION ;
154
160
const headings = getHeadingList ( ) . filter ( ( { level } ) => level > 1 ) ;
155
161
let result = '<div class="wrapper">' ;
156
162
if ( isBlog ) {
@@ -163,7 +169,7 @@ function buildMenus(html) {
163
169
result += `<div class="table-of-contents sticky"><div class="mobile-trigger"></div>
164
170
${ headings . map ( ( { id, raw, level } ) => `<div class="toc-link"><a href="${
165
171
htmlFileName . replace ( '.html' , '' ) } #${ id } " class="h${
166
- level } with-docs-version" data-default-version="${ DEFAULT_VERSION } ">${
172
+ level } with-docs-version" data-default-version="${ defaultVersion } ">${
167
173
raw } </a></div>`) . join ( '\n' ) }
168
174
</div>` ;
169
175
}
@@ -235,13 +241,14 @@ let versionsCache = [];
235
241
async function getVersionsFromMdFiles ( mdFiles ) {
236
242
if ( versionsCache . length ) return versionsCache ;
237
243
244
+ const defaultVersion = BRANCH ? BRANCH : DEFAULT_VERSION ;
238
245
const versions = [ ] ;
239
246
for ( const mdPath of mdFiles ) {
240
247
const match = mdPath . match ( / \/ w e b \/ (?< version > [ ^ / ] + ) \/ d o c s \/ / ) ;
241
248
if ( match && match . groups && match . groups . version ) {
242
249
versions . push ( match . groups . version ) ;
243
250
} else {
244
- versions . push ( DEFAULT_VERSION ) ;
251
+ versions . push ( defaultVersion ) ;
245
252
}
246
253
}
247
254
versionsCache = versions ;
@@ -275,17 +282,20 @@ async function buildPlayground(template, version, versions) {
275
282
playground = playground . replace ( '{core-js-bundle-esmodules}' , `${ bundleESModulesScript } ` ) ;
276
283
const playgroundWithVersion = playground . replace ( '{versions-menu}' , `${ versionsMenu } ` ) ;
277
284
const playgroundFilePath = path . join ( RESULT_DIR , version , 'playground.html' ) ;
278
- await fs . mkdir ( path . dirname ( playgroundFilePath ) , { recursive : true } ) ;
279
- await fs . writeFile ( playgroundFilePath , playgroundWithVersion , 'utf8' ) ;
280
- if ( version === DEFAULT_VERSION ) {
285
+ if ( version !== BRANCH ) {
286
+ await fs . mkdir ( path . dirname ( playgroundFilePath ) , { recursive : true } ) ;
287
+ await fs . writeFile ( playgroundFilePath , playgroundWithVersion , 'utf8' ) ;
288
+ echo ( chalk . green ( `File created: ${ playgroundFilePath } ` ) ) ;
289
+ }
290
+
291
+ const defaultVersion = BRANCH ? BRANCH : DEFAULT_VERSION ;
292
+ if ( version === defaultVersion ) {
281
293
const defaultVersionsMenu = await buildPlaygroundMenuForVersion ( versions , '' ) ;
282
294
const defaultVersionPlayground = playground . replace ( '{versions-menu}' , `${ defaultVersionsMenu } ` ) ;
283
295
const defaultPlaygroundPath = path . join ( RESULT_DIR , 'playground.html' ) ;
284
296
await fs . writeFile ( defaultPlaygroundPath , defaultVersionPlayground , 'utf8' ) ;
285
297
echo ( chalk . green ( `File created: ${ defaultPlaygroundPath } ` ) ) ;
286
298
}
287
-
288
- echo ( chalk . green ( `File created: ${ playgroundFilePath } ` ) ) ;
289
299
}
290
300
291
301
async function createDocsIndexes ( versions ) {
@@ -319,8 +329,9 @@ async function build() {
319
329
const mdFiles = await getAllMdFiles ( DOCS_DIR ) ;
320
330
const versions = await getVersionsFromMdFiles ( mdFiles ) ;
321
331
const uniqueVersions = [ ...new Set ( versions ) ] ;
322
- const bundleScript = `<script nomodule src="${ BUNDLES_PATH } /${ DEFAULT_VERSION } /${ BUNDLE_NAME } "></script>` ;
323
- const bundleESModulesScript = `<script type="module" src="${ BUNDLES_PATH } /${ DEFAULT_VERSION } /${ BUNDLE_NAME_ESMODULES } "></script>` ;
332
+ const defaultVersion = BRANCH ? BRANCH : DEFAULT_VERSION ;
333
+ const bundleScript = `<script nomodule src="${ BUNDLES_PATH } /${ defaultVersion } /${ BUNDLE_NAME } "></script>` ;
334
+ const bundleESModulesScript = `<script type="module" src="${ BUNDLES_PATH } /${ defaultVersion } /${ BUNDLE_NAME_ESMODULES } "></script>` ;
324
335
325
336
let currentVersion = '' ;
326
337
let versionsMenu = '' ;
0 commit comments