Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Sep 17, 2023
1 parent 16e7387 commit a89e3e8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
8 changes: 0 additions & 8 deletions mknodes/navs/mknav.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,6 @@ def add_doc(
self.nav.register(nav)
return nav

@property
def page_mapping(self):
return {
node.resolved_file_path: node
for _level, node in self.iter_nodes()
if hasattr(node, "resolved_file_path")
}


if __name__ == "__main__":
docs = MkNav()
Expand Down
8 changes: 0 additions & 8 deletions mknodes/navs/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ def links(self) -> list[mklink.MkLink]:
"""Return all registered links."""
return [node for node in self.values() if isinstance(node, mklink.MkLink)]

@property
def page_mapping(self):
return {
node.resolved_file_path: node
for _level, node in self.iter_nodes()
if hasattr(node, "resolved_file_path")
}

def to_literate_nav(self):
nav = navbuilder.NavBuilder()
# In a nav, the first inserted item becomes the index page in case
Expand Down
7 changes: 3 additions & 4 deletions mknodes/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def on_config(self, config: MkDocsConfig):
build_kwargs=self.config.kwargs,
clone_depth=self.config.clone_depth,
)
self.build_info = self.project.build()

def on_files(self, files: Files, config: MkDocsConfig) -> Files:
"""Create the node tree and write files to build folder.
Expand Down Expand Up @@ -153,8 +154,7 @@ def on_pre_page(
files: Files,
) -> Page | None:
"""During this phase we set the edit paths."""
mapping = mknode.MkNode._env.globals["page_mapping"]
node = mapping.get(page.file.src_uri) # type: ignore[attr-defined]
node = self.build_info.page_mapping.get(page.file.src_uri)
edit_path = node._edit_path if isinstance(node, mkpage.MkPage) else None
cfg = mkdocsconfig.Config(config)
if path := cfg.get_edit_url(edit_path):
Expand All @@ -169,8 +169,7 @@ def on_page_markdown(
files: Files,
) -> str | None:
"""During this phase links get replaced and `jinja2` stuff get rendered."""
mapping = mknode.MkNode._env.globals["page_mapping"]
node = mapping.get(page.file.src_uri) # type: ignore[attr-defined]
node = self.build_info.page_mapping.get(page.file.src_uri)
if node is None:
return markdown
markdown = node.env.render_string(markdown)
Expand Down
7 changes: 5 additions & 2 deletions mknodes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def __init__(
self._root: mknav.MkNav | None = None
self.build_fn = classhelpers.to_callable(build_fn)
self.build_kwargs = build_kwargs or {}
self.build()

def build(self):
logger.debug("Building page...")
Expand All @@ -79,7 +78,11 @@ def build(self):

from mknodes.basenodes import mknode

mapping = self._root.page_mapping
mapping = {
node.resolved_file_path: node
for _level, node in self._root.iter_nodes()
if hasattr(node, "resolved_file_path")
}

paths = [pathlib.Path(i).stem for i in mapping]
self.linkprovider.set_excludes(paths)
Expand Down

0 comments on commit a89e3e8

Please sign in to comment.