diff --git a/admin.html b/admin.html index 7cea3b6..cc4a086 100644 --- a/admin.html +++ b/admin.html @@ -576,6 +576,15 @@ // =========================== // CATEGORY HELPERS // =========================== + function sortSubcategories(subs) { + return [...subs].sort((a, b) => { + const aM = a.fi.toLowerCase() === 'muut' ? 1 : 0; + const bM = b.fi.toLowerCase() === 'muut' ? 1 : 0; + if (aM !== bM) return aM - bM; + return a.fi.localeCompare(b.fi, 'fi'); + }); + } + function getCatLabel(id) { const cat = ADMIN.categories.find(c => c.id === id); return cat ? cat.fi : id; @@ -589,7 +598,7 @@ const el = document.getElementById('catList'); if (!cats.length) { el.innerHTML = `
${at('cat_empty')}
`; return; } el.innerHTML = cats.map(c => { - const subs = (c.subcategories || []).map(s => + const subs = sortSubcategories(c.subcategories || []).map(s => `${s.fi} ` ).join(''); return ` @@ -670,7 +679,7 @@ function updateAdminSubcategories(checked = []) { const catId = document.getElementById('postCategory').value; const cat = ADMIN.categories.find(c => c.id === catId); - const subs = cat?.subcategories || []; + const subs = sortSubcategories(cat?.subcategories || []); const group = document.getElementById('adminSubcatGroup'); const box = document.getElementById('adminSubcatCheckboxes'); if (!subs.length) { group.style.display = 'none'; box.innerHTML = ''; return; } diff --git a/script.js b/script.js index 13e1655..1c74979 100644 --- a/script.js +++ b/script.js @@ -81,6 +81,18 @@ function applyTranslations() { document.querySelectorAll('[data-i18n-ph]').forEach(el => { el.placeholder = t(el.dataset.i18nPh); }); } +// =========================== +// HELPERS +// =========================== +function sortSubcategories(subs) { + return [...subs].sort((a, b) => { + const aM = a.fi.toLowerCase() === 'muut' ? 1 : 0; + const bM = b.fi.toLowerCase() === 'muut' ? 1 : 0; + if (aM !== bM) return aM - bM; + return a.fi.localeCompare(b.fi, 'fi'); + }); +} + // =========================== // API // =========================== @@ -256,7 +268,7 @@ function renderSubFilters() { if (!container) return; if (currentFilter === 'all') { container.innerHTML = ''; return; } const cat = APP.categories.find(c => c.id === currentFilter); - const subs = (cat?.subcategories || []).filter(s => countPostsInSubcategory(currentFilter, s.id) > 0); + const subs = sortSubcategories((cat?.subcategories || []).filter(s => countPostsInSubcategory(currentFilter, s.id) > 0)); if (!subs.length) { container.innerHTML = ''; return; } container.innerHTML = `` + @@ -453,7 +465,7 @@ function setSubmitType(type) { function updateSubcategoryPicker() { const catId = document.getElementById('sub-category').value; const cat = APP.categories.find(c => c.id === catId); - const subs = cat?.subcategories || []; + const subs = sortSubcategories(cat?.subcategories || []); const group = document.getElementById('sub-subcategory-group'); const sel = document.getElementById('sub-subcategory'); if (!subs.length) {