diff --git a/src/mkdocs/mkdocs.py b/src/mkdocs/mkdocs.py index 86e13b3..5608d63 100644 --- a/src/mkdocs/mkdocs.py +++ b/src/mkdocs/mkdocs.py @@ -71,10 +71,16 @@ def __init__(self, path): self.url = str(url).removesuffix('index.html') +class Template: + def __init__(self, path): + self.path = path + + class Site: - def __init__(self, pages, statics): + def __init__(self, pages, statics, templates): self._pages = pages self._statics = statics + self._templates = templates self._paths = { str(resource.path): resource for resource in pages + statics @@ -82,6 +88,9 @@ def __init__(self, pages, statics): self._urls = { str(resource.url): resource for resource in pages + statics } + self._templates = { + str(template.path): template for template in templates + } def lookup_by_path(self, path) -> Page | Static | None: return self._paths.get(path) @@ -97,6 +106,10 @@ def pages(self) -> list[Page]: def statics(self) -> list[Static]: return list(self._statics) + @property + def templates(self) -> list[Template]: + return list(self._templates) + def __len__(self) -> int: return len(self.pages) + len(self.statics) @@ -164,10 +177,12 @@ def load_site(self, input_dir): pages = [] statics = [] + templates = [] for path in paths: if path.parts[0] == "templates": - pass + template = Template(path) + templates.append(template) elif path.suffix == ".md": page = Page(path) pages.append(page) @@ -177,7 +192,8 @@ def load_site(self, input_dir): pages = sorted(pages, key=lambda x: x.url) statics = sorted(statics, key=lambda x: x.url) - return Site(pages, statics) + templates = sorted(templates, key=lambda x: x.path) + return Site(pages, statics, templates) def load_nav(self, config, site): if not config: @@ -263,6 +279,8 @@ def build(self, input, output): html = self.md.reset().convert(text) toc = TableOfContents(self.md) page_ctx = PageContext(page=page, text=text, html=html, toc=toc) + # Really I think we want this to be `render(page=..., site=...)` + # That's then neaty enough constrained as a context for users to work against.` output = self.base.render(page=page_ctx, nav=self.nav) output_path.parent.mkdir(parents=True, exist_ok=True)