add more logging
This commit is contained in:
parent
941b993287
commit
2b5eef9839
4 changed files with 34 additions and 3 deletions
|
@ -19,6 +19,7 @@ class ZonaBuilder:
|
||||||
cli_root: Path | None = None,
|
cli_root: Path | None = None,
|
||||||
cli_output: Path | None = None,
|
cli_output: Path | None = None,
|
||||||
):
|
):
|
||||||
|
logger.debug("Initializing ZonaBuilder.")
|
||||||
self.layout: Layout = discover_layout(cli_root, cli_output)
|
self.layout: Layout = discover_layout(cli_root, cli_output)
|
||||||
self.config: ZonaConfig = ZonaConfig.from_file(
|
self.config: ZonaConfig = ZonaConfig.from_file(
|
||||||
self.layout.root / "config.yml"
|
self.layout.root / "config.yml"
|
||||||
|
@ -31,6 +32,7 @@ class ZonaBuilder:
|
||||||
items: list[Item] = []
|
items: list[Item] = []
|
||||||
|
|
||||||
base = layout.root / layout.content
|
base = layout.root / layout.content
|
||||||
|
logger.debug(f"Discovering content in {base}.")
|
||||||
for path in base.rglob("*"):
|
for path in base.rglob("*"):
|
||||||
if path.is_file() and not util.should_ignore(
|
if path.is_file() and not util.should_ignore(
|
||||||
path, patterns=self.config.ignore, base=base
|
path, patterns=self.config.ignore, base=base
|
||||||
|
@ -45,6 +47,9 @@ class ZonaBuilder:
|
||||||
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"
|
layout.root / "content" / "static"
|
||||||
):
|
):
|
||||||
|
logger.debug(
|
||||||
|
f"Parsing {path.name} as Markdown document."
|
||||||
|
)
|
||||||
item.metadata, item.content = parse_metadata(path)
|
item.metadata, item.content = parse_metadata(path)
|
||||||
if item.metadata.post == True:
|
if item.metadata.post == True:
|
||||||
item.post = True
|
item.post = True
|
||||||
|
|
|
@ -4,9 +4,10 @@ from pathlib import Path
|
||||||
from zona import server
|
from zona import server
|
||||||
from zona.builder import ZonaBuilder
|
from zona.builder import ZonaBuilder
|
||||||
from zona.layout import initialize_site
|
from zona.layout import initialize_site
|
||||||
from zona.log import setup_logging
|
from zona.log import setup_logging, get_logger
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
logger = get_logger()
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
|
@ -26,6 +27,7 @@ def init(
|
||||||
|
|
||||||
Optionally specify the ROOT directory.
|
Optionally specify the ROOT directory.
|
||||||
"""
|
"""
|
||||||
|
logger.info("Initializing site...")
|
||||||
initialize_site(root)
|
initialize_site(root)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,21 @@ from dataclasses import dataclass, field
|
||||||
from dacite import from_dict
|
from dacite import from_dict
|
||||||
import yaml
|
import yaml
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from zona.log import get_logger
|
||||||
|
|
||||||
|
logger = get_logger()
|
||||||
|
|
||||||
|
|
||||||
def find_config(start: Path | None = None) -> Path | None:
|
def find_config(start: Path | None = None) -> Path | None:
|
||||||
|
logger.debug("Searching for config file...")
|
||||||
current = (start or Path.cwd()).resolve()
|
current = (start or Path.cwd()).resolve()
|
||||||
|
|
||||||
for parent in [current, *current.parents]:
|
for parent in [current, *current.parents]:
|
||||||
candidate = parent / "config.yml"
|
candidate = parent / "config.yml"
|
||||||
if candidate.is_file():
|
if candidate.is_file():
|
||||||
|
logger.debug(f"Config file {candidate} found.")
|
||||||
return candidate
|
return candidate
|
||||||
|
logger.debug("Couldn't find config file.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from rich import print
|
|
||||||
import typer
|
import typer
|
||||||
from dataclasses import dataclass, asdict
|
from dataclasses import dataclass, asdict
|
||||||
from zona.config import ZonaConfig, find_config
|
from zona.config import ZonaConfig, find_config
|
||||||
from zona import util
|
from zona import util, log
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
logger = log.get_logger()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Layout:
|
class Layout:
|
||||||
|
@ -25,11 +26,14 @@ class Layout:
|
||||||
output=(root / "public").resolve() if not output else output,
|
output=(root / "public").resolve() if not output else output,
|
||||||
)
|
)
|
||||||
if validate:
|
if validate:
|
||||||
|
logger.debug("Validating site layout...")
|
||||||
if not layout.content.is_dir():
|
if not layout.content.is_dir():
|
||||||
|
logger.error("Missing required content directory!")
|
||||||
raise FileNotFoundError(
|
raise FileNotFoundError(
|
||||||
"Missing required content directory!"
|
"Missing required content directory!"
|
||||||
)
|
)
|
||||||
if not layout.templates.is_dir():
|
if not layout.templates.is_dir():
|
||||||
|
logger.debug("Using default template directory.")
|
||||||
# use the included defaults
|
# use the included defaults
|
||||||
layout.templates = util.get_resource_dir("templates")
|
layout.templates = util.get_resource_dir("templates")
|
||||||
|
|
||||||
|
@ -40,19 +44,24 @@ def discover_layout(
|
||||||
cli_root: Path | None = None, cli_output: Path | None = None
|
cli_root: Path | None = None, cli_output: Path | None = None
|
||||||
) -> Layout:
|
) -> Layout:
|
||||||
if cli_root:
|
if cli_root:
|
||||||
|
logger.debug("Using user provided site root.")
|
||||||
root = cli_root
|
root = cli_root
|
||||||
else:
|
else:
|
||||||
|
logger.debug("Discovering site layout...")
|
||||||
config = find_config(cli_root)
|
config = find_config(cli_root)
|
||||||
if config:
|
if config:
|
||||||
root = config.parent
|
root = config.parent
|
||||||
else:
|
else:
|
||||||
|
logger.debug("Using CWD as root.")
|
||||||
root = Path.cwd()
|
root = Path.cwd()
|
||||||
return Layout.from_input(root, cli_output)
|
return Layout.from_input(root, cli_output)
|
||||||
|
|
||||||
|
|
||||||
def initialize_site(root: Path | None = None):
|
def initialize_site(root: Path | None = None):
|
||||||
|
logger.info("Initializing site.")
|
||||||
# initialize a new project
|
# initialize a new project
|
||||||
if not root:
|
if not root:
|
||||||
|
logger.debug("No root provided; using CWD.")
|
||||||
root = Path.cwd()
|
root = Path.cwd()
|
||||||
root = root.absolute().resolve()
|
root = root.absolute().resolve()
|
||||||
config = find_config(root)
|
config = find_config(root)
|
||||||
|
@ -64,11 +73,15 @@ def initialize_site(root: Path | None = None):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if ans:
|
if ans:
|
||||||
|
logger.debug("Unlinking config file.")
|
||||||
config.unlink()
|
config.unlink()
|
||||||
# create requires layout
|
# create requires layout
|
||||||
|
logger.debug("Generating layout.")
|
||||||
layout = Layout.from_input(root=root, validate=False)
|
layout = Layout.from_input(root=root, validate=False)
|
||||||
# load template resources
|
# load template resources
|
||||||
|
logger.debug("Loading internal templates.")
|
||||||
templates = util.get_resources("templates")
|
templates = util.get_resources("templates")
|
||||||
|
logger.debug("Loading internal static content.")
|
||||||
static = util.get_resources("content")
|
static = util.get_resources("content")
|
||||||
for dir, resources in [
|
for dir, resources in [
|
||||||
(layout.root, None),
|
(layout.root, None),
|
||||||
|
@ -76,13 +89,18 @@ def initialize_site(root: Path | None = None):
|
||||||
(layout.templates, templates),
|
(layout.templates, templates),
|
||||||
]:
|
]:
|
||||||
if not dir.is_dir():
|
if not dir.is_dir():
|
||||||
|
logger.debug(f"Creating {dir}.")
|
||||||
dir.mkdir()
|
dir.mkdir()
|
||||||
if resources is not None:
|
if resources is not None:
|
||||||
|
logger.debug("Writing resources.")
|
||||||
for r in resources:
|
for r in resources:
|
||||||
|
logger.debug(f"Writing {(root / Path(r.name))}.")
|
||||||
(root / Path(r.name)).write_text(r.contents)
|
(root / Path(r.name)).write_text(r.contents)
|
||||||
|
|
||||||
config_path = layout.root / "config.yml"
|
config_path = layout.root / "config.yml"
|
||||||
|
logger.debug("Loading default configuation.")
|
||||||
config = ZonaConfig()
|
config = ZonaConfig()
|
||||||
|
logger.debug(f"Writing default configuration to {config_path}.")
|
||||||
with open(config_path, "w") as f:
|
with open(config_path, "w") as f:
|
||||||
yaml.dump(
|
yaml.dump(
|
||||||
asdict(config),
|
asdict(config),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue