Resources

All MkNodes can have "resources", which describe what is needed for the node to work.

This can include:

  • CSS / JavaScript (either remote links or included in MkNodes)
  • Markdown extensions including their specific config, if required
  • Required python packages
  • Plugins
  • Additional asset files (images, ...)

If a template for a MkPage was set, then the PageTemplate also is included as a resource for the MkPage itself.

These resources are collected during the build phase and put into the appropriate places. These places can be:

  • Config file
  • Build folder
  • The HTML file the node is included in, by creating / modifying the page template.

Using this mechanism is optional, it is still possible to include the resources directly. Inferred resources and directly included resources will get merged then.

Info

This mechanism only works when MkNodes "knows" about the nodes you used. That is the case when adding MkNodes directly to the tree as Python object, or by applying them as jinja2 filters / macros using the MkTemplate node. In both cases, the resources get collected. What won't work: Adding markdown in text form as an MkText node which needs resources, or when using MkPage.from_file for example. MkNodes is not a parser, so it cant know which extensions etc. your Markdown needs in order to get rendered correctly. In that case you have to add the required extensions etc manually to the MkDocs config, like you did before.

As examples, you can check the "Page information" box on all websites of this documentation. It will show the required resources for given page.

Page info
Code for this page
mknodes.manual.page_section._
@nav.route.page("Resources")
def _(page: mk.MkPage):
    page += mk.MkTemplate("resources.jinja")
Resources
Resources(css=[],
          markdown_extensions={'attr_list': {},
                               'md_in_html': {},
                               'pymdownx.emoji': {'emoji_generator': <function to_svg at 0x7fd7a6931800>,
                                                  'emoji_index': <function twemoji at 0x7fd7a69316c0>},
                               'pymdownx.magiclink': {'repo': 'mknodes',
                                                      'repo_url_shorthand': True,
                                                      'user': 'phil65'}},
          plugins=[],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/mknodes/manual/page_section.py
  source_function: null
  source_line_no: 72
template: SUMMARY.html
title: Resources