add post detection
This commit is contained in:
parent
75c2bc2755
commit
437aff51e7
4 changed files with 18 additions and 0 deletions
|
@ -6,6 +6,7 @@ from zona.layout import Layout, discover_layout
|
||||||
from zona.config import ZonaConfig
|
from zona.config import ZonaConfig
|
||||||
from zona import util
|
from zona import util
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from rich import print
|
||||||
|
|
||||||
|
|
||||||
class ZonaBuilder:
|
class ZonaBuilder:
|
||||||
|
@ -39,6 +40,13 @@ class ZonaBuilder:
|
||||||
layout.root / "content" / "static"
|
layout.root / "content" / "static"
|
||||||
):
|
):
|
||||||
item.metadata, item.content = parse_metadata(path)
|
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.type = ItemType.MARKDOWN
|
||||||
item.copy = False
|
item.copy = False
|
||||||
name = destination.stem
|
name = destination.stem
|
||||||
|
@ -58,6 +66,7 @@ class ZonaBuilder:
|
||||||
"" if rel_url == Path(".") else rel_url.as_posix()
|
"" if rel_url == Path(".") else rel_url.as_posix()
|
||||||
)
|
)
|
||||||
items.append(item)
|
items.append(item)
|
||||||
|
# print(item)
|
||||||
self.items = items
|
self.items = items
|
||||||
|
|
||||||
def _build(self):
|
def _build(self):
|
||||||
|
|
|
@ -14,6 +14,11 @@ def find_config(start: Path | None = None) -> Path | None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BlogConfig:
|
||||||
|
dir: str = "blog"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MarkdownConfig:
|
class MarkdownConfig:
|
||||||
image_labels: bool = True
|
image_labels: bool = True
|
||||||
|
@ -44,6 +49,7 @@ class ZonaConfig:
|
||||||
markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
|
markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
|
||||||
theme: ThemeConfig = field(default_factory=ThemeConfig)
|
theme: ThemeConfig = field(default_factory=ThemeConfig)
|
||||||
build: BuildConfig = field(default_factory=BuildConfig)
|
build: BuildConfig = field(default_factory=BuildConfig)
|
||||||
|
blog: BlogConfig = field(default_factory=BlogConfig)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls, path: Path) -> "ZonaConfig":
|
def from_file(cls, path: Path) -> "ZonaConfig":
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from rich import print
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ class Metadata:
|
||||||
header: bool = True
|
header: bool = True
|
||||||
footer: bool = True
|
footer: bool = True
|
||||||
template: str = "page.html"
|
template: str = "page.html"
|
||||||
|
post: bool | None = None
|
||||||
|
|
||||||
|
|
||||||
def parse_metadata(path: Path) -> tuple[Metadata, str]:
|
def parse_metadata(path: Path) -> tuple[Metadata, str]:
|
||||||
|
|
|
@ -20,6 +20,7 @@ class Item:
|
||||||
content: str | None = None
|
content: str | None = None
|
||||||
type: ItemType | None = None
|
type: ItemType | None = None
|
||||||
copy: bool = True
|
copy: bool = True
|
||||||
|
post: bool = False
|
||||||
|
|
||||||
|
|
||||||
# @dataclass
|
# @dataclass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue