Skip to content

Metadata

Description

Every MkPage as well as every 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 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[str, Any] | 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().

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.