Skip to content

Commit 2137735

Browse files
authored
Exclude page versions (#279)
<img width="836" height="383" alt="image" src="https://github.com/user-attachments/assets/50c79ca3-6c77-477c-b7c1-f59b770b3a83" />
1 parent 253c1e5 commit 2137735

File tree

5 files changed

+32
-40
lines changed

5 files changed

+32
-40
lines changed

preview-src/ui-model.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ page:
7575
title: Java Client
7676
attributes:
7777
component-order: '!home, !templates, !imdg, !privacy, hazelcast, management-center, cloud, *'
78-
excluded-versions: 'hazelcast:4.0'
78+
excluded-versions: 'management-center:4.0'
7979
last-versions-count: 10
8080
component:
8181
name: management-center
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
module.exports = ({ data: { root } }) => {
4+
let versions = root.page.versions
5+
const excludedVersions = root.page.attributes['excluded-versions']
6+
const currentComponentName = root.page.component.name
7+
if (excludedVersions) {
8+
const excludedComponentVersions = excludedVersions.split(',').map((it) => it.trim())
9+
// console.debug('[DEBUG:SORT_COMPONENTS] excluding versions: ', excludedComponentVersions)
10+
excludedComponentVersions.forEach((componentVersion) => {
11+
const [componentName, excludedVersionName] = componentVersion.split(':')
12+
if (currentComponentName === componentName) {
13+
versions = versions.filter(({ version }) => {
14+
return version !== excludedVersionName
15+
})
16+
}
17+
})
18+
}
19+
return versions
20+
}

src/helpers/sort-components.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
'use strict'
22

3-
// filter out excluded versions
4-
const excludeComponentVersions = (targetCollection, page) => {
5-
if (page.attributes['excluded-versions']) {
6-
const excludedComponentVersions = page.attributes['excluded-versions']
7-
.split(',').map((it) => it.trim())
8-
// console.debug('[DEBUG:SORT_COMPONENTS] excluding versions: ', excludedComponentVersions)
9-
excludedComponentVersions.forEach((componentVersion, index) => {
10-
const [componentName, versionName] = componentVersion.split(':')
11-
const component = targetCollection.find(({ name }) => name === componentName)
12-
if (!component) {
13-
console.warn(`No component found for excluded-versions[${index}] -> ${componentVersion}`)
14-
} else {
15-
component.versions = component.versions.map((nextVersion) => {
16-
return {
17-
...nextVersion,
18-
isHidden: nextVersion.version === versionName,
19-
}
20-
})
21-
}
22-
})
23-
}
24-
return targetCollection
25-
}
26-
27-
module.exports = (collection, property, orderSpec, { data: { root } }) => {
3+
module.exports = (collection, property, orderSpec) => {
284
if (orderSpec == null || orderSpec === '*') return Object.values(collection)
295
const sourceCollection = Object.values(collection).reduce((accum, it) => accum.set(it[property], it), new Map())
306
const order = orderSpec
@@ -36,15 +12,13 @@ module.exports = (collection, property, orderSpec, { data: { root } }) => {
3612
})
3713
const restIdx = order.indexOf('*')
3814
if (~restIdx) order.splice(restIdx, 1)
39-
let targetCollection = order.reduce((accum, key) => {
15+
const targetCollection = order.reduce((accum, key) => {
4016
if (sourceCollection.has(key)) {
4117
accum.push(sourceCollection.get(key))
4218
sourceCollection.delete(key)
4319
}
4420
return accum
4521
}, [])
4622
if (~restIdx) targetCollection.splice(restIdx, 0, ...sourceCollection.values())
47-
targetCollection = excludeComponentVersions(targetCollection, root.page)
48-
// console.debug('[DEBUG:SORT_COMPONENTS] targetCollection: ', targetCollection)
4923
return targetCollection
5024
}

src/partials/nav-explore.hbs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@
2626
{{#with page.versions}}
2727
{{#if (and (not-eq @root.page.component.name 'cloud') (not-eq @root.page.component.name 'home') (not-eq @root.page.component.name 'templates'))}}
2828
<ul class="nav-version-picker-versions" id="navbarVersionsList">
29-
{{#each this}}
30-
{{#unless ./isHidden}}
31-
{{#if (lte @index 10)}}
32-
<li
33-
class="version {{~#if (eq ./version @root.page.version)}} is-current{{/if~}}"
34-
>
35-
<a href="{{{relativize ./url}}}">{{./displayVersion}}</a>
36-
</li>
37-
{{/if}}
38-
{{/unless}}
29+
{{#each (filter-out-excluded-versions)}}
30+
{{#if (lte @index 10)}}
31+
<li
32+
class="version {{~#if (eq ./version @root.page.version)}} is-current{{/if~}}"
33+
>
34+
<a href="{{{relativize ./url}}}">{{./displayVersion}}</a>
35+
</li>
36+
{{/if}}
3937
{{/each}}
4038
</ul>
4139
{{/if}}

src/partials/page-versions.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="page-versions">
33
<button class="version-menu-toggle" title="Show other versions of page">Version {{@root.page.componentVersion.displayVersion}}</button>
44
<div class="version-menu">
5-
{{#each this}}
5+
{{#each (filter-out-excluded-versions)}}
66
{{#if (lte @index 10)}}
77
<a class="version
88
{{~#if (eq ./version @root.page.version)}} is-current{{/if~}}

0 commit comments

Comments
 (0)