You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following up on squidfunk/mkdocs-material#5909 (comment), I'm suggesting to adjust the logic that MkDocs implies to create Page objects from/in files, i.e., File objects. Currently, _data_to_navigation will always create (and thus overwrite) Page on everything that doesn't look like a Link or Section. Excerpt of the comment linked:
MkDocs will always generate either a Link or a Page for a file that is not excluded. As you've probably noticed, the blog plugin makes use of subclasses for pages of specific types, e.g. Post, View, etc., and relations among different concepts in the plugin are managed inside the instances of those subclasses. The problem is, that MkDocs will always generate a plain old Page instance, overwriting the more specific instance that has been generated by the plugin beforeafter on_files and before on_nav. We could still solve it by splitting file generation and page instantiation, but this would make things much more complicated and non-linear, because during generation, we already assign categories to pages and vice versa, etc. We would need to split this into two stages, blowing up the code base of the plugin and also the runtime, as we're doing two passes. This is clearly not favorable from our perspective.
Moving forward: I believe that this problem can be mitigated with a very small but important change in MkDocs: if a File already defines a dedicated Page in file.page, MkDocs should just use that instead of creating a new one:
It's essentially a single line change in MkDocs that would make things much, much simpler for plugin developers. I've written several plugins now, and I repeatedly had to work around the oddities of this behavior.
# Now: always create a pagereturnPage(title, file, config)
# Better: only create a page when one was not created beforereturnfile.pageifisinstance(file.page, Page) elsePage(title, file, config)
Currently, the only way to work around this limitation is to overwrite Page.__class__ on the resulting instance in on_nav, e.g., like done in section-index, which, AFAIK, does not call __init__ or initializes instance variables:
Following up on squidfunk/mkdocs-material#5909 (comment), I'm suggesting to adjust the logic that MkDocs implies to create
Page
objects from/in files, i.e.,File
objects. Currently,_data_to_navigation
will always create (and thus overwrite)Page
on everything that doesn't look like aLink
orSection
. Excerpt of the comment linked:Thus, I'm proposing to change the following line:
Currently, the only way to work around this limitation is to overwrite
Page.__class__
on the resulting instance inon_nav
, e.g., like done in section-index, which, AFAIK, does not call__init__
or initializes instance variables:The text was updated successfully, but these errors were encountered: