From 34c921bc68f07eb62254067be8cb1a434837582a Mon Sep 17 00:00:00 2001 From: Gio Date: Sun, 19 May 2024 16:13:17 -0500 Subject: [PATCH] Add disabled status for #3304 (POC) --- pelican/contents.py | 24 ++++++++++++++++++++++-- pelican/generators.py | 15 ++++++++++++++- pelican/readers.py | 5 ++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 474e5bbfea..d84977f9c2 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -528,9 +528,29 @@ def refresh_metadata_intersite_links(self): self.metadata["summary"] = self._summary +class SkipStub(Content): + # Stub class representing content that should not be processed in any way + + def __init__( + self, content, metadata=None, settings=None, source_path=None, context=None + ): + self.source_path = source_path + + def is_valid(self): + return False + + @property + def content(self): + raise NotImplementedError("Stub content should not be read") + + @property + def save_as(self): + raise NotImplementedError("Stub content cannot be saved") + + class Page(Content): mandatory_properties = ("title",) - allowed_statuses = ("published", "hidden", "draft") + allowed_statuses = ("published", "hidden", "draft", "disabled") default_status = "published" default_template = "page" @@ -541,7 +561,7 @@ def _expand_settings(self, key): class Article(Content): mandatory_properties = ("title", "date", "category") - allowed_statuses = ("published", "hidden", "draft") + allowed_statuses = ("published", "hidden", "draft", "disabled") default_status = "published" default_template = "article" diff --git a/pelican/generators.py b/pelican/generators.py index 3b5ca9e4b4..b64f76431a 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -18,7 +18,7 @@ ) from pelican.cache import FileStampDataCacher -from pelican.contents import Article, Page, Static +from pelican.contents import Article, Page, Static, SkipStub from pelican.plugins import signals from pelican.plugins._utils import plugin_enabled from pelican.readers import Readers @@ -675,6 +675,10 @@ def generate_context(self): self._add_failed_source_path(f) continue + if isinstance(article, SkipStub): + logger.debug("Safely skipping %s", f) + continue + if not article.is_valid(): self._add_failed_source_path(f) continue @@ -687,6 +691,8 @@ def generate_context(self): all_drafts.append(article) elif article.status == "hidden": hidden_articles.append(article) + elif article.status == "disabled": + raise AssertionError("Disabled documents should be skipped") self.add_source_path(article) self.add_static_links(article) @@ -879,6 +885,10 @@ def generate_context(self): self._add_failed_source_path(f) continue + if isinstance(page, SkipStub): + logger.debug("Safely skipping %s", f) + continue + if not page.is_valid(): self._add_failed_source_path(f) continue @@ -891,6 +901,9 @@ def generate_context(self): hidden_pages.append(page) elif page.status == "draft": draft_pages.append(page) + elif page.status == "disabled": + raise AssertionError("Disabled documents should be skipped") + self.add_source_path(page) self.add_static_links(page) diff --git a/pelican/readers.py b/pelican/readers.py index 60b9765a78..ec5b155edb 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -15,7 +15,7 @@ from pelican import rstdirectives # NOQA from pelican.cache import FileStampDataCacher -from pelican.contents import Author, Category, Page, Tag +from pelican.contents import Author, Category, Page, Tag, SkipStub from pelican.plugins import signals from pelican.utils import get_date, pelican_open, posixize_path @@ -646,6 +646,9 @@ def typogrify_wrapper(text): ) context_signal.send(context_sender, metadata=metadata) + if metadata.get("status") == "disabled": + content_class = SkipStub + return content_class( content=content, metadata=metadata,