mkdocs-static-i18n icon indicating copy to clipboard operation
mkdocs-static-i18n copied to clipboard

Fix incompatiiblity with material-blog plugin

Open dvolodin7 opened this issue 1 year ago • 11 comments

Files for graphic assets in material blog posts have page = None, leading to crash.

Proposed fix checks for page attribute is really set.

dvolodin7 avatar Oct 03 '23 09:10 dvolodin7

Hi @dvolodin7 thanks for your contribution.

Did you actually get a working blog out of this PR? Because it indeed fixes a crash but it does not fully fix the incompatibility with the material blog plugin AFAIK.

ultrabug avatar Oct 13 '23 08:10 ultrabug

Though this bug fixes a crash and allows to build doc at all, the blog section is still empty. Current state can be checked at our site: https://getnoc.com/blog/

Project repository is here: https://github.com/nocproject/noc/

I'm still investigating the problem. First problem, the mkdocs_static_i18n ignores additional pages, generated by material blog plugin:

WARNING -  mkdocs_static_i18n: Unhandled file case - blog/archive/2023.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/archive/2022.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/archive/2021.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/archive/2020.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/archive/2019.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/archive/2018.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/archive/2011.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/category/general.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/category/releases.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/page/2/index.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/page/3/index.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/page/4/index.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/category/releases/page/2.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/category/releases/page/3.md
WARNING -  mkdocs_static_i18n: Unhandled file case - blog/category/releases/page/4.md
INFO    -  DeprecationWarning: A plugin has set File.page to an instance of Page and it got overwritten. The behavior of this will change in MkDocs 1.6

I believe it is the same problem, which leads to incompatibility with mkdocs_gen_files plugin, I have previously reported in #263 . The reason is that files absolute paths are in temporary directory, not in docs.

And later, when using mkdocs serve

INFO    -  The following pages are being built only for the preview but will be excluded from `mkdocs build` per
           `exclude_docs`:
             - http://127.0.0.1:8000/blog/2019-noc-18-1-1/
             - http://127.0.0.1:8000/blog/2018-noc-18-1a1/
             - http://127.0.0.1:8000/blog/2019-noc-19-1-1/
             - http://127.0.0.1:8000/blog/2019-noc-19-1-2/
             - http://127.0.0.1:8000/blog/2019-noc-19-1-3/
             - http://127.0.0.1:8000/blog/2019-noc-19-1/
             - http://127.0.0.1:8000/blog/2019-noc-19-2-1/
             - http://127.0.0.1:8000/blog/2019-noc-19-2-2/
             - http://127.0.0.1:8000/blog/2019-noc-19-2/
             - http://127.0.0.1:8000/blog/2019-noc-19-3-1/
             - http://127.0.0.1:8000/blog/2019-noc-19-3/
             - http://127.0.0.1:8000/blog/2020-noc-20-1/
             - http://127.0.0.1:8000/blog/2020-noc-20-2-1/
             - http://127.0.0.1:8000/blog/2020-noc-20-2-2/
             - http://127.0.0.1:8000/blog/2020-noc-20-2/
             - http://127.0.0.1:8000/blog/2020-noc-20-3/
             - http://127.0.0.1:8000/blog/2021-noc-20-4-5/
             - http://127.0.0.1:8000/blog/2022-noc-20-4-6/
             - http://127.0.0.1:8000/blog/2020-noc-20-4/
             - http://127.0.0.1:8000/blog/2022-noc-2211/
             - http://127.0.0.1:8000/blog/2022-noc-2212/
             - http://127.0.0.1:8000/blog/2022-noc-2213/
             - http://127.0.0.1:8000/blog/2022-noc-2214/
             - http://127.0.0.1:8000/blog/2022-noc-22-1/
             - http://127.0.0.1:8000/blog/2022-noc-2221/
             - http://127.0.0.1:8000/blog/2022-noc-2222/
             - http://127.0.0.1:8000/blog/2022-noc-2223/
             - http://127.0.0.1:8000/blog/2023-noc-2224/
             - http://127.0.0.1:8000/blog/2022-noc-222/
             - http://127.0.0.1:8000/blog/2023-noc-2311/
             - http://127.0.0.1:8000/blog/2023-noc-2312/
             - http://127.0.0.1:8000/blog/2023-noc-2313/
             - http://127.0.0.1:8000/blog/2023-noc-2314/
             - http://127.0.0.1:8000/blog/2023-noc-2315/
             - http://127.0.0.1:8000/blog/2023-noc-231/
             - http://127.0.0.1:8000/blog/2023-project-augeas-unifying-noc-documentation/
             - http://127.0.0.1:8000/blog/2018-welcome-to-new-site/
             - http://127.0.0.1:8000/blog/2011-index/
             - http://127.0.0.1:8000/blog/2018-index/

As the result, build/docs/blog/ directory contains only blog images.

dvolodin7 avatar Oct 13 '23 10:10 dvolodin7

Digging further I have found, that exclusion of files are occured in this place in mkdocs build.py:

            if file.page is None and file.inclusion.is_excluded():
                if live_server:
                    excluded.append(urljoin(live_server.url, file.url))
                Page(None, file, config)

I've added additional logging and found, the file.page is None.

dvolodin7 avatar Oct 13 '23 10:10 dvolodin7

@ultrabug I have performed some investigation and tried to combine various versions of mkdocs-material with various versions of mkdocs-static-i18n

It seems the only working combination is mkdocs-static-i18n v1.1.0 and v1.1.1, patched as in this PR, and mkdocs-material v9.2.5.

Using other versions of mkdocs-material either leads tao build errors or leaves blog output empty.

The resulting blog is on our side: https://getnoc.com/blog/ The code is in our repo: https://code.getnoc.com/noc/noc

dvolodin7 avatar Oct 18 '23 10:10 dvolodin7

Yes you're right @dvolodin7

FYI I've been working on the blog plugin support lately. I'm making progress but it's pretty hard because of the material/blog internals...

ultrabug avatar Oct 19 '23 20:10 ultrabug

@ultrabug I'm completely agree. I've tried to investigate both plugins' internals and the problem is not trivial

At least, I have good stand and can help to check patches.

dvolodin7 avatar Oct 20 '23 07:10 dvolodin7

Yes you're right @dvolodin7

FYI I've been working on the blog plugin support lately. I'm making progress but it's pretty hard because of the material/blog internals...

@ultrabug I know it's not a simple matter, but do you perhaps have some kind of ETA for the support? I didn't touch it myself after the 9.2 release, because I had other compatibility issues to fix first, and I believed it will be supported soon, but perhaps I should also chip in with my 2 cents and hack a working solution 🤔

kamilkrzyskow avatar Oct 20 '23 20:10 kamilkrzyskow

@kamilkrzyskow I don't really have an ETA yet. I prioritized some open issues / bugs and your own proposals so far instead of working on the blog support.

As for now, I've made progress but as I said it's a real struggle and finding the right amount of focused time is hard for me lately.

What I can say is that it's now my primary focus when it comes to this plugin's development.

ultrabug avatar Oct 25 '23 12:10 ultrabug

Would this be a solution for my issue too?

Traceback (most recent call last):
  File "/home/jan/.local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/home/jan/.local/lib/python3.10/site-packages/click/core.py", line 1134, in __call__
    return self.main(*args, **kwargs)
  File "/home/jan/.local/lib/python3.10/site-packages/click/core.py", line 1059, in main
    rv = self.invoke(ctx)
  File "/home/jan/.local/lib/python3.10/site-packages/click/core.py", line 1665, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jan/.local/lib/python3.10/site-packages/click/core.py", line 1401, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jan/.local/lib/python3.10/site-packages/click/core.py", line 767, in invoke
    return __callback(*args, **kwargs)
  File "/home/jan/.local/lib/python3.10/site-packages/mkdocs/__main__.py", line 270, in serve_command
    serve.serve(**kwargs)
  File "/home/jan/.local/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 86, in serve
    builder(config)
  File "/home/jan/.local/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, live_server=None if is_clean else server, dirty=is_dirty)
  File "/home/jan/.local/lib/python3.10/site-packages/mkdocs/commands/build.py", line 311, in build
    nav = config.plugins.on_nav(nav, config=config, files=files)
  File "/home/jan/.local/lib/python3.10/site-packages/mkdocs/plugins.py", line 536, in on_nav
    return self.run_event('nav', nav, config=config, files=files)
  File "/home/jan/.local/lib/python3.10/site-packages/mkdocs/plugins.py", line 507, in run_event
    result = method(item, **kwargs)
  File "/home/jan/.local/lib/python3.10/site-packages/mkdocs_static_i18n/plugin.py", line 76, in on_nav
    nav = self.reconfigure_material_blog(nav, config, files)
  File "/home/jan/.local/lib/python3.10/site-packages/mkdocs_static_i18n/reconfigure.py", line 765, in reconfigure_material_blog
    file.page._set_canonical_url(mkdocs_config.get('site_url', None))
AttributeError: 'NoneType' object has no attribute '_set_canonical_url'

I have mkdcos-material 9.4.10 and mkdcos-static-i18n 1.2.0

I am building a multilingual site, and am trying to add a blog. As soon as I add my first blog post, it crashes.

janvanveldhuizen avatar Nov 24 '23 07:11 janvanveldhuizen

Hello @ultrabug, any ETA after a few months? Do you have some draft PR you could share to give me a head-start of what the issues might be when supporting the blog plugin?

kamilkrzyskow avatar Feb 09 '24 14:02 kamilkrzyskow

Version 1.2.3 of the plugin introduces the same fix for the crash as this PR. The author of the fix was once again not attributed (as the first person to fix the crash), but those are only 2 lines, so who cares, right? 🙄 (I do care...)

Anyways, I don't think this PR will move further, so it should be closed. And the discussion, should move to the related issue:

  • https://github.com/ultrabug/mkdocs-static-i18n/issues/283

I got 1 like before the edit 👀 EDIT: I provided a makeshift hook solution to allow for one default language blog instance, so if anyone is interested you'll find it here:

  • https://github.com/ultrabug/mkdocs-static-i18n/issues/283#issuecomment-2213879576

kamilkrzyskow avatar Jul 08 '24 11:07 kamilkrzyskow