ultrabug / mkdocs-static-i18n

MkDocs i18n plugin using static translation markdown files
https://ultrabug.github.io/mkdocs-static-i18n/
MIT License
219 stars 37 forks source link

Fix incompatiiblity with material-blog plugin #268

Open dvolodin7 opened 9 months ago

dvolodin7 commented 9 months ago

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

Proposed fix checks for page attribute is really set.

ultrabug commented 9 months ago

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.

dvolodin7 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

@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

ultrabug commented 8 months ago

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...

dvolodin7 commented 8 months ago

@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.

kamilkrzyskow commented 8 months ago

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 🤔

ultrabug commented 8 months ago

@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.

janvanveldhuizen commented 7 months ago

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.

kamilkrzyskow commented 5 months ago

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 commented 6 days ago

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:

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: