-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Allow plugins to provide their own Page
#3367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Page
Page
Thanks for the change.
I pushed my commit and changed the approach a bit because I think it makes more sense to distinguish "1" as the special case - "don't overwrite any object if it's there", rather than distinguishing "3" - "it's fine to overwrite something if it forgot to subclass Although we could maybe keep thinking and make "2" disallowed altogether? Not sure. Or a warning? Actually let me do that |
Let me know if the current shape of the PR works well for you. I'll actually release it soon, then :) |
Thanks for your input!
I think we shouldn't allow that just now. It's a door to sloppyness, and is something we could add in the future without any compatibility issues if and only if it appears to be necessary for whatever reason – I currently can't think of one. Or am I missing something? |
I didn't understand your comment, sorry 😅 You say we shouldn't allow "that". What is meant here? |
Oops, sorry for not being clear 😅 I meant we shouldn't allow |
Sure, but the thing is that MkDocs currently "allows" it to happen but then just overwrites it. Then the same still happens with your code. That's why I thought it's better to eventually "not allow" it - first show a warning, later break entirely. |
Sure, I think a deprecation path might be a good idea. If such plugins exist, this would be a breaking change for those, but I'd say it's okay, as it's undefined behavior anyways. Adding this change, we also would uncover if there are such plugins and whether there are actually valid use cases for this edge case we currently consider unsound. As an addendum : I've just started using the subclassing technique to add "special" page-like objects to MkDocs, allowing me for much better integration with MkDocs, not having to reimplement parts of it myself. Before the last rewrite of Material for MkDocs' blog plugin, the code was very imperative. Moving specific behavior into subclasses of from material.plugins.blog.structure import Archive
def on_page_markdown(markdown, page, **kwargs):
if isinstance(page, Archive):
# Page is an archive page generated by the blog plugin
pass |
So, to sum up: LGTM! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the course of the discussion and the proposed solution, thanks a lot!
OK sadly this commit actually causes strange changes in behavior! |
Somehow MkDocs first populates that file with |
The problem affects sites that use https://github.com/oprypin/mkdocs-literate-nav First mkdocs_literate_nav creates a bogus file
Then MkDocs used to overwrite that file but now it can't
|
So we likely need to revert this and keep brainstorming 😅 |
First of all things for merging and investigating. So the problem in the mkdocs-nav-literate plugin comes from creating pages to work around the warning that MkDocs emits when pages are not included – this could now be solved with the new file inclusion feature, right? And mkdocs-file-filter uses the page to read metadata early, which is super inefficient as files are always read twice as I can judge from the code. Okay, so not that easy then, and it looks like users had to work around some design limitations, e.g., metadata is only made available after navigation construction, which we solve in the blog plugin by overriding the page class and moving it to the Another idea: we could only imply this logic once if isinstance(file.page, Page) and file.page.__class__.__name__ != Page.__name__ There's probably a better approach to do that. In general, I think we need to find a better way for plugins to work together, as currently, many plugins need to work around one or the other ordering issue. If we manage to find a canonical way that we can recommend, this should go into the developer guide in the docs. |
Thanks. Yes there is a good way to check for the exact type. For this release, let's limit this ability only to strict subclasses. That's not a nice solution but it's the only thing we can reasonably do on short notice. I'll send such a pull request. |
Closes #3366