Skip to content

Commit 8ccb280

Browse files
Use data-days-open attribute instead of parsing title text
Simplify sorting by reading days_open from the issue data via a data attribute on each li element, replacing the regex title parser.
1 parent 90f2612 commit 8ccb280

File tree

2 files changed

+2
-62
lines changed

2 files changed

+2
-62
lines changed

assets/javascript/contributing.js

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,7 @@ function issueSelectHandler(event, isPopState) {
7474
}
7575

7676
function getIssueDays(element) {
77-
// Parse "(Open X days)" from the issue title text
78-
var text = element.textContent || '';
79-
var match = text.match(/\(Open\s+(\d+)\s+days?\)/i);
80-
if (match) {
81-
return parseInt(match[1], 10);
82-
}
83-
return 0;
77+
return parseInt(element.dataset.daysOpen, 10) || 0;
8478
}
8579

8680
function applySorting() {
@@ -125,64 +119,10 @@ function applySorting() {
125119
});
126120
});
127121

128-
// Also sort the library-level list items by their oldest/newest issue
129-
var topList = document.querySelector('.open-issues > ul');
130-
if (topList) {
131-
var libraryItems = Array.from(topList.querySelectorAll(':scope > li'));
132-
133-
if (!topList.dataset.originalOrder) {
134-
topList.dataset.originalOrder = 'stored';
135-
libraryItems.forEach(function(item, index) {
136-
item.dataset.originalIndex = index;
137-
});
138-
}
139-
140-
libraryItems.sort(function(a, b) {
141-
var issuesA = a.querySelectorAll('.issues-list > li');
142-
var issuesB = b.querySelectorAll('.issues-list > li');
143-
var maxA = getMaxDays(issuesA, sortOrder);
144-
var maxB = getMaxDays(issuesB, sortOrder);
145-
if (sortOrder === 'newest') {
146-
return maxA - maxB;
147-
} else {
148-
return maxB - maxA;
149-
}
150-
});
151-
152-
libraryItems.forEach(function(item) {
153-
topList.appendChild(item);
154-
});
155-
}
156-
157122
setParams();
158123
}
159124

160-
function getMaxDays(issues, sortOrder) {
161-
var result = sortOrder === 'newest' ? Infinity : 0;
162-
issues.forEach(function(issue) {
163-
var days = getIssueDays(issue);
164-
if (sortOrder === 'newest') {
165-
result = Math.min(result, days);
166-
} else {
167-
result = Math.max(result, days);
168-
}
169-
});
170-
return result === Infinity ? 0 : result;
171-
}
172-
173125
function restoreOriginalOrder() {
174-
// Restore library-level order
175-
var topList = document.querySelector('.open-issues > ul');
176-
if (topList && topList.dataset.originalOrder) {
177-
var libraryItems = Array.from(topList.querySelectorAll(':scope > li'));
178-
libraryItems.sort(function(a, b) {
179-
return (parseInt(a.dataset.originalIndex) || 0) - (parseInt(b.dataset.originalIndex) || 0);
180-
});
181-
libraryItems.forEach(function(item) {
182-
topList.appendChild(item);
183-
});
184-
}
185-
186126
// Restore issue-level order within each list
187127
var issuesLists = document.querySelectorAll('.issues-list');
188128
issuesLists.forEach(function(list) {

contributing/open_issues.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h3>Open Issues</h3>
5151
{{ label | downcase | replace: ' ', '-' }}
5252
{% endfor %}
5353
{% endcapture %}
54-
<li class="{{ classes | strip }}"><a href="{{ issue.url }}">{{ issue.title }}</a>
54+
<li class="{{ classes | strip }}" data-days-open="{{ issue.days_open }}"><a href="{{ issue.url }}">{{ issue.title }}</a>
5555
{% for label in issue.labels %}
5656
{% if label != 'None' %}
5757
<span class="issue-label tag-{{ label | downcase | replace: ' ', '-' }}">{{label}}</span>

0 commit comments

Comments
 (0)