diff --git a/mknodes/project.py b/mknodes/project.py index c6b1befc..5e29c860 100644 --- a/mknodes/project.py +++ b/mknodes/project.py @@ -125,6 +125,7 @@ def build(self, show_code_admonition: bool = False): extra_files |= node.files match node: case mk.MkPage() as page: + path = page.resolved_file_path if show_code_admonition and page.created_by: code = mk.MkCode.for_object(page.created_by) typ = "section" if page.is_index() else "page" @@ -136,16 +137,39 @@ def build(self, show_code_admonition: bool = False): ) page.append(details) if page.inclusion_level: - path = page.resolved_file_path if page.template: - html_path = pathlib.Path(path).with_suffix(".html").as_posix() + node_path = pathlib.Path(path) + elif any(i.page_template for i in page.parent_navs): + nav = next(i for i in page.parent_navs if i.page_template) + node_path = pathlib.Path(nav.resolved_file_path) + else: + node_path = None + if node_path: + html_path = node_path.with_suffix(".html").as_posix() page._metadata.template = html_path page.template.filename = html_path - md = page.to_markdown() - node_files[path] = md + for nav in page.parent_navs: + if nav.page_template: + p = pathlib.Path(nav.resolved_file_path) + parent_path = p.with_suffix(".html").as_posix() + page.template.extends = parent_path + break + md = page.to_markdown() + node_files[path] = md case mknav.MkNav(): logger.info("Processing section %r...", node.section) - path, md = node.resolved_file_path, node.to_markdown() + path = node.resolved_file_path + if node.page_template: + html_path = pathlib.Path(path).with_suffix(".html").as_posix() + for nav in node.parent_navs: + if nav.page_template: + p = pathlib.Path(nav.resolved_file_path) + parent_path = p.with_suffix(".html").as_posix() + node.page_template.extends = parent_path + break + node.metadata.template = html_path + node.page_template.filename = html_path + md = node.to_markdown() node_files[path] = md ctx.build_files = node_files | extra_files diff --git a/pyproject.toml b/pyproject.toml index 705d3628..2e1987f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -261,7 +261,9 @@ ignore = [ "D408", # Section underline should be in the line following the section's name ("{name}") "D409", # Section underline should match the length of its name ("{name}") "D413", # Missing blank line after last section ("{name}") + "PLR0912",# Too many branches "PLR0913",# Too many arguments to function call + "PLR0915",# Too many statements "SLF001",# Private member accessed "RUF012", # Mutable class attributes should be annotated "RUF013", # PEP 484 prohibits implicit `Optional`