Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some internal references aren't processed correctly #68

Closed
tijlk opened this issue Feb 11, 2022 · 5 comments
Closed

Some internal references aren't processed correctly #68

tijlk opened this issue Feb 11, 2022 · 5 comments

Comments

@tijlk
Copy link

tijlk commented Feb 11, 2022

Hi Tim,

Since I added the lightgallery mkdocs plugin to my documentation, I can't use the print-site plugin anymore, because the print-site plugin seems to replace url's incorrectly.

The lightgallery plugin adds the following to my index.html page:

<link href="./assets/theme/css/lightgallery.min.css" rel="stylesheet"/>
<script src="./assets/theme/js/lightgallery.min.js"></script>

Note the ./ before assets. I'm not sure why it's doing this. I don't specify the path to the .css and .js files anywhere directly. I'm assuming lightgallery pulls this from the theme - custom_dir which is set to docs/assets/theme in my case.

In print_page.html created by the print-site plugin, this is then changed to:

<link rel="stylesheet" href="//assets/theme/css/lightgallery.min.css">
<script src="//assets/theme/js/lightgallery.min.js"></script>

While just loading the print_page.html file in the browser doesn't seem to give any issue, when I then use htmlark to convert it into a single .html file with everything embedded into it, it fails, because it then claims the .css and .js for lightgallery can't be found.

I'm not entirely sure whether this is a bug in the print-site plugin or elsewhere to be honest.

I worked around it for now by changing my workflow from:

mkdocs build
htmlark docs_html/print_page.html -o documentation.html

to

mkdocs build
sed -i 's/\/\/assets/assets/g' docs_html/print_page.html
htmlark docs_html/print_page.html -o documentation.html
@timvink
Copy link
Owner

timvink commented Feb 13, 2022

Hi Tijl!

Thanks for reporting. I'm having trouble re-producing this locally (urls with "./assets" are kept unchanged).

Two things to check:

  • are you using the latest version of this plugin? 2.2.3 was the last release that fixed some edge cases with URLs
  • Can you try running htmlark inside the directory where mkdocs build outputs (by default site/)

If possible it would be great to have a minimal reproducible example (for example in a temporary repo). If I can reproduce then I can debug, fix and write a unit test for it.

@timvink
Copy link
Owner

timvink commented Feb 13, 2022

I also see there are multiple mkdocs lightbox plugins:

Which one are you using? And which Mkdocs version? Python version? Mkdocs theme? etc :)

@tijlk
Copy link
Author

tijlk commented Feb 15, 2022

I'm using:

@tijlk
Copy link
Author

tijlk commented Feb 15, 2022

Hi Tim,

You can find a reproducible example here.

To reproduce:

  1. Clone https://github.com/tijlk/print-site-debugging
  2. Run ./create_env.sh
  3. Run ./build_docs_unsuccessfully.sh and you'll get the error at the end:
...
INFO     -  Documentation built in 0.54 seconds
CSS: Error reading '//assets/theme/css/lightgallery.min.css': No such file or directory
Unable to convert webpage: [Errno 2] No such file or directory: '//assets/theme/css/lightgallery.min.css'

If instead you run ./build_docs_successfully.sh, which has the added sed -i '' 's/\/\/assets/assets/g' docs_html/print_page.html command, it'll run successfully.

I'm assuming you're on Mac and have conda installed.

@timvink
Copy link
Owner

timvink commented Feb 16, 2022

Awesome! Very very helpful.

<link rel="stylesheet" href="//assets/theme/css/lightgallery.min.css">
<script src="//assets/theme/js/lightgallery.min.js"></script>

The // prefix in those URLs is caused by the main.html template (these lines). I could already fix the issue by removing the {{ base_url }}/ bit in the template. But that's not really a solution because then it would only work when mkdocs.yml uses use_directory_urls: false.

So I added some extra logic that looks for href links in the <head> section of the print page that start with "//", and replace it with "" or "../". I can do that because the print-site is always on the main level (either print_site.html or print_site/index.html).

Just released in v2.3.1. Let me know if it works for you :)

@timvink timvink closed this as completed Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants