mirror of
https://github.com/kbenestad/mdcms.git
synced 2026-06-18 15:24:32 +00:00
Show category-less posts/pages in all categories
Files without a category suffix (e.g. post.md alongside post.en.md) previously only appeared in the default category. They now appear in every category, so untranslated content is always visible. - mdcms.py: nav entries with a bare variant get `uncategorized: true`; search.json keeps `category: null` instead of mapping to default code - index.html: pageShouldDisplay, posts filter, and category dropdown all treat uncategorized/null-category items as universally visible https://claude.ai/code/session_01EzU13EL8D5Ud2ngQUKDj9e
This commit is contained in:
parent
aa9ea34683
commit
e1527d8e3b
2 changed files with 14 additions and 8 deletions
|
|
@ -1200,6 +1200,7 @@ body {
|
||||||
// - Otherwise: hide
|
// - Otherwise: hide
|
||||||
if (!categoriesUse) return true;
|
if (!categoriesUse) return true;
|
||||||
if (page.file === defaultPage()) return true;
|
if (page.file === defaultPage()) return true;
|
||||||
|
if (page.uncategorized) return true;
|
||||||
const variants = page.variants || [];
|
const variants = page.variants || [];
|
||||||
if (variants.includes(activeCategory)) return true;
|
if (variants.includes(activeCategory)) return true;
|
||||||
const cat = categoriesByCode[activeCategory];
|
const cat = categoriesByCode[activeCategory];
|
||||||
|
|
@ -1602,7 +1603,7 @@ function fmtDatetime(dtStr) {
|
||||||
|
|
||||||
// Category filter
|
// Category filter
|
||||||
if (categoriesUse && activeCategory) {
|
if (categoriesUse && activeCategory) {
|
||||||
posts = posts.filter(function(e) { return e.category === activeCategory; });
|
posts = posts.filter(function(e) { return !e.category || e.category === activeCategory; });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field filter
|
// Field filter
|
||||||
|
|
@ -2245,7 +2246,7 @@ function fmtDatetime(dtStr) {
|
||||||
? navData.find(p => p.file === currentPage)
|
? navData.find(p => p.file === currentPage)
|
||||||
: null;
|
: null;
|
||||||
categoriesList.forEach(cat => {
|
categoriesList.forEach(cat => {
|
||||||
const hasVariant = !page || !page.variants || page.variants.includes(cat.code);
|
const hasVariant = !page || page.uncategorized || !(page.variants && page.variants.length) || page.variants.includes(cat.code);
|
||||||
const hasMsg = !!cat.notfoundmessage;
|
const hasMsg = !!cat.notfoundmessage;
|
||||||
if (hasVariant || hasMsg || cat.code === activeCategory) out.add(cat.code);
|
if (hasVariant || hasMsg || cat.code === activeCategory) out.add(cat.code);
|
||||||
});
|
});
|
||||||
|
|
@ -2272,7 +2273,7 @@ function fmtDatetime(dtStr) {
|
||||||
'data-code': cat.code
|
'data-code': cat.code
|
||||||
});
|
});
|
||||||
option.appendChild(document.createTextNode(primary));
|
option.appendChild(document.createTextNode(primary));
|
||||||
const hasVariant = !page || !page.variants || page.variants.includes(cat.code);
|
const hasVariant = !page || page.uncategorized || !(page.variants && page.variants.length) || page.variants.includes(cat.code);
|
||||||
if (!hasVariant && cat.notfoundmessage) {
|
if (!hasVariant && cat.notfoundmessage) {
|
||||||
option.appendChild(el('span', { className: 'secondary', textContent: cat.notfoundmessage }));
|
option.appendChild(el('span', { className: 'secondary', textContent: cat.notfoundmessage }));
|
||||||
} else if (secondary) {
|
} else if (secondary) {
|
||||||
|
|
|
||||||
15
mdcms.py
15
mdcms.py
|
|
@ -266,10 +266,14 @@ def build_page_nav(
|
||||||
}
|
}
|
||||||
if categories_use:
|
if categories_use:
|
||||||
covered = {}
|
covered = {}
|
||||||
|
has_uncategorized = False
|
||||||
for code, record in variants.items():
|
for code, record in variants.items():
|
||||||
key = code if code is not None else default_code
|
if code is None:
|
||||||
if key:
|
has_uncategorized = True
|
||||||
covered[key] = record.get("title", "")
|
else:
|
||||||
|
covered[code] = record.get("title", "")
|
||||||
|
if has_uncategorized:
|
||||||
|
entry["uncategorized"] = True
|
||||||
entry["variants"] = sorted(covered.keys())
|
entry["variants"] = sorted(covered.keys())
|
||||||
entry["titles"] = covered
|
entry["titles"] = covered
|
||||||
out.append(entry)
|
out.append(entry)
|
||||||
|
|
@ -313,6 +317,8 @@ def generate_nav_yml(sections: list, pages: list, categories_use: bool = False)
|
||||||
if p.get("section-id"):
|
if p.get("section-id"):
|
||||||
lines.append(f" section-id: {p['section-id']}")
|
lines.append(f" section-id: {p['section-id']}")
|
||||||
lines.append(f" sort: {p.get('sort', 100)}")
|
lines.append(f" sort: {p.get('sort', 100)}")
|
||||||
|
if categories_use and p.get("uncategorized"):
|
||||||
|
lines.append(" uncategorized: true")
|
||||||
if categories_use and p.get("variants"):
|
if categories_use and p.get("variants"):
|
||||||
lines.append(f" variants: [{', '.join(p['variants'])}]")
|
lines.append(f" variants: [{', '.join(p['variants'])}]")
|
||||||
if categories_use and p.get("titles"):
|
if categories_use and p.get("titles"):
|
||||||
|
|
@ -344,8 +350,7 @@ def generate_search_json(
|
||||||
"body": r.get("body", ""),
|
"body": r.get("body", ""),
|
||||||
}
|
}
|
||||||
if categories_use:
|
if categories_use:
|
||||||
code = r.get("code")
|
entry["category"] = r.get("code") # None → null = show in all categories
|
||||||
entry["category"] = code if code is not None else default_code
|
|
||||||
out.append(entry)
|
out.append(entry)
|
||||||
return json.dumps(out, indent=2, ensure_ascii=False)
|
return json.dumps(out, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue