Skip to content

mkdocs_nype.extensions.material

Synopsis

mkdocs-material extension module

Works through being invoked from the mkdocs-nype __init__.py file before the mkdocs-material plugins get to load etc.

In some cases, mkdocs-material plugins lack configurability and typically this issue is solved by adding another plugin with its own configuration that later overrides stuff during the MkDocs event loop.

However, some of those cases don't make much sense as a separate plugin with its own event loop, so this module aims to add those micro adjustments.

  1. Extend the BlogConfig class to be able to configure more options.
  2. Monkey-patch some events to add logic before or after their execution to use the new options.

MIT License 2024 Kamil Krzyśków (HRY) for Nype (npe.cm)

INDEX_VARIANTS

INDEX_VARIANTS = ('index', 'index-grouped', 'index-grouped-combo-a', 'index-grouped-combo-b')

All of the index-only display variants

INDEX_CARDS_WITH_CARD_CATEGORIES

INDEX_CARDS_WITH_CARD_CATEGORIES = tuple([f'{var}+all' for var in INDEX_VARIANTS])

All of the index display variants + normal cards all

BlogConfig

Bases: BlogConfig

Default values of the new options should match standard mkdocs-material behaviour

hide_read_more

hide_read_more = Type(bool, default=False)

Used later in templates to decide if the blog Views should show the read more link for Excerpts

hide_post_metadata

hide_post_metadata = Type(bool, default=False)

Used later in templates to decide if the blog Views should show the metadata of the post, like the date and categories

blog_cards

blog_cards = Choice(('off', *INDEX_VARIANTS, 'all', *INDEX_CARDS_WITH_CARD_CATEGORIES), default='off')

Toggle the blog_cards to show on all Views or only the index page

blog_card_continues

blog_card_continues = DictOfItems(Type(str), default={})

Mapping of category names to Continue Reading messages used in templates for the blog post cards. _default key is reserved for the Default value.

blog_card_icons

blog_card_icons = DictOfItems(Type(str), default={})

Mapping of category names to icon paths used in templates for the blog post cards. _default key is reserved for the Default value.

extend_blog

extend_blog()

This function must be executed before the BlogPlugin class is created and loaded into "MkDocs memory" via some other "import" during Plugin load

wrap_blog_on_config

wrap_blog_on_config(func)

wrap_blog_on_files

wrap_blog_on_files(func)

wrap_blog_on_page_markdown

wrap_blog_on_page_markdown(func)

wrap_blog_on_page_context

wrap_blog_on_page_context(func)