Skip to content

Built-in blog plugin not compatible with mkdocs-static-i18n #4863

@jeremy-feng

Description

@jeremy-feng

Context

I want to write blogs in multiple languages. I found mkdocs-static-i18n is easy to use.

So I try to organize my blog contents with two languages, zh(default language) and en. That is, one is file_name.md and another one is file_name.en.md.

Bug description

mkdocs-static-i18n is a nice plugin for write contents in multiple laguages. However, when I use both blog and mkdocs-static-i18n plugins, adding a .md file in blog/posts will result in an error: AttributeError: 'NoneType' object has no attribute 'title'

Traceback (most recent call last):
  File "C:\Users\Administrator\miniconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Administrator\miniconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Administrator\miniconda3\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "C:\Users\Administrator\miniconda3\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\Administrator\miniconda3\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Users\Administrator\miniconda3\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\Administrator\miniconda3\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\Administrator\miniconda3\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\Administrator\miniconda3\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\Administrator\miniconda3\lib\site-packages\mkdocs\commands\serve.py", line 116, in serve
    server.serve()
  File "C:\Users\Administrator\miniconda3\lib\site-packages\mkdocs\livereload\__init__.py", line 162, in serve
    self._build_loop()
  File "C:\Users\Administrator\miniconda3\lib\site-packages\mkdocs\livereload\__init__.py", line 184, in _build_loop
    func()
  File "C:\Users\Administrator\miniconda3\lib\site-packages\mkdocs\commands\serve.py", line 76, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "C:\Users\Administrator\miniconda3\lib\site-packages\mkdocs\commands\build.py", line 311, in build
    env = config.plugins.run_event('env', env, config=config, files=files)
  File "C:\Users\Administrator\miniconda3\lib\site-packages\mkdocs\plugins.py", line 520, in run_event
    result = method(item, **kwargs)
  File "C:\Users\Administrator\miniconda3\lib\site-packages\material\plugins\blog\plugin.py", line 489, in on_env
    self._generate_excerpt(file, base, config, files)
  File "C:\Users\Administrator\miniconda3\lib\site-packages\material\plugins\blog\plugin.py", line 730, in _generate_excerpt
    excerpt = Page(page.title, temp, config)
AttributeError: 'NoneType' object has no attribute 'title'

I tested many senarios.

  • Use both blog and mkdocs-static-i18n:
    • AttributeError: 'NoneType' object has no attribute 'title'
  • Only use blog but not mkdocs-static-i18n:
    • Blog style works well but I can not write contents in multiple laguanges with ease.
  • Only use mkdocs-static-i18n but not blog:
    • I can not write contents in multiple laguanges, but the blog features are all lost.

Related links

https://ultrabug.github.io/mkdocs-static-i18n/

Reproduction

I tried to generate a reproduction .zip file using the built-in info plugin.

When I run mkdocs build, it asks me to upgrade to the latest version. So I have to replace my current insider version to public version.

But my issue need to use blog plugin. So I cannot build it as well.

I have prepared a zip file which contains the minimal project source files. I hope you can help me solve it. Thank you!

test.zip

Steps to reproduce

  1. mkdocs serve. There should be an error indicating that there is a problem (possibly related to blog title) with the .md file in /blog.
  2. If you delete the i18n plugin, you will find that the blog is rendered well.

Browser

Chrome

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugnot fixableIssue concerns an unfixable bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions