orzih / mkdocs-with-pdf

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

`exclude_pages` Skips Page Html Generation #64

Closed Jacusaurus closed 3 years ago

Jacusaurus commented 3 years ago

Usage of exclude_pages causes whatever pages are excluded to not only be excluded from generated PDF (desired behavior), but also to be skipped when mkdocs generates the site html (undesired behavior).

I have tested this multiple times with both mkdocs build and mkdocs serve as did a colleague of mine on a different mkdocs project. When attempting to navigate to the page on the development server (localhost:8000), when I click the link it changes the browser URL to reflect the target page, but only shows previous pages' content. If I click it again, it updates the URL with additional paths that make the link nonsensical (something like localhost:8000/this/is/a/test/page/ to localhost:8000/this/is/a/test/page/a/test/page/) and I get an error 404. If I attempt to navigate to the page directly by URL, it displays a blank page, with absolutely no content. This is consistent across Chrome and Firefox.

The output file for an excluded site page contains only <!-- skipped 'Page(title='TITLE', url='this/is/a/test/page/')' --> (edited to reflect example used earlier).

I'm using:

I don't know why it would be intended behavior if a user could simply remove a page from their documentation to the same effect. I don't believe that this is intended behavior, but if it is then it should probably be clearly reflected in the documentation.

orzih commented 3 years ago

This plugin does not change anything other than about PDF.

Please check site(output) folder with/without exclude_pages option. If you encounter this issue, please send me your test data.

Jacusaurus commented 3 years ago

@orzih I created a new, simple project to demonstrate the functionality.

I have attached the project files. I used the same mkdocs.yml file, but added the last two lines when I generated the pages with exclude_pages.

In the attached compressed file, site_include is the result of generating the site without exclude_pages and site_exclude is the result of generating the site with exclude_pages. As you can see, the problem is with subpage 1, with the html at site_exclude/subpages/subpage1/index.html, which reads <!-- skipped 'Page(title='Page 1 Placeholder', url='subpages/subpage1/')' -->. The debugging html is also provided. html_for_pdf_include.html is the html produced by generating the site without exclude_pages and html_for_pdf_exclude.html is the html produced by generating the site with exclude_pages. trials.tar.gz

orzih commented 3 years ago

@Jacusaurus Thank you for sending the test data, and, I got what this bug is.

I fixed it in v0.9.1. Please check it.

Jacusaurus commented 3 years ago

@orzih Already updated Pypi version to v0.9.2? You're quick! Unfortunately, while your change fixed the issue of page html not being generated, it broke the exclude_pages option. I tried both with the enabled_if_env and without it, but the pages were never excluded from the PDF.

orzih commented 3 years ago

@Jacusaurus Please check a use_directory_urls mode.

in console log:

WARNING  -  Config value: 'site_url'. Warning: This option is now required. Set to a valid URL or an empty string to avoid an error in a future release.
WARNING  -  Config value: 'site_url'. Warning: The 'use_directory_urls' option has been disabled because 'site_url' contains an empty value. Either define a valid URL
            for 'site_url' or set 'use_directory_urls' to False.

If use_directory_urls: true:

plugins:
    - with-pdf:
        exclude_pages:
            - subpages/subpage1/

If use_directory_urls: false:

plugins:
    - with-pdf:
        exclude_pages:
            - subpages/subpage1.html

And, now exclude_pages use regex. The following is valid in both cases:

plugins:
    - with-pdf:
        exclude_pages:
            - subpages/subpage1
Jacusaurus commented 3 years ago

@orzih You are correct. use_directory_urls is true by default and with the newer version of mkdocs it complained because site_url wasn't set, which is what caused it to generate all site pages into the PDF regardless of exclude_pages. I fixed that error on my end by adding a site_url and also tested the new regex function of exclude_pages. In both cases I didn't notice any undesired behavior. As such, I'm closing this issue. As a side-note, perhaps there should be a note in the README detailing that site_url must be set; however, given that this is a configuration error in mkdocs and not your plugin, maybe such a note doesn't belong in the README. Your call. Aside from the issue, thank you very much for maintaining the plugin and making it publicly available!