Skip to content

templatecontext

Class info

Classes

Name Children Inherits
MkNodesConfig
mkdocs_mknodes.plugin.mknodesconfig
    TemplateContext
    mkdocs_mknodes.commands.templatecontext

      🛈 DocStrings

      TemplateContext

      Bases: TypedDict

      Parameters:

      Name Type Description Default
      nav ForwardRef('Navigation', module='mkdocs_mknodes.commands.templatecontext')
      required
      pages ForwardRef('Sequence[File]', module='mkdocs_mknodes.commands.templatecontext')
      required
      base_url ForwardRef('str', module='mkdocs_mknodes.commands.templatecontext')
      required
      extra_css ForwardRef('Sequence[str]', module='mkdocs_mknodes.commands.templatecontext')
      required
      extra_javascript ForwardRef('Sequence[str]', module='mkdocs_mknodes.commands.templatecontext')
      required
      mkdocs_version ForwardRef('str', module='mkdocs_mknodes.commands.templatecontext')
      required
      mknodes_version ForwardRef('str', module='mkdocs_mknodes.commands.templatecontext')
      required
      build_date_utc ForwardRef('datetime', module='mkdocs_mknodes.commands.templatecontext')
      required
      config ForwardRef('MkNodesConfig', module='mkdocs_mknodes.commands.templatecontext')
      required
      page ForwardRef('Page | None', module='mkdocs_mknodes.commands.templatecontext')
      required
      Source code in mkdocs_mknodes/commands/templatecontext.py
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      class TemplateContext(TypedDict):
          nav: Navigation
          pages: Sequence[File]
          base_url: str
          extra_css: Sequence[str]  # Do not use, prefer `config.extra_css`.
          extra_javascript: Sequence[str]  # Do not use, prefer `config.extra_javascript`.
          mkdocs_version: str
          mknodes_version: str
          build_date_utc: datetime
          config: MkNodesConfig
          page: Page | None
      

      get_context

      get_context(
          nav: Navigation,
          files: Sequence[File] | Files,
          config: MkNodesConfig,
          page: Page | None = None,
          base_url: str = "",
      ) -> TemplateContext
      

      Return the template context for a given page or template.

      Source code in mkdocs_mknodes/commands/templatecontext.py
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      def get_context(
          nav: Navigation,
          files: Sequence[File] | Files,
          config: MkNodesConfig,
          page: Page | None = None,
          base_url: str = "",
      ) -> TemplateContext:
          """Return the template context for a given page or template."""
          if page is not None:
              base_url = htmlfilters.relative_url_mkdocs(".", page.url)
      
          extra_javascript = [
              htmlfilters.normalize_url(str(script), page.url if page else None, base_url)
              for script in config.extra_javascript
          ]
          extra_css = [
              htmlfilters.normalize_url(path, page.url if page else None, base_url)
              for path in config.extra_css
          ]
      
          if isinstance(files, Files):
              files = files.documentation_pages()
      
          import mkdocs
      
          import mkdocs_mknodes
      
          return TemplateContext(
              nav=nav,
              pages=files,
              base_url=base_url,
              extra_css=extra_css,
              extra_javascript=extra_javascript,
              mknodes_version=mkdocs_mknodes.__version__,
              mkdocs_version=mkdocs.__version__,
              build_date_utc=utils.get_build_datetime(),
              config=config,
              page=page,
          )