add post detection

This commit is contained in:
Daniel Fichtinger 2025-06-27 23:11:42 -04:00
parent 75c2bc2755
commit 437aff51e7
4 changed files with 18 additions and 0 deletions

View file

@ -6,6 +6,7 @@ from zona.layout import Layout, discover_layout
from zona.config import ZonaConfig
from zona import util
from pathlib import Path
from rich import print
class ZonaBuilder:
@ -39,6 +40,13 @@ class ZonaBuilder:
layout.root / "content" / "static"
):
item.metadata, item.content = parse_metadata(path)
if item.metadata.post == True:
item.post = True
elif item.metadata.post is None:
# check if in posts dir?
blog_dir = base / Path(self.config.blog.dir)
if item.source.is_relative_to(blog_dir):
item.post = True
item.type = ItemType.MARKDOWN
item.copy = False
name = destination.stem
@ -58,6 +66,7 @@ class ZonaBuilder:
"" if rel_url == Path(".") else rel_url.as_posix()
)
items.append(item)
# print(item)
self.items = items
def _build(self):

View file

@ -14,6 +14,11 @@ def find_config(start: Path | None = None) -> Path | None:
return None
@dataclass
class BlogConfig:
dir: str = "blog"
@dataclass
class MarkdownConfig:
image_labels: bool = True
@ -44,6 +49,7 @@ class ZonaConfig:
markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
theme: ThemeConfig = field(default_factory=ThemeConfig)
build: BuildConfig = field(default_factory=BuildConfig)
blog: BlogConfig = field(default_factory=BlogConfig)
@classmethod
def from_file(cls, path: Path) -> "ZonaConfig":

View file

@ -1,4 +1,5 @@
from dataclasses import dataclass
from rich import print
from pathlib import Path
from datetime import date
@ -19,6 +20,7 @@ class Metadata:
header: bool = True
footer: bool = True
template: str = "page.html"
post: bool | None = None
def parse_metadata(path: Path) -> tuple[Metadata, str]:

View file

@ -20,6 +20,7 @@ class Item:
content: str | None = None
type: ItemType | None = None
copy: bool = True
post: bool = False
# @dataclass