Skip to content

Commit f3bd709

Browse files
Copilotbrunoborges
andcommitted
Add JDK version filtering by LTS cycle on homepage
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 0b78f8c commit f3bd709

File tree

5 files changed

+75
-22
lines changed

5 files changed

+75
-22
lines changed

site/app.js

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,39 @@
202202
2. Category Filter Pills (homepage)
203203
========================================================== */
204204
const initFilters = () => {
205-
const pills = document.querySelectorAll('.filter-pill');
205+
const pills = document.querySelectorAll('#categoryFilter .filter-pill');
206+
const jdkPills = document.querySelectorAll('#jdkFilter .filter-pill');
206207
const cards = document.querySelectorAll('.tip-card');
207208
if (!pills.length || !cards.length) return;
208209

210+
let activeCategory = null;
211+
let activeJdk = null;
212+
213+
// LTS cycle ranges: each entry covers all versions introduced since the previous LTS
214+
const LTS_RANGES = {
215+
'11': [9, 11],
216+
'17': [12, 17],
217+
'21': [18, 21],
218+
'25': [22, 25]
219+
};
220+
221+
const applyFilters = () => {
222+
cards.forEach(card => {
223+
const matchesCategory = !activeCategory || card.dataset.category === activeCategory;
224+
let matchesJdk = true;
225+
if (activeJdk) {
226+
const version = parseInt(card.dataset.jdk, 10);
227+
const range = LTS_RANGES[activeJdk];
228+
matchesJdk = range && version >= range[0] && version <= range[1];
229+
}
230+
card.classList.toggle('filter-hidden', !(matchesCategory && matchesJdk));
231+
});
232+
233+
if (window.updateViewToggleState) {
234+
window.updateViewToggleState();
235+
}
236+
};
237+
209238
pills.forEach(pill => {
210239
pill.addEventListener('click', () => {
211240
const category = pill.dataset.filter || 'all';
@@ -215,45 +244,46 @@
215244
pills.forEach(p => p.classList.remove('active'));
216245
if (!wasActive) pill.classList.add('active');
217246

218-
const showAll = (!wasActive && category === 'all');
219-
const showCategory = (!wasActive && category !== 'all') ? category : null;
220-
221-
// Filter cards
222-
cards.forEach(card => {
223-
if (showAll || card.dataset.category === showCategory) {
224-
card.classList.remove('filter-hidden');
225-
} else {
226-
card.classList.add('filter-hidden');
227-
}
228-
});
247+
activeCategory = (!wasActive && category !== 'all') ? category : null;
229248

230249
// Update URL hash to reflect active filter
231-
const activeFilter = pill.classList.contains('active') ? category : null;
232-
if (activeFilter && activeFilter !== 'all') {
233-
history.replaceState(null, '', '#' + activeFilter);
250+
if (activeCategory) {
251+
history.replaceState(null, '', '#' + activeCategory);
234252
} else {
235253
history.replaceState(null, '', window.location.pathname + window.location.search);
236254
}
237255

238-
// Update view toggle button state
239-
if (window.updateViewToggleState) {
240-
window.updateViewToggleState();
241-
}
256+
applyFilters();
257+
});
258+
});
259+
260+
jdkPills.forEach(pill => {
261+
pill.addEventListener('click', () => {
262+
const version = pill.dataset.jdkFilter || 'all';
263+
const wasActive = pill.classList.contains('active');
264+
265+
// Update active JDK pill (toggle off if re-clicked)
266+
jdkPills.forEach(p => p.classList.remove('active'));
267+
if (!wasActive) pill.classList.add('active');
268+
269+
activeJdk = (!wasActive && version !== 'all') ? version : null;
270+
271+
applyFilters();
242272
});
243273
});
244274

245275
// Apply filter from a given category string (or "all" / empty for no filter)
246276
const applyHashFilter = (category) => {
247277
const target = category
248-
? document.querySelector(`.filter-pill[data-filter="${category}"]`)
278+
? document.querySelector(`#categoryFilter .filter-pill[data-filter="${category}"]`)
249279
: null;
250280
if (target) {
251281
target.click();
252282
// Scroll the filter section into view
253283
const section = document.getElementById('all-comparisons');
254284
if (section) section.scrollIntoView({ behavior: 'smooth' });
255285
} else {
256-
const allButton = document.querySelector('.filter-pill[data-filter="all"]');
286+
const allButton = document.querySelector('#categoryFilter .filter-pill[data-filter="all"]');
257287
if (allButton) allButton.click();
258288
}
259289
};

site/styles.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ nav {
407407
}
408408

409409
/* ---------- Filter Pills ---------- */
410+
.filter-group {
411+
margin-bottom: 40px;
412+
}
413+
414+
.filter-group .filter-pills {
415+
margin-bottom: 12px;
416+
}
417+
418+
.filter-group .filter-pills:last-child {
419+
margin-bottom: 0;
420+
}
421+
410422
.filter-pills {
411423
display: flex;
412424
flex-wrap: wrap;

templates/index-card.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<a href="{{cardHref}}" class="tip-card filter-hidden" data-category="{{category}}">
1+
<a href="{{cardHref}}" class="tip-card filter-hidden" data-category="{{category}}" data-jdk="{{jdkVersion}}">
22
<div class="tip-card-body">
33
<div class="tip-card-header">
44
<div class="tip-badges"><span class="badge {{category}}">{{catDisplay}}</span></div>

templates/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ <h1>{{site.tagline_line1}}<br><span class="gradient">{{site.tagline_line2}}</spa
233233
<h2 class="section-title">{{site.allComparisons}}</h2>
234234
<span class="section-badge">{{site.snippetsBadge}}</span>
235235
</div>
236+
<div class="filter-group">
236237
<div class="filter-pills" id="categoryFilter">
237238
<span class="filter-label">{{filters.show}}</span>
238239
<button class="filter-pill" data-filter="all">{{filters.all}}</button>
@@ -248,6 +249,15 @@ <h2 class="section-title">{{site.allComparisons}}</h2>
248249
<button class="filter-pill" data-filter="tooling">Tooling</button>
249250
<button class="filter-pill" data-filter="enterprise">Enterprise</button>
250251
</div>
252+
<div class="filter-pills" id="jdkFilter">
253+
<span class="filter-label">{{filters.jdk}}</span>
254+
<button class="filter-pill" data-jdk-filter="all">{{filters.all}}</button>
255+
<button class="filter-pill" data-jdk-filter="11">Java 11</button>
256+
<button class="filter-pill" data-jdk-filter="17">Java 17</button>
257+
<button class="filter-pill" data-jdk-filter="21">Java 21</button>
258+
<button class="filter-pill" data-jdk-filter="25">Java 25</button>
259+
</div>
260+
</div>
251261
<div class="view-toggle-wrap">
252262
<button class="view-toggle-btn" id="viewToggle" aria-label="Toggle view mode">
253263
<span class="view-toggle-icon"></span>

translations/strings/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ sections:
3333
filters:
3434
show: 'Show:'
3535
all: All
36+
jdk: 'JDK:'
3637
difficulty:
3738
beginner: Beginner
3839
intermediate: Intermediate

0 commit comments

Comments
 (0)