comwes / mkpdfs-mkdocs-plugin

Converts your mkdocs documentation in PDF, to be shared with users
https://comwes.github.io/mkpdfs-mkdocs-plugin
GNU General Public License v3.0
103 stars 36 forks source link

TypeError: 'NoneType' object is not iterable #9

Closed amber-moe closed 3 years ago

amber-moe commented 5 years ago

Some errors happened when I run mkdocs serve. The errors as follow:

INFO    -  Building documentation...
Unable to revert mtime: /Library/Fonts
INFO    -  Cleaning site directory
WARNING -  A relative path to '../' is included in the 'nav' configuration, which is not found in the documentation files
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/mkdocs", line 10, in <module>
    sys.exit(cli())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/__main__.py", line 134, in serve_command
    livereload=livereload
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/commands/serve.py", line 119, in serve
    config = builder()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/commands/serve.py", line 114, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/commands/build.py", line 270, in build
    nav = config['plugins'].run_event('nav', nav, config=config, files=files)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkpdfs_mkdocs/mkpdfs.py", line 44, in on_nav
    self.generator.add_nav(nav)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkpdfs_mkdocs/generator.py", line 66, in add_nav
    self.addToOrder(p)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkpdfs_mkdocs/generator.py", line 89, in addToOrder
    for child in page.children:
TypeError: 'NoneType' object is not iterable

This is my yaml file:

site_name: mkdocs versions
repo_url: https://github.com/Amber1990Zhang/versions
repo_name: versions
theme: 'material'
edit_uri: ''
plugins:
  - mkdocs-versioning:
      version: 1.1.0
  # - mkpdfs
nav:
  - Home : 'index.md'
  - Circle: 'circle.md'
  - Triangle: 'triangle.md'
  - Version: '../'

Please help, thanks.

kruzfuz commented 4 years ago

I'm having the same issue. Have there been any findings on your side in the meantime?

kruzfuz commented 4 years ago

If it's of any help to anybody: we realized that the build process fails if mkpdfs cannot find a file where an item in the nav configuration is declared. For you @Amber1990Zhang, that means it is possible that mkpdfs is looking for a file for the "Version" entry in your nav section but cannot find one, and that's why you receive the error message. I hope that helps!

amber-moe commented 4 years ago

@kruzfuz thanks for your reply, I removed version information this time but it's not working either.

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/mkdocs", line 10, in <module>
    sys.exit(cli())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/commands/build.py", line 298, in build
    config['plugins'].run_event('post_build', config)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkpdfs_mkdocs/mkpdfs.py", line 64, in on_post_build
    self.generator.write()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkpdfs_mkdocs/generator.py", line 53, in write
    self.gen_articles()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkpdfs_mkdocs/generator.py", line 168, in gen_articles
    self.add_tocs()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkpdfs_mkdocs/generator.py", line 154, in add_tocs
    self._gen_toc_section(n)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkpdfs_mkdocs/generator.py", line 186, in _gen_toc_section
    stoc = self._gen_toc_for_section(p.file.url, p)
AttributeError: 'Section' object has no attribute 'file'
comwes commented 4 years ago

Hello @kruzfuz and @Amber1990Zhang,

Currently I'm quite busy at work and will look into this issue as soon as possible.

KR, Gerry N

jwaschkau commented 4 years ago

I think the plugin has a problem with mkdocs>=1.1.

I am using mkdocs < 1.1 without a problem.

igordejanovic commented 4 years ago

I'm having the same issue. Did a quick debugging session and found out that the break occurs if the page is given in the mkdocs nav configuration is a URL. Are links supported in the nav?

jwaschkau commented 4 years ago

I'm having the same issue. Did a quick debugging session and found out that the break occurs if the page is given in the mkdocs nav configuration is a URL. Are links supported in the nav?

I opened a PR ( #26 ) which excludes external links. I think this is the best solution for now as i am not sure how to represent external links in the generated pdf.

comwes commented 3 years ago

This should be fixed in the upcoming version. Probably fixed by #8