From 11dc053118c736d2ccdb4b984c96f952563f5499 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 19 May 2026 07:00:36 +0000 Subject: [PATCH] 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 --- docs/unreleased.md | 10 ++++++---- mdcms.py | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/unreleased.md b/docs/unreleased.md index ee88ec0..da789a7 100644 --- a/docs/unreleased.md +++ b/docs/unreleased.md @@ -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 diff --git a/mdcms.py b/mdcms.py index b50ebb5..8a90c69 100644 --- a/mdcms.py +++ b/mdcms.py @@ -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: - has_uncategorized = True + 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)