From 04948a93739f1d80c53cf4d63882733e19bb597b Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Mon, 14 Jul 2025 16:04:05 -0400 Subject: [PATCH 1/3] formatted python files --- src/zona/builder.py | 20 ++++++++++++++------ src/zona/cli.py | 8 ++++++-- src/zona/config.py | 4 +++- src/zona/server.py | 4 +++- src/zona/util.py | 11 ++++++++--- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/zona/builder.py b/src/zona/builder.py index 12b5458..a04b2eb 100644 --- a/src/zona/builder.py +++ b/src/zona/builder.py @@ -48,7 +48,9 @@ class ZonaBuilder: destination=destination, url=str(destination.relative_to(layout.output)), ) - if path.name.endswith(".md") and not path.is_relative_to( + if path.name.endswith( + ".md" + ) and not path.is_relative_to( layout.root / "content" / "static" ): logger.debug(f"Parsing {path.name}.") @@ -69,11 +71,13 @@ class ZonaBuilder: item.copy = False name = destination.stem if name == "index": - item.destination = item.destination.with_suffix( - ".html" + item.destination = ( + item.destination.with_suffix(".html") ) else: - relative = path.relative_to(base).with_suffix("") + relative = path.relative_to(base).with_suffix( + "" + ) name = relative.stem item.destination = ( layout.output @@ -85,7 +89,9 @@ class ZonaBuilder: layout.output ) item.url = ( - "" if rel_url == Path(".") else rel_url.as_posix() + "" + if rel_url == Path(".") + else rel_url.as_posix() ) items.append(item) self.items = items @@ -111,7 +117,9 @@ class ZonaBuilder: # write code highlighting stylesheet if self.config.markdown.syntax_highlighting.enabled: pygments_style = zmd.get_style_defs(self.config) - pygments_path = self.layout.output / "static" / "pygments.css" + pygments_path = ( + self.layout.output / "static" / "pygments.css" + ) util.ensure_parents(pygments_path) pygments_path.write_text(pygments_style) for item in self.item_map.values(): diff --git a/src/zona/cli.py b/src/zona/cli.py index a7e2dd5..4b48d3a 100644 --- a/src/zona/cli.py +++ b/src/zona/cli.py @@ -59,7 +59,9 @@ def build( """ if draft: print("Option override: including drafts.") - builder = ZonaBuilder(cli_root=root, cli_output=output, draft=draft) + builder = ZonaBuilder( + cli_root=root, cli_output=output, draft=draft + ) builder.build() @@ -73,7 +75,9 @@ def serve( ] = None, host: Annotated[ str, - typer.Option("--host", help="Hostname for live preview server."), + typer.Option( + "--host", help="Hostname for live preview server." + ), ] = "localhost", port: Annotated[ int, diff --git a/src/zona/config.py b/src/zona/config.py index cc56ec2..2a50fd4 100644 --- a/src/zona/config.py +++ b/src/zona/config.py @@ -76,7 +76,9 @@ IGNORELIST = [".marksman.toml"] class ZonaConfig: base_url: str = "/" # dictionary where key is name, value is url - sitemap: SitemapConfig = field(default_factory=lambda: {"Home": "/"}) + sitemap: SitemapConfig = field( + default_factory=lambda: {"Home": "/"} + ) # list of globs relative to content that should be ignored ignore: list[str] = field(default_factory=lambda: IGNORELIST) markdown: MarkdownConfig = field(default_factory=MarkdownConfig) diff --git a/src/zona/server.py b/src/zona/server.py index 23c4c0b..82e6381 100644 --- a/src/zona/server.py +++ b/src/zona/server.py @@ -238,7 +238,9 @@ def serve( event_handler, path=str(root / "content"), recursive=True ) observer.schedule( - event_handler, path=str(root / "templates"), recursive=True + event_handler, + path=str(root / "templates"), + recursive=True, ) observer.start() diff --git a/src/zona/util.py b/src/zona/util.py index 2d5c514..9ccc2c6 100644 --- a/src/zona/util.py +++ b/src/zona/util.py @@ -19,7 +19,9 @@ def get_resource(path: str) -> ZonaResource: if file.is_file(): return ZonaResource(name=path, contents=file.read_text()) else: - raise FileNotFoundError(f"{path} is not a valid Zona resource!") + raise FileNotFoundError( + f"{path} is not a valid Zona resource!" + ) def get_resources(subdir: str) -> list[ZonaResource]: @@ -75,10 +77,13 @@ def normalize_url(url: str) -> str: return url -def should_ignore(path: Path, patterns: list[str], base: Path) -> bool: +def should_ignore( + path: Path, patterns: list[str], base: Path +) -> bool: rel_path = path.relative_to(base) return any( - fnmatch.fnmatch(str(rel_path), pattern) for pattern in patterns + fnmatch.fnmatch(str(rel_path), pattern) + for pattern in patterns ) From 27178dc6d8c0f43dfa9da56db8e9d772bc99ffa0 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Mon, 14 Jul 2025 16:06:24 -0400 Subject: [PATCH 2/3] updated formatter config --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index caf20fb..2a2e6b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,7 @@ allowedUntypedLibraries = ["frontmatter", "pygments", "pymdownx", "l2m4m"] [tool.ruff] line-length = 70 indent-width = 4 -target-version = "py311" +target-version = "py312" [tool.ruff.lint] fixable = ["ALL"] From 07152a37468309a57e9fef6698f5bed65807e4bd Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Mon, 14 Jul 2025 16:11:47 -0400 Subject: [PATCH 3/3] feat: ignore frontmatter option --- README.md | 1 + src/zona/builder.py | 22 +++++++--------------- src/zona/metadata.py | 1 + 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index dcccab2..d46a69b 100644 --- a/README.md +++ b/README.md @@ -317,6 +317,7 @@ available: | `template` | `str \| none` = `none` | Template to use for this page. Relative to `templates/`, `.html` extension optional. | | `post` | `bool \| none` = `none` | Whether this page is a **post**. `true`/`false` is _absolute_. Leave it unset for automatic detection. | | `draft` | `bool` = `false` | Whether this page is a draft. See [drafts](#drafts) for more. | +| `ignore` | `bool` = `false` | Whether this page should be ignored in _both_ `final` and `draft` contexts. | | `math` | `bool` = `true` | Whether the LaTeX extension should be enabled for this page. | **Note**: you can specify the date in any format that can be parsed by diff --git a/src/zona/builder.py b/src/zona/builder.py index a04b2eb..446f07d 100644 --- a/src/zona/builder.py +++ b/src/zona/builder.py @@ -48,14 +48,12 @@ class ZonaBuilder: destination=destination, url=str(destination.relative_to(layout.output)), ) - if path.name.endswith( - ".md" - ) and not path.is_relative_to( + if path.name.endswith(".md") and not path.is_relative_to( layout.root / "content" / "static" ): logger.debug(f"Parsing {path.name}.") item.metadata, item.content = parse_metadata(path) - if ( + if item.metadata.ignore or ( item.metadata.draft and not self.config.build.include_drafts ): @@ -71,13 +69,11 @@ class ZonaBuilder: item.copy = False name = destination.stem if name == "index": - item.destination = ( - item.destination.with_suffix(".html") + item.destination = item.destination.with_suffix( + ".html" ) else: - relative = path.relative_to(base).with_suffix( - "" - ) + relative = path.relative_to(base).with_suffix("") name = relative.stem item.destination = ( layout.output @@ -89,9 +85,7 @@ class ZonaBuilder: layout.output ) item.url = ( - "" - if rel_url == Path(".") - else rel_url.as_posix() + "" if rel_url == Path(".") else rel_url.as_posix() ) items.append(item) self.items = items @@ -117,9 +111,7 @@ class ZonaBuilder: # write code highlighting stylesheet if self.config.markdown.syntax_highlighting.enabled: pygments_style = zmd.get_style_defs(self.config) - pygments_path = ( - self.layout.output / "static" / "pygments.css" - ) + pygments_path = self.layout.output / "static" / "pygments.css" util.ensure_parents(pygments_path) pygments_path.write_text(pygments_style) for item in self.item_map.values(): diff --git a/src/zona/metadata.py b/src/zona/metadata.py index b079266..0cd6a8c 100644 --- a/src/zona/metadata.py +++ b/src/zona/metadata.py @@ -24,6 +24,7 @@ class Metadata: template: str | None = None post: bool | None = None draft: bool = False + ignore: bool = False math: bool = True