Skip to content

Commit b3c9de4

Browse files
Add library group sorting by issue age
Sort library groups alongside issues when using Newest/Oldest sort. Libraries are ordered by their best matching issue (min days for newest, max days for oldest). Default restores alphabetical order. - Add id='libraries-list' to top ul for reliable targeting - Add getBestDays() helper to find representative issue age per library - Restore both library and issue order when switching back to Default
1 parent 8ccb280 commit b3c9de4

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

assets/javascript/contributing.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,62 @@ function applySorting() {
119119
});
120120
});
121121

122+
// Sort the library groups by their best matching issue
123+
var topList = document.getElementById('libraries-list');
124+
if (topList) {
125+
var libraryItems = Array.from(topList.querySelectorAll(':scope > li'));
126+
127+
if (!topList.dataset.originalOrder) {
128+
topList.dataset.originalOrder = 'stored';
129+
libraryItems.forEach(function(item, index) {
130+
item.dataset.originalIndex = index;
131+
});
132+
}
133+
134+
libraryItems.sort(function(a, b) {
135+
var bestA = getBestDays(a.querySelectorAll('.issues-list > li'), sortOrder);
136+
var bestB = getBestDays(b.querySelectorAll('.issues-list > li'), sortOrder);
137+
if (sortOrder === 'newest') {
138+
return bestA - bestB;
139+
} else {
140+
return bestB - bestA;
141+
}
142+
});
143+
144+
libraryItems.forEach(function(item) {
145+
topList.appendChild(item);
146+
});
147+
}
148+
122149
setParams();
123150
}
124151

152+
function getBestDays(issues, sortOrder) {
153+
var result = sortOrder === 'newest' ? Infinity : 0;
154+
issues.forEach(function(issue) {
155+
var days = getIssueDays(issue);
156+
if (sortOrder === 'newest') {
157+
result = Math.min(result, days);
158+
} else {
159+
result = Math.max(result, days);
160+
}
161+
});
162+
return result === Infinity ? 0 : result;
163+
}
164+
125165
function restoreOriginalOrder() {
166+
// Restore library-level order
167+
var topList = document.getElementById('libraries-list');
168+
if (topList && topList.dataset.originalOrder) {
169+
var libraryItems = Array.from(topList.querySelectorAll(':scope > li'));
170+
libraryItems.sort(function(a, b) {
171+
return (parseInt(a.dataset.originalIndex) || 0) - (parseInt(b.dataset.originalIndex) || 0);
172+
});
173+
libraryItems.forEach(function(item) {
174+
topList.appendChild(item);
175+
});
176+
}
177+
126178
// Restore issue-level order within each list
127179
var issuesLists = document.querySelectorAll('.issues-list');
128180
issuesLists.forEach(function(list) {

contributing/open_issues.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</p>
4141
</div>
4242
<h3>Open Issues</h3>
43-
<ul>
43+
<ul id="libraries-list">
4444
{% for library in site.data.libraries.open_issues %}
4545
<li>
4646
{{library[0]}}

0 commit comments

Comments
 (0)