Skip to content

Metadata

Description

Every MkPage as well as every [MkNav][mknodes.MkNav] can carry metadata. Page metadata inherits from Nav metadata, similarly as the MkDocs-Material meta plugin.

Metadata can be set either via the MkPage constructor, via the MkNav.route.page decorator. Also, some methods like [MkNav.parse.folder][mknodes.navs.navparser.NavParser.folder] take metadata keyword arguments in order to set it for all parsed pages.

Examples

Via decorators:

@nav.route.page("My page", icon="material/code-json", status="new")
def _(page: mk.MkPage):
    ...

Via constructor:

page = MkPage("My page", icon="material/code-json", status="new")

Metadata fields

The Metadata class is a subclassed Python dictionary.

It is enhanced with properties for common metadata fields in order to get proper type hints. Since this object is a dict subclass, you can of course also add any non-documented stuff to the Metadata.

creation_date property writable

creation_date: bool | None

Page creation date.

description property writable

description: str | None

Description text for the page.

exclude_from_search: bool | None

Exclude this page from search.

hide property writable

hide: list[SectionStr] | None

A list of items which should be hidden from the page.

MkDocs-Material supports "navigation", "toc", "path", "tags".

icon property writable

icon: str | None

An icon for the page (Example: "material/wrench").

inclusion_level property writable

inclusion_level: str | None

Page inclusion level.

render_macros property writable

render_macros: bool | None

Whether this page should get rendered by the templating engine.

revision_date property writable

revision_date: bool | None

Date when page was last revised.

search property writable

search: dict | None

A dictionary containing search-related settings ("boost" / "exclude").

search_boost property writable

search_boost: float | None

A multiplier to modify search relevance.

status property writable

status: PageStatusStr | str | None

The status of the page.

MkDocs-Material supports "new", "deprecated" and "encrypted" by default by showing an icon in the site nav. Additional icons can be added during the build process via [MaterialTheme.add_status_icon][mknodes.MaterialTheme.add_status_icon].

subtitle property writable

subtitle: str | None

Subtitle for the page.

tags property writable

tags: list[str]

A list of tags associated with the page.

template property writable

template: str | None

Filename of the template the page should use.

This is only a reference, you still need to add the template to the theme.

title property writable

title: str | None

Title for the page.

as_page_header

as_page_header() -> str

Format metadata in Page header format (with --- separators).

parse classmethod

parse(text: str) -> tuple[Self, str]

Parse given text for metadata and return a (Metadata, Rest-from-text) tuple.

Page info
Code for this page
mknodes.manual.page_section._
@nav.route.page(
    "Metadata",
    status="deprecated",
    search_boost=2.0,
    subtitle="Subtitle",
    description="Description",
)
def _(page: mk.MkPage):
    page += mk.MkTemplate("pages/page_metadata.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=[Plugin('mkdocstrings')],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/mknodes/manual/page_section.py
  source_function: null
  source_line_no: 43
description: Description
search:
  boost: 2.0
status: deprecated
subtitle: Subtitle
template: SUMMARY.html
title: Metadata