Skip to content

mkdocs_nype.plugins.custom_blog_categorization.plugin

Synopsis

MkDocs plugin made to add a custom categorization to the material/blog plugin.

This plugin was formerly a hook:

By default the blog plugin only allows to use Archive and Category views. This plugin adds another for a Custom view.

A lot of the code is based from the plugin as those instructions aren't in importable functions.

Note

  • This only generates the "back-end" Python data structures, the user has to add overrides for blog*.html templates. Use page.code_name or view.code_name to access the list of attached pages. (where code_name is the defined name in mkdocs.yml)

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

PLUGIN_NAME

PLUGIN_NAME: str = 'custom_blog_categorization'

Name of this plugin. Used in logging.

LOG

LOG: PrefixedLogger = PrefixedLogger(PLUGIN_NAME, getLogger(f'mkdocs.plugins.{PLUGIN_NAME}'))

Logger instance for this plugins.

CustomBlogCategorizationPlugin

CustomBlogCategorizationPlugin()

Bases: BasePlugin[CustomBlogCategorizationConfig]

blog_instance

blog_instance: BlogPlugin = None

custom_view

custom_view: View = None

on_config

on_config(config)

Load the Experience blog instance, override BlogPlugin._render_post

on_files

on_files(files, *, config: MkDocsConfig)

Add the custom views to the blog

on_nav

on_nav(nav, *, config, files)

Attach views to navigation

on_page_markdown

on_page_markdown(markdown, *, page, config, files)

Add custom categorization to the excerpt

decorate_render_post

decorate_render_post(func)

The categorization_toc isn't taken into account when rendering, so adjust the view afterwards

_get_exp_blog_instance

_get_exp_blog_instance(config: MkDocsConfig) -> Optional[BlogPlugin]

Find the blog with the Experience URL

_generate_categorization_views

_generate_categorization_views(plugin: BlogPlugin, config: MkDocsConfig, files: Files)

Generate views for custom categorization. Based on BlogPlugin._generate_categories

_format_path_for_industry

_format_path_for_industry(plugin: BlogPlugin, name: str)

Format path for industry Based on BlogPlugin._format_path_for_category

_slugify_industry

_slugify_industry(name: str)

Based on BlogPlugin._slugify_category