MkPages
General information
MkPages are nodes which are children from MkNavs, and represent a single page from a website. Like already described, a page can either be a regular page or an “index page” for an MkNav. An index page shows when clicking on a menu item with children, or for the website root.
Page metadata
MkPages have metadata attached, which can be set via the MkPage.metadata attribute. MkPage.metadata is also inherited from the parent MkNavs in case they have metadata set. That metadata can alter the behaviour and appearance of given page. It can be used to show icons / subtitles in menus, to modify the search ranking, to set a reference to a PageTemplate, and much more.
Note
The page information box at the bottom of each page also contains the metadata content of the current page, as well as the code which created the page. If you’re interested how MkNodes works, it can help to check out these information boxes! (What you will notice: MkNodes puts some data about the page instantiation into the metadata.)
Further info
See the Metadata section, the MkDocs Documentation as well as the MkDocs-Material docs for further info.
Page templates
Each MkPage also carries a PageTemplate, which can be used for more advanced modification of a page. For example, page templates can be used to put HTML / Markdown into other areas of the page than just the main content area, like the announcement bar or the site nav section. Like metadata, the templates also inherit from MkNavs, meaning that a MkPage will use the template of a parent MkNav if it has one defined.
More information about templates can be found here.
Using MkPages
MkPages can get created in many ways:
-
By simply use the constructor and add the page to an MkNav:
The classic way
page = MkPage("My page") nav += page -
By using the nav.route.page decorator.
Via decorators
@nav.route.page("My page") def _(page): ...More information about routing can be found here.
-
By using MkNav.add_page:
Via add_page
page = nav.add_page("My page") -
By using the alternative constructor MkPage.from_file:
Via MkPage.from_file
page = MkPage.from_file("path/to/file.md") -
Or indirectly by using “batch operations” like nav.parse.folder and similar (see also: NavParser):
Via parse.folder or similar
nav = MkNav() nav.parse.folder("path/to/folder/with/markdown/files/") assert nav.nav.get_pages()
Like many other nodes, MkPages inherits from MkContainer and looks to the outside world like a list, meaning you can add nodes to them by using += or MkPage.append().
Each MkPage also has an MkFootnotes node “embedded” which can be used to easily add footnotes to a page. (Scroll to the bottom to see the result)
MkFootnotes embedded
page = MkPage("My page")
page.footnotes[1] = r"Footnotes are numbered, can be set via \__setitem__."
page.footnotes[2] = r"They can also get nested[^3]."
page.footnotes[3] = MkAdmonition("And they can also contain other Markdown (nodes).")
Build process
During the build process, all Markdown nodes which are part of an MkPage get collected and scanned for required resources like CSS / JS / static assets. If appropriate, these resources then automatically get inserted into the PageTemplate and end up in the HTML header.
The final URL of an MkPage is determined by its position inside the tree and gets calculated when the tree gets “serialized” into markdown. The HTML filename is inferred from the page title in case no specific path is given.
MkPages are not tied to a static site engine: MkNodes does not depend on MkDocs or any other engine. The site generator mkdocs-mknodes serializes the MkPages of a tree to Markdown (including the front matter), writes them into the docs folder together with the nav and the required resources, and the site engine (Zensical) builds the HTML website from there.
Template MkPages
MkNodes also contains two special subclasses of MkPage, MkModulePage and MkClassPage. They get used by the automatic API generator node named MkDoc and contain a jinja2 template used to create an API / info page for given module / class.
Page info
Code for this section
mknodes.manual.page_section._
@nav.route.page(is_index=True)
def _(page: mk.MkPage) -> None:
page += mk.MkTemplate("pages/mkpage_index.jinja")
page.footnotes[1] = r"Footnotes are numbered, can be set via \__setitem__."
page.footnotes[2] = r"They can also get nested[^3]."
page.footnotes[3] = mk.MkAdmonition("They can also contain other Markdown (nodes).")
Resources
Resources(css=[],
markdown_extensions={},
plugins=[],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/page_section.py
source_function: _
source_line_no: 7
title: MkPages
-
↩Note
They can also contain other Markdown (nodes).