orzih / mkdocs-with-pdf

Generate a single PDF file from MkDocs repository.
MIT License
318 stars 76 forks source link

AttributeError. Don't need a cover page. #80

Open D34m0nN0n3 opened 2 years ago

D34m0nN0n3 commented 2 years ago

Good day!

It is necessary to generate PDF without cover, but an error occurs: AttributeError: 'Options' object has no attribute '_cover_title' How can I fix it?

Site config mkdocs.yml:

  - with-pdf:
      cover: false
      back_cover: false
      headless_chrome_path: headless-chromium
      output_path: document.pdf
      debug_html: true
      verbose: true

Log:

INFO     -  PDF count: 0
Traceback (most recent call last):
  File "/var/mkdocs/.local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs/__main__.py", line 183, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs/commands/build.py", line 309, in build
    config['plugins'].run_event('post_build', config=config)
  File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs/plugins.py", line 96, in run_event
    result = method(**kwargs)
  File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs_with_pdf/plugin.py", line 134, in on_post_build
    self.generator.on_post_build(config, self.config['output_path'])
  File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs_with_pdf/generator.py", line 122, in on_post_build
    add_stylesheet(style_for_print(self._options))
  File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs_with_pdf/styles/__init__.py", line 33, in style_for_print
    """
  File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs_with_pdf/options.py", line 122, in cover_title
    return self._cover_title
AttributeError: 'Options' object has no attribute '_cover_title'
section_end:1632486121:step_script

Version: mkdocs-with-pdf==0.9.2

Yinameah commented 2 years ago

+1 I have the same issue.

F-Brar commented 2 years ago

+1

feasgal commented 2 years ago

+1

nofak commented 1 year ago

+1

3phase commented 1 year ago

Have you found any workarounds?

samzong commented 1 year ago

Just a guess, but could it be due to different versions of Python? I will try downgrading

hotJavaEnjoyer commented 1 year ago

The problem is that self._cover_title in Options.py gets only defined if self.cover=true, but it is always read in line 28 of the init file. So if you configure cover: false in your mkdocs.yml, the init file attempts to read a non existing property.

In order to resolve this issue, one could either always define self._cover_title in Options.py regardless of self.cover:

# Cover
self.cover = local_config['cover']
self.back_cover = local_config['back_cover']
+ self._cover_title = None
if self.cover or self.back_cover:
    self._cover_title = local_config['cover_title'] \
        if local_config['cover_title'] else config['site_name']
    self._cover_subtitle = local_config['cover_subtitle']
    self._cover_logo = local_config['cover_logo']

Or remove the if-statement underneath altogether. The plugin works just fine if cover properties are defined but the cover is invisible.

WangPingGang commented 1 year ago

+1

librick commented 3 months ago

Also seeing this. Using mkdocs 1.5.3 and mkdocs-with-pdf 0.9.3. My config looks like:

site_name: My Docs
plugins:
  - with-pdf:
      cover: false

Running mkdocs build produces the error "AttributeError: 'Options' object has no attribute '_cover_title'. Did you mean: 'cover_title'?".

I created a venv with python3 -m venv venv and activated with source ./venv/bin/activate. I can confirm that modifying venv/lib/python3.11/site-packages/mkdocs_with_pdf/options.py as suggested by https://github.com/orzih/mkdocs-with-pdf/issues/80#issuecomment-1508444386 allows mkdocs build to build succesfully when cover: false.

Obviously, manually patching this file isn't a great solution, maybe someone can put up a PR if one doesn't already exist.