From 6f10e8f2b61684eb8052764e23744610ae8a4a6c Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Sun, 11 Oct 2026 19:52:32 +0200 Subject: [PATCH] fix: Don't link to missing category pages When `CATEGORY_SAVE_AS` is disabled but `CATEGORIES_SAVE_AS` is not, the category index page was still generated, and its links pointed to category pages that don't exist. This change shows category names without links in the Simple and NotMyIdea themes in such cases and also documents that both settings must be disabled to remove all category-related output. --- docs/settings.rst | 3 ++ pelican/tests/test_theme.py | 46 ++++++++++--------- .../notmyidea/templates/categories.html | 2 +- .../themes/simple/templates/categories.html | 2 +- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 7b78a75f..5551a4bf 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -596,6 +596,9 @@ This would save your articles into something like The location to save a category. The default is ``"category/{slug}.html"``. Set this to ``""`` to disable category pages. Articles still keep their categories, which can be used in URL patterns such as ``ARTICLE_SAVE_AS``. + To disable all category output, also set ``CATEGORIES_SAVE_AS = None`` + and ``CATEGORY_FEED_ATOM = None`` (as well as ``CATEGORY_FEED_RSS``, if + you have enabled it). .. data:: TAG_URL diff --git a/pelican/tests/test_theme.py b/pelican/tests/test_theme.py index 7e0fff6a..742f9b73 100644 --- a/pelican/tests/test_theme.py +++ b/pelican/tests/test_theme.py @@ -184,31 +184,33 @@ class TestTemplateInheritance(LoggedTestCase): try: for theme in ("simple", "notmyidea"): - with self.subTest(theme=theme): - settings = read_settings( - path=None, - override={ - "THEME": theme, - "PATH": content_dir, - "OUTPUT_PATH": self.temp_output, - "CACHE_PATH": self.temp_cache, - "SITEURL": "http://example.com", - "ARTICLE_SAVE_AS": "{category}/{slug}.html", - "CATEGORY_SAVE_AS": False, - "CATEGORIES_SAVE_AS": False, - }, - ) + for category_save_as in ("", None, False): + with self.subTest(theme=theme, CATEGORY_SAVE_AS=category_save_as): + settings = read_settings( + path=None, + override={ + "THEME": theme, + "PATH": content_dir, + "OUTPUT_PATH": self.temp_output, + "CACHE_PATH": self.temp_cache, + "SITEURL": "http://example.com", + "ARTICLE_SAVE_AS": "{category}/{slug}.html", + "CATEGORY_SAVE_AS": category_save_as, + }, + ) - pelican = Pelican(settings=settings) - mute(True)(pelican.run)() + pelican = Pelican(settings=settings) + mute(True)(pelican.run)() - with open( - os.path.join(self.temp_output, "blog", "in-blog.html") - ) as f: - content = f.read() + for page in ("blog/in-blog.html", "categories.html"): + with open(os.path.join(self.temp_output, page)) as f: + content = f.read() - self.assertIn("blog", content) - self.assertNotIn("/category/", content) + self.assertIn("blog", content) + self.assertNotIn("/category/", content) + self.assertFalse( + os.path.exists(os.path.join(self.temp_output, "category")) + ) finally: rmtree(content_dir) diff --git a/pelican/themes/notmyidea/templates/categories.html b/pelican/themes/notmyidea/templates/categories.html index 033f892a..4f64bb60 100644 --- a/pelican/themes/notmyidea/templates/categories.html +++ b/pelican/themes/notmyidea/templates/categories.html @@ -8,7 +8,7 @@

Categories for {{ SITENAME }}

diff --git a/pelican/themes/simple/templates/categories.html b/pelican/themes/simple/templates/categories.html index c723f8a0..700ef657 100644 --- a/pelican/themes/simple/templates/categories.html +++ b/pelican/themes/simple/templates/categories.html @@ -6,7 +6,7 @@

Categories on {{ SITENAME }}

{% endblock %}