|
5716 | 5716 | if (key === 'co_advisors') obj.co_advisors = []; |
5717 | 5717 | } |
5718 | 5718 |
|
| 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 | + |
5719 | 5733 | // ── Serialize entries back to YAML ──────────────────────────────────────────── |
5720 | 5734 | function serializePhdYaml(entries) { |
5721 | 5735 | return entries.map(e => { |
|
5840 | 5854 | container.innerHTML = '<div class="ex-empty"><span class="spin"></span> Loading\u2026</div>'; return; |
5841 | 5855 | } |
5842 | 5856 | const q = (document.getElementById('phd-search')?.value || '').toLowerCase(); |
5843 | | - const filtered = phdState.entries.filter((e, i) => { |
| 5857 | + const filtered = sortPhdEntries(phdState.entries).filter((e) => { |
5844 | 5858 | if (!q) return true; |
5845 | 5859 | return (e.author + ' ' + e.title + ' ' + e.date).toLowerCase().includes(q); |
5846 | 5860 | }); |
|
5881 | 5895 |
|
5882 | 5896 | async function deletePhd(idx) { |
5883 | 5897 | const entry = phdState.entries[idx]; |
5884 | | - const updated = phdState.entries.filter((_, i) => i !== idx); |
| 5898 | + const updated = sortPhdEntries(phdState.entries.filter((_, i) => i !== idx)); |
5885 | 5899 | await savePhdToGitHub(updated, `Remove PhD thesis: ${entry.author}`, { deletePdf: entry.pdf }); |
5886 | 5900 | } |
5887 | 5901 |
|
|
5929 | 5943 | if (editingPhdIdx !== null) { |
5930 | 5944 | updated = [...phdState.entries]; |
5931 | 5945 | updated[editingPhdIdx] = entry; |
| 5946 | + updated = sortPhdEntries(updated); |
5932 | 5947 | commitMsg = `Update PhD thesis: ${author}`; |
5933 | 5948 | } else { |
5934 | | - updated = [entry, ...phdState.entries]; |
| 5949 | + updated = sortPhdEntries([entry, ...phdState.entries]); |
5935 | 5950 | commitMsg = `Add PhD thesis: ${author}`; |
5936 | 5951 | } |
5937 | 5952 | await savePhdToGitHub(updated, commitMsg); |
|
0 commit comments