Skip to content

Commit e810a83

Browse files
committed
bug fix
1 parent b27b0db commit e810a83

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

_layouts/phd_thesis.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---
44

55
<div class="thesis-list">
6-
<table class="table thesis-table">
6+
<table class="table thesis-table" id="phd-table">
77
<thead>
88
<tr>
99
<th scope="col">Date</th>
@@ -39,3 +39,21 @@
3939
</tbody>
4040
</table>
4141
</div>
42+
<script>
43+
(function(){
44+
const MON = {Jan:1,Feb:2,Mar:3,Apr:4,May:5,Jun:6,Jul:7,Aug:8,Sep:9,Oct:10,Nov:11,Dec:12};
45+
function dateKey(td) {
46+
const [mon, yr] = td.split(' ');
47+
return (parseInt(yr)||0)*100 + (MON[mon]||0);
48+
}
49+
const tbody = document.querySelector('#phd-table tbody');
50+
if (!tbody) return;
51+
const rows = Array.from(tbody.querySelectorAll('tr'));
52+
rows.sort(function(a,b){
53+
const dk = dateKey(b.cells[0].textContent.trim()) - dateKey(a.cells[0].textContent.trim());
54+
if (dk !== 0) return dk;
55+
return a.cells[1].textContent.trim().localeCompare(b.cells[1].textContent.trim());
56+
});
57+
rows.forEach(function(r){ tbody.appendChild(r); });
58+
})();
59+
</script>

admin/panel.html

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5716,6 +5716,20 @@
57165716
if (key === 'co_advisors') obj.co_advisors = [];
57175717
}
57185718

5719+
// ── Sort helper ──────────────────────────────────────────────────────────────
5720+
const PHD_MONTH_ORDER = {Jan:1,Feb:2,Mar:3,Apr:4,May:5,Jun:6,Jul:7,Aug:8,Sep:9,Oct:10,Nov:11,Dec:12};
5721+
function phdDateKey(date) {
5722+
const [mon, yr] = (date || '').split(' ');
5723+
return (parseInt(yr) || 0) * 100 + (PHD_MONTH_ORDER[mon] || 0);
5724+
}
5725+
function sortPhdEntries(arr) {
5726+
return [...arr].sort((a, b) => {
5727+
const dk = phdDateKey(b.date) - phdDateKey(a.date);
5728+
if (dk !== 0) return dk;
5729+
return (a.author || '').localeCompare(b.author || '');
5730+
});
5731+
}
5732+
57195733
// ── Serialize entries back to YAML ────────────────────────────────────────────
57205734
function serializePhdYaml(entries) {
57215735
return entries.map(e => {
@@ -5840,7 +5854,7 @@
58405854
container.innerHTML = '<div class="ex-empty"><span class="spin"></span> Loading\u2026</div>'; return;
58415855
}
58425856
const q = (document.getElementById('phd-search')?.value || '').toLowerCase();
5843-
const filtered = phdState.entries.filter((e, i) => {
5857+
const filtered = sortPhdEntries(phdState.entries).filter((e) => {
58445858
if (!q) return true;
58455859
return (e.author + ' ' + e.title + ' ' + e.date).toLowerCase().includes(q);
58465860
});
@@ -5881,7 +5895,7 @@
58815895

58825896
async function deletePhd(idx) {
58835897
const entry = phdState.entries[idx];
5884-
const updated = phdState.entries.filter((_, i) => i !== idx);
5898+
const updated = sortPhdEntries(phdState.entries.filter((_, i) => i !== idx));
58855899
await savePhdToGitHub(updated, `Remove PhD thesis: ${entry.author}`, { deletePdf: entry.pdf });
58865900
}
58875901

@@ -5929,9 +5943,10 @@
59295943
if (editingPhdIdx !== null) {
59305944
updated = [...phdState.entries];
59315945
updated[editingPhdIdx] = entry;
5946+
updated = sortPhdEntries(updated);
59325947
commitMsg = `Update PhD thesis: ${author}`;
59335948
} else {
5934-
updated = [entry, ...phdState.entries];
5949+
updated = sortPhdEntries([entry, ...phdState.entries]);
59355950
commitMsg = `Add PhD thesis: ${author}`;
59365951
}
59375952
await savePhdToGitHub(updated, commitMsg);

0 commit comments

Comments
 (0)