ultrabug / mkdocs-static-i18n

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

Is folder based docs structure incompatible with static navigation? #168

Closed NachtgeistW closed 1 year ago

NachtgeistW commented 1 year ago

I'm trying to build a mkdocs document with this plugin. Since it contains 12 categories and dozens of pages and images, I choose to use folder base docs structure when working on its i18n. It works perfectly when I just set the folder. However, when I'm trying to add static navigation, it begins to throw an exception as below:

``` txt INFO - Building documentation... INFO - Setting the default 'theme.language' option to 'zh' INFO - Cleaning site directory INFO - Translated default navigation to zh INFO - Translated navigation to zh Traceback (most recent call last): File "C:\Users\night\anaconda3\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\night\anaconda3\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\night\anaconda3\Scripts\mkdocs.exe\__main__.py", line 7, in File "C:\Users\night\anaconda3\lib\site-packages\click\core.py", line 1128, in __call__ return self.main(*args, **kwargs) File "C:\Users\night\anaconda3\lib\site-packages\click\core.py", line 1053, in main rv = self.invoke(ctx) File "C:\Users\night\anaconda3\lib\site-packages\click\core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Users\night\anaconda3\lib\site-packages\click\core.py", line 1395, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Users\night\anaconda3\lib\site-packages\click\core.py", line 754, in invoke return __callback(*args, **kwargs) File "C:\Users\night\anaconda3\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\night\anaconda3\lib\site-packages\mkdocs\commands\serve.py", line 83, in serve builder(config) File "C:\Users\night\anaconda3\lib\site-packages\mkdocs\commands\serve.py", line 76, in builder build(config, live_server=live_server, dirty=dirty) File "C:\Users\night\anaconda3\lib\site-packages\mkdocs\commands\build.py", line 302, in build nav = config.plugins.run_event('nav', nav, config=config, files=files) File "C:\Users\night\anaconda3\lib\site-packages\mkdocs\plugins.py", line 520, in run_event result = method(item, **kwargs) File "C:\Users\night\anaconda3\lib\site-packages\mkdocs_static_i18n\plugin.py", line 418, in on_nav nav = folder_structure.on_nav(self, nav, config, files) File "C:\Users\night\anaconda3\lib\site-packages\mkdocs_static_i18n\folder_structure.py", line 402, in on_nav raise Exception( Exception: could not find default homepage Page(url='') ```

Are they incompatible, or do I miss some setting on MkDocs or this plugin?

Here is my project: https://github.com/CeVIO-User-Guide-Unofficial/CeVIO-AI/tree/i18n

The package version. Thought Material for MkDocs is 9.0.0b3 here, I have met this problem in ver 8.5 before:

mkdocs 1.4.2 mkdocs-material 9.0.0b3 mkdocs-material-extensions 1.1 mkdocs-static-i18n 0.53

NachtgeistW commented 1 year ago

I think I have reproduced the problem with the given demo pages. In mkdocs.yml, if you put the index.md under a top level like this:

nav:
  - Home: 
    - index.md

It will throw this exception. But only folder mode occurs this problem, it works fine in suffix mode.


To be honest, I can avoid this problem if I put index.md in a separate top level, but I really do not want to use the 13th category in the document. And for some reason in this document, I had to put some MarkDown files together with index.md. Would you please fix it?

adamkusmirek commented 1 year ago

On the off-chance of sounding dense: I am not sure whether I understand your problem correctly to be honest.

so this config snippet:

nav:
  - Home:
    - index.md

in conjunction with docs_structure: folder will result in the exception being thrown, correct?

What do you mean with this?:

I can avoid this problem if I put index.md in a separate top level,

and this:

I really do not want to use the 13th category in the document

How would the desired outcome look like exactly?

Also:

And for some reason in this document, I had to put some MarkDown files together with index.md

Which files exactly are you refering to here?

BTW: just tried to run your code and everything seemed to go just fine, just had to install some additional deps in addition to the ones you mentioned above.

Full package list:

mkdocs==1..4.2
mkdocs-material==9.0.0b3
mkdocs-material-extensions==1.1
mkdocs-static-i18n==0.53
mkdocs-git-revision-date-localized-plugin ==1.1.0
mkdocs-glightbox==0.3.1
ultrabug commented 1 year ago

Hello @NachtgeistW

Just like @adamkusmirek I installed your documentation but I find any problem with it and your static navigation.

Is this issue still accurate?

NachtgeistW commented 1 year ago

Hello @NachtgeistW

Just like @adamkusmirek I installed your documentation but I find any problem with it and your static navigation.

Is this issue still accurate?

Yes, it is. I will reply to adamkusmirek soon in detail.

NachtgeistW commented 1 year ago

@adamkusmirek Thanks for your reply! Because it's too long, I use @ to reply to you.

so this config snippet:

nav:
  - Home:
    - index.md

in conjunction with docs_structure: folder will result in the exception being thrown, correct?

Yes. According to my research, if index.md isn't put in the root folder, for example, putting it in a subfolder named Home, the plugin will throw this exception.

I can avoid this problem if I put index.md in a separate top level,

means "A simple way to avoid this is to move index.md out of the subfolder." Apologize for my poor English😢

I really do not want to use the 13th category in the document

Please ignore it. This is not related to the exception. Apologize for reporting unrelated content.

BTW: just tried to run your code and everything seemed to go just fine

I think I have pushed the right codes on that branch after reporting this bug by accident. Now I push it again, please use those codes:

https://github.com/CeVIO-User-Guide-Unofficial/CeVIO-AI/tree/i18n_plugin_testing

ultrabug commented 1 year ago

@NachtgeistW did you make progress on this issue?

You might be interested in #175 and the testing branch of #187

ultrabug commented 1 year ago

will land in 0.55