Compare commits
1
Commits
7bf04ff064
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1ecd0f480 |
No files matched your search
@@ -149,7 +149,6 @@ def init(args: argparse.Namespace) -> None:
|
||||
"items_per_page": int(items_per_page),
|
||||
}
|
||||
)
|
||||
Site.resolve_template_path(config.template)
|
||||
|
||||
config.to_file(config_path)
|
||||
(args.site / "content").mkdir(exist_ok=True)
|
||||
|
||||
+9
-5
@@ -27,6 +27,7 @@ from pathlib import Path
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
builtin_templates = Path(__file__).parent / "templates"
|
||||
|
||||
|
||||
class Site:
|
||||
@@ -43,15 +44,18 @@ class Site:
|
||||
self.tags_by_count: list[tuple[str, int]] = []
|
||||
|
||||
self.config = SiteConfig.from_file(site / "config.yml")
|
||||
self.template_path: Path = Site.resolve_template_path(self.config.template)
|
||||
self.template_path: Path = self.resolve_template_path(self.config.template)
|
||||
self.output_path: Path = self.site_path / "output"
|
||||
self.jinja_env = Environment(loader=FileSystemLoader(self.template_path))
|
||||
|
||||
@staticmethod
|
||||
def resolve_template_path(template: str) -> Path:
|
||||
path = Path(__file__).parent / "templates" / template
|
||||
def resolve_template_path(self, template: str) -> Path:
|
||||
path = self.site_path / "templates" / template
|
||||
if path.is_dir():
|
||||
return path
|
||||
|
||||
path = builtin_templates / template
|
||||
if not path.is_dir():
|
||||
raise ConfigError(f"template '{template}' not found at {path}")
|
||||
raise ConfigError(f"template '{template}' not found.")
|
||||
return path
|
||||
|
||||
def add_by_section(self, content: Content) -> None:
|
||||
|
||||
+22
-2
@@ -78,9 +78,29 @@ def test_clean_removes_output_directory(make_site):
|
||||
assert not site.output_path.exists()
|
||||
|
||||
|
||||
def test_resolve_template_path_raises_for_missing_template():
|
||||
def test_resolve_template_path_raises_for_missing_template(site_dir):
|
||||
path = site_dir("thin_site")
|
||||
(path / "config.yml").write_text("name: test\ntemplate: does-not-exist\n")
|
||||
|
||||
with pytest.raises(ConfigError, match="not found"):
|
||||
Site.resolve_template_path("does-not-exist")
|
||||
Site(path)
|
||||
|
||||
|
||||
def test_resolve_template_path_prefers_local_override(site_dir):
|
||||
path = site_dir("thin_site")
|
||||
(path / "config.yml").write_text("name: test\ntemplate: plain\n")
|
||||
local = path / "templates" / "plain"
|
||||
local.mkdir(parents=True)
|
||||
|
||||
assert Site(path).template_path == local
|
||||
|
||||
|
||||
def test_resolve_template_path_falls_back_to_builtin(site_dir):
|
||||
path = site_dir("thin_site")
|
||||
(path / "config.yml").write_text("name: test\ntemplate: plain\n")
|
||||
|
||||
assert Site(path).template_path.name == "plain"
|
||||
assert not Site(path).template_path.is_relative_to(path)
|
||||
|
||||
|
||||
def test_home_url(site_dir):
|
||||
|
||||
Reference in new issue
Block a user