diff --git a/mkdocs.yml b/mkdocs.yml index e674b1b4..58450e10 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -58,7 +58,7 @@ plugins: - literate-nav - mknodes: build_fn: mknodes.manual.root:build - show_code_admonition: true + show_page_info: true # build_fn: mknodes.navs.mkdefaultwebsite:MkDefaultWebsite.for_project # repo_path: https://github.com/pallets/jinja2.git - mkdocstrings: diff --git a/mknodes/basenodes/mkadmonition.py b/mknodes/basenodes/mkadmonition.py index b8f04f11..817a1a4d 100644 --- a/mknodes/basenodes/mkadmonition.py +++ b/mknodes/basenodes/mkadmonition.py @@ -26,7 +26,7 @@ def __init__( self, content: str | list | mknode.MkNode, *, - typ: datatypes.AdmonitionTypeStr = "info", + typ: datatypes.AdmonitionTypeStr | str = "info", title: str | None = None, collapsible: bool = False, expanded: bool = False, diff --git a/mknodes/buildcollector.py b/mknodes/buildcollector.py index 3d397ad2..23d9a7c1 100644 --- a/mknodes/buildcollector.py +++ b/mknodes/buildcollector.py @@ -13,15 +13,15 @@ class BuildCollector: """MkNodes Project.""" - def __init__(self, nodes: list[mk.MkNode], show_code_admonition: bool = False): + def __init__(self, nodes: list[mk.MkNode], show_page_info: bool = False): """The main project to create a website. Arguments: nodes: The theme to use - show_code_admonition: Add a code admonition box to each page. + show_page_info: Add a code admonition box to each page. """ self.nodes = nodes - self.show_code_admonition = show_code_admonition + self.show_page_info = show_page_info self.node_files: dict[str, str | bytes] = {} self.extra_files: dict[str, str | bytes] = {} for node in self.nodes: @@ -34,16 +34,7 @@ def __init__(self, nodes: list[mk.MkNode], show_code_admonition: bool = False): def collect_page(self, page: mk.MkPage): path = page.resolved_file_path - if self.show_code_admonition and page.created_by: - code = mk.MkCode.for_object(page.created_by) - typ = "section" if page.is_index() else "page" - details = mk.MkAdmonition( - code, - title=f"Code for this {typ}", - collapsible=True, - typ="quote", - ) - page.append(details) + req = page.get_requirements() if page.inclusion_level: if page.template: node_path = pathlib.Path(path) @@ -62,6 +53,30 @@ def collect_page(self, page: mk.MkPage): parent_path = p.with_suffix(".html").as_posix() page.template.extends = parent_path break + if self.show_page_info: + adm = mk.MkAdmonition([], title="Page info", typ="theme", collapsible=True) + + if page.created_by: + typ = "section" if page.is_index() else "page" + details = mk.MkAdmonition( + mk.MkCode.for_object(page.created_by), + title=f"Code for this {typ}", + collapsible=True, + typ="quote", + ) + adm += details + + title = "Requirements" + pretty = mk.MkPrettyPrint(req) + details = mk.MkAdmonition(pretty, title=title, collapsible=True, typ="quote") + adm += details + + title = "Metadata" + code = mk.MkCode(str(page.metadata), language="yaml") + details = mk.MkAdmonition(code, title=title, collapsible=True, typ="quote") + adm += details + + page += adm md = page.to_markdown() self.node_files[path] = md diff --git a/mknodes/plugin/__init__.py b/mknodes/plugin/__init__.py index 01f56dfa..bee79d20 100644 --- a/mknodes/plugin/__init__.py +++ b/mknodes/plugin/__init__.py @@ -65,7 +65,7 @@ def on_config(self, config: MkDocsConfig): clone_depth=self.config.clone_depth, ) logger.info("Generating pages...") - self.build_info = self.project.build(self.config.show_code_admonition) + self.build_info = self.project.build(self.config.show_page_info) # now we add our stuff to the MkDocs build environment cfg = mkdocsconfig.Config(config) diff --git a/mknodes/plugin/pluginconfig.py b/mknodes/plugin/pluginconfig.py index 2d622d4c..c3f9ae91 100644 --- a/mknodes/plugin/pluginconfig.py +++ b/mknodes/plugin/pluginconfig.py @@ -32,11 +32,14 @@ class PluginConfig(base.Config): """Folder to create the Markdown files in. If no folder is set, **MkNodes** will generate a temporary dir.""" - show_code_admonition = c.Type(bool, default=False) - """Append an admonition box with the generator code to each page. + show_page_info = c.Type(bool, default=False) + """Append an admonition box with build-related information. If True, all pages get added an expandable admonition box at the bottom, - containing the code which generated the page. - In order for this to work, the page needs to be created via decorators, or - the `generated_by` attribute of the MkPage needs to be set manually. + containing information about the created page. + This includes: + - Metadata + - Requirements + - Code which created the page (needs the page to be created via decorators, or + the `generated_by` attribute of the MkPage needs to be set manually) """ diff --git a/mknodes/project.py b/mknodes/project.py index d599bbdc..da69f37d 100644 --- a/mknodes/project.py +++ b/mknodes/project.py @@ -88,7 +88,7 @@ def __init__( self.build_fn = classhelpers.to_callable(build_fn) self.build_kwargs = build_kwargs or {} - def build(self, show_code_admonition: bool = False): + def build(self, show_page_info: bool = False): logger.debug("Building page...") self.build_fn(project=self, **self.build_kwargs) logger.debug("Finished building page.") @@ -118,7 +118,7 @@ def build(self, show_code_admonition: bool = False): if root := self._root: iterator = itertools.chain(iterator, root.iter_nodes()) nodes = [i[1] for i in iterator] - collector = BuildCollector(nodes, show_code_admonition) + collector = BuildCollector(nodes, show_page_info) ctx.build_files = collector.node_files | collector.extra_files jinjahelpers.set_markdown_exec_namespace(self.env.globals) return ctx