Scope uncategorized-post fix to posts/ only

Pages without a category suffix still map to the default category.
Only posts/ files without a suffix get uncategorized: true in nav.yml
and category: null in search.json.

https://claude.ai/code/session_01EzU13EL8D5Ud2ngQUKDj9e
This commit is contained in:
Claude 2026-05-19 07:00:36 +00:00
parent 51cb68c4f9
commit 11dc053118
No known key found for this signature in database
2 changed files with 19 additions and 6 deletions

View file

@ -4,23 +4,25 @@ Changes merged into `development` that have not yet been released to `main`.
---
## Untranslated content now visible in all categories
## Untranslated posts now visible in all categories
**Status:** On `development`, pending release.
### What was broken
When the category system is enabled, a page or post file without a category suffix (e.g. `posts/my-post.md`) was silently assigned to the default category only. Switching to any other category caused those files to disappear from the navigation and from `posts-*` tag listings — even though no translated version existed. If you wrote English posts without a `.en.md` suffix, they simply vanished the moment a visitor switched language.
When the category system is enabled, a post file without a category suffix (e.g. `posts/my-post.md`) was silently assigned to the default category only. Switching to any other category caused those posts to disappear from the nav and from `posts-*` tag listings — even though no translated version existed. If you wrote posts without a language suffix, they simply vanished the moment a visitor switched category.
Pages without a category suffix are unaffected: they continue to be assigned to the default category, which is the correct behaviour for pages.
### What it does now
Files without a category suffix are treated as uncategorised — meaning they belong to every category, not just the default one. A post called `my-post.md` now appears in the nav and post lists regardless of which category is active. A post called `my-post.en.md` still appears only in the `en` category as before.
Posts without a category suffix are treated as uncategorised — meaning they appear in every category. A post called `my-post.md` now shows up regardless of which category is active. A post called `my-post.en.md` still appears only in the `en` category as before.
Mixed situations work as expected: if you have both `my-post.md` and `my-post.nb.md`, the Norwegian variant is shown when the `nb` category is active, and the bare `my-post.md` is shown for every other category.
### What changes in the build output
After rebuilding a site with `mdcms build`, affected entries in `nav.yml` gain an `uncategorized: true` field:
After rebuilding a site with `mdcms build`, affected post entries in `nav.yml` gain an `uncategorized: true` field:
```yaml
- file: posts/my-post.md

View file

@ -265,11 +265,15 @@ def build_page_nav(
"sort": sort,
}
if categories_use:
is_post = file.startswith("posts/")
covered = {}
has_uncategorized = False
for code, record in variants.items():
if code is None:
if is_post:
has_uncategorized = True
elif default_code:
covered[default_code] = record.get("title", "")
else:
covered[code] = record.get("title", "")
if has_uncategorized:
@ -350,7 +354,14 @@ def generate_search_json(
"body": r.get("body", ""),
}
if categories_use:
entry["category"] = r.get("code") # None → null = show in all categories
code = r.get("code")
is_post = r.get("file", "").startswith("posts/")
if code is not None:
entry["category"] = code
elif is_post:
entry["category"] = None # null = show in all categories
else:
entry["category"] = default_code
out.append(entry)
return json.dumps(out, indent=2, ensure_ascii=False)