Add draft content support, excluded from build by default

This commit is contained in:
2026-08-26 03:21:27 +02:00
parent 48af9665f0
commit 728b1ee1bf
3 changed files with 7 additions and 0 deletions
+1
View File
@@ -27,6 +27,7 @@ class Article(Content):
meta.get("updated", None), meta.get("updated", None),
set(meta["tags"]) if "tags" in meta else None, set(meta["tags"]) if "tags" in meta else None,
meta.get("summary", None), meta.get("summary", None),
meta.get("draft", False),
) )
self.title: str = meta["title"] self.title: str = meta["title"]
+2
View File
@@ -28,6 +28,7 @@ class Content(Output):
updated: date | None = None, updated: date | None = None,
tags: set[str] | None = None, tags: set[str] | None = None,
summary: str | None = None, summary: str | None = None,
draft: bool = False,
): ):
super().__init__(site, Content.build_path(section, slug)) super().__init__(site, Content.build_path(section, slug))
if tags is None: if tags is None:
@@ -42,6 +43,7 @@ class Content(Output):
self.updated = updated self.updated = updated
self.tags: set[str] = tags self.tags: set[str] = tags
self.summary: str | None = summary self.summary: str | None = summary
self.draft: bool = draft
@staticmethod @staticmethod
def build_path(section: str, slug: str) -> Path: def build_path(section: str, slug: str) -> Path:
+4
View File
@@ -34,6 +34,7 @@ class ConfigError(RuntimeError):
class Site: class Site:
def __init__(self, site: Path, drafts: bool = False): def __init__(self, site: Path, drafts: bool = False):
self.site_path = site.resolve() self.site_path = site.resolve()
self.drafts = drafts
self.content: list[Content] = [] self.content: list[Content] = []
self.directories: list[Directory] = [] self.directories: list[Directory] = []
self.other_outputs: list[Output] = [] self.other_outputs: list[Output] = []
@@ -178,6 +179,9 @@ class Site:
for file in content_path.rglob("*"): for file in content_path.rglob("*"):
if file.is_file() and is_content(file): if file.is_file() and is_content(file):
content = create_content(self, file) content = create_content(self, file)
if content.draft and not self.drafts:
log.debug("Skipping draft content %s", file)
continue
self.add_by_path(content) self.add_by_path(content)
self.add_by_section(content) self.add_by_section(content)
self.add_by_tag(content) self.add_by_tag(content)