diff --git a/api.php b/api.php
index 3a350f8..dba6175 100644
--- a/api.php
+++ b/api.php
@@ -315,7 +315,21 @@ function getOrInitCategories(): array {
writeData('categories.json', $cats);
return $cats;
}
- return readData('categories.json', []);
+ $cats = readData('categories.json', []);
+ // Merge in subcategories if existing file doesn't have them yet
+ $defaults = defaultCategories();
+ $defaultMap = [];
+ foreach ($defaults as $d) { $defaultMap[$d['id']] = $d; }
+ $changed = false;
+ foreach ($cats as &$cat) {
+ if (!isset($cat['subcategories']) && isset($defaultMap[$cat['id']]['subcategories'])) {
+ $cat['subcategories'] = $defaultMap[$cat['id']]['subcategories'];
+ $changed = true;
+ }
+ }
+ unset($cat);
+ if ($changed) writeData('categories.json', $cats);
+ return $cats;
}
// ─── Routing ───────────────────────────────────────────────────
diff --git a/index.html b/index.html
index 64c5f54..d0ff5ef 100644
--- a/index.html
+++ b/index.html
@@ -109,7 +109,12 @@
-
+
+
+
+
+
+
diff --git a/script.js b/script.js
index 7375ac7..38fd810 100644
--- a/script.js
+++ b/script.js
@@ -239,9 +239,10 @@ function filterPosts() {
cards.forEach(card => {
const matchesCat = currentFilter === 'all' || card.dataset.category === currentFilter;
const matchesSub = currentSubFilter === 'all' || card.dataset.subcategory === currentSubFilter;
- const title = card.querySelector('h3').textContent.toLowerCase();
- const desc = card.querySelector('p:not(.card-author)').textContent.toLowerCase();
- const matchesSearch = title.includes(query) || desc.includes(query);
+ const title = (card.querySelector('h3')?.textContent || '').toLowerCase();
+ const desc = (card.querySelector('p:not(.card-author)')?.textContent || '').toLowerCase();
+ const subLbl = (card.dataset.subcategory || '').toLowerCase();
+ const matchesSearch = !query || title.includes(query) || desc.includes(query) || subLbl.includes(query);
const show = matchesCat && matchesSub && matchesSearch;
card.style.display = show ? '' : 'none';
if (show) visible++;
@@ -402,10 +403,27 @@ function setSubmitType(type) {
document.getElementById('sub-typePostBtn').classList.toggle('active', type === 'post');
}
+function updateSubcategoryPicker() {
+ const catId = document.getElementById('sub-category').value;
+ const cat = APP.categories.find(c => c.id === catId);
+ const subs = cat?.subcategories || [];
+ const group = document.getElementById('sub-subcategory-group');
+ const sel = document.getElementById('sub-subcategory');
+ if (!subs.length) {
+ group.style.display = 'none';
+ sel.innerHTML = '';
+ } else {
+ sel.innerHTML = `` +
+ subs.map(s => ``).join('');
+ group.style.display = '';
+ }
+}
+
function openSubmitModal() {
const cats = APP.categories;
const sel = document.getElementById('sub-category');
sel.innerHTML = cats.map(c => ``).join('');
+ updateSubcategoryPicker();
setSubmitType('recipe');
document.getElementById('submitOverlay').classList.add('open');
document.body.style.overflow = 'hidden';
@@ -507,12 +525,13 @@ async function submitPublicPost() {
return;
}
- const category = document.getElementById('sub-category').value;
- const cat = APP.categories.find(c => c.id === category);
- const emoji = cat?.emoji || '📝';
- const author = document.getElementById('sub-author').value.trim() || 'Vieras';
- const desc = document.getElementById('sub-desc').value.trim();
- const images = [
+ const category = document.getElementById('sub-category').value;
+ const subcategory = document.getElementById('sub-subcategory')?.value || '';
+ const cat = APP.categories.find(c => c.id === category);
+ const emoji = cat?.emoji || '📝';
+ const author = document.getElementById('sub-author').value.trim() || 'Vieras';
+ const desc = document.getElementById('sub-desc').value.trim();
+ const images = [
document.getElementById('sub-img1').value.trim(),
document.getElementById('sub-img2').value.trim(),
document.getElementById('sub-img3').value.trim(),
@@ -520,7 +539,7 @@ async function submitPublicPost() {
const post = {
id: title.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/\s+/g,'_').replace(/[^a-z0-9_]/g,'') + '_' + Date.now(),
- title, emoji, category, author, desc, images,
+ title, emoji, category, subcategory, author, desc, images,
type: submitType,
};