ultrabug / mkdocs-static-i18n

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

This plugin doesn't support blog in mkdocs materia #236

Closed mendax1234 closed 11 months ago

mendax1234 commented 1 year ago

Blog plugin has been added to mkdocs material recently in beta version. However, l notice that this plugin doesn't support blog function. And the error is below:

INFO     -  Building documentation...
WARNING  -  mkdocs-material language switcher contextual link is not compatible with theme.features = navigation.instant
WARNING  -  Language 'zh' is not supported by lunr.js, not setting it in the 'plugins.search.lang' option
INFO     -  Cleaning site directory
WARNING  -  A relative path to 'blog/posts/hello-world.zh.md' is included in the 'nav' configuration, which is not found
            in the documentation files
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Scripts\mkdocs.exe\__main__.py", line 7, in <module>      
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1157, in __call__  
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1078, in main      
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1688, in invoke    
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1434, in invoke    
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 783, in invoke     
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\commands\serve.py", line 83, in serve
    builder(config)
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\commands\serve.py", line 76, in builder
build
    nav = config.plugins.run_event('nav', nav, config=config, files=files)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\plugins.py", line 520, in run_event    
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\danie\AppData\Local\Programs\Python\Python311\Lib\site-packages\material\plugins\blog\plugin.py", line 299, in on_nav
    head.previous_page.next_page = tail.next_page
                                   ^^^^^^^^^^^^^^
AttributeError: 'Link' object has no attribute 'next_page'

Hope this bug can be fixed!

ultrabug commented 1 year ago

This one is going to be tricky to get working as the material/blog plugin does not offer many options to lure it into supporting multiple files per post.

At a first glance, supporting the material/blog plugin would require different techniques between suffix and folder i18n structures...

Friendly ping @squidfunk since I see that you're working on improving this plugin

squidfunk commented 1 year ago

We're working on stabilizing the blog plugin at the advent of the 9.2 release, and will also tackle the problem that the PR you linked attempts to fix – better support with plugins that allow to manage navigation dynamically. Currently, the blog plugin requires an explicit nav. This requirement will be lifted before the 9.2 release, so it should work with awesome pages and other plugins. I'm, however, not sure what would be necessary to allow for working with this plugin, as I'm not familar with the different modes it supports. If we can make the blog plugin easily compatible, we're happy to do so, but I'm not sure what it would require. If you, @ultrabug, or somebody else would like to work on a PR that makes it compatible, without tying it to this plugin explicitly, we're happy to consider. However, we'd kindly ask you to wait until the 9.2 release, as the blog plugin will go through a major refactor in the light of MkDocs 1.5, as it makes managing generated files much, much easier ☺️

ultrabug commented 1 year ago

Absolutely okay to wait for 9.2 and the overall update of the plugin @squidfunk, thanks for your input.

I'll be glad to help and contribute what it takes to make it compatible with this plugin so that users will be able to get multilang blogs using both our projects!

squidfunk commented 12 months ago

Material for MkDocs 9.2 is out! The blog plugin was completely rewritten. I invite you to study the source code, it's heavily documented and pretty self-explanatory. Each page generated and managed by the blog plugin receives a distinct type, i.e., Post, View, Archive, Category and so forth. Those types can be imported and checked against by third-party plugins, something like:

from material.plugins.blog.structure import Post, View

def on_page_markdown(self, markdown, *, page, config, files):

    # Handle blog post
    if isinstance(page, Post):
        pass

    # Handle generated views, i.e., blog index, archive and category pages
    elif isinstance(page, View):
        pass

The following event priorities were given, so that third-party plugins can alter behavior before the blog plugin picks them up:

That being said, we're happy to improve interop if you encounter any issues.

ultrabug commented 11 months ago

I'm happy to announce release v1.0.0 of the mkdocs-static-i18n plugin which should fix this issue!