Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/mkdocs/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,26 @@ 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
}
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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
Loading