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

Fix support for html logo and favicon as url #9381

Merged
merged 4 commits into from Jun 30, 2021

Conversation

tronical
Copy link
Contributor

Subject: Fix support for html logo and favicon as url

Feature or Bugfix

  • Bugfix

Purpose

Stripping the url in the context setup means that any later isurl()
calls will fail and logo_url will always be a local relative path.

Stripping the url in the context setup means that any later isurl()
calls will fail and logo_url will always be a local relative path.
@tk0miya tk0miya added this to the 4.1.0 milestone Jun 27, 2021
@tk0miya
Copy link
Member

tk0miya commented Jun 27, 2021

Could you merge the HEAD of 4.x branch please?

sphinx/builders/html/__init__.py Outdated Show resolved Hide resolved
sphinx/builders/html/__init__.py Outdated Show resolved Hide resolved
@tronical
Copy link
Contributor Author

Could you merge the HEAD of 4.x branch please?

Will do. I've pushed the merge as well as the assignment fixes. I need a bit more time for the test :)

@tk0miya tk0miya merged commit 83f60d4 into sphinx-doc:4.x Jun 30, 2021
@tk0miya
Copy link
Member

tk0miya commented Jun 30, 2021

Thank you for update. Merging now!

tk0miya added a commit that referenced this pull request Jun 30, 2021
@ViktorHaag
Copy link
Contributor

Hello @tk0miya and @tronical -- I believe this fix has a problem. I will try to state it as I understand the situation.

If you pull your html_logo (or favicon) from a file in your source directory, but someplace other than the conf root, then this fix causes an issue.

The configuration documentation for the HTML writer makes it clear that html_logo and html_favicon should be either file paths (relative to the directory with conf.py) or a URL. In this case, let's assume both are files.

During building both these files will be copied over into the output into the _static directory. Let us assume that I have this in my conf.py:

html_logo = os.path.join( ".static", "logo.png" )
html_favicon = os.path.join( ".static", "favicon.ico" )

That is, in my configuration directory, I have a .static subdirectory where I put my static files (including the logo and favicon files), and this entire directory gets copied over to _static in the output. I can verify that, even with this change, the copying process during build works -- the resource files get found in my .static input directory and copied over to the _static subdirectory in the output as expected.

However, now the problem comes with setting the values for logo and logo_url (and the favicon variable values as well) that will get passed into the templating engine. Before this change, when building the writing context for output we used basename to strip off any leading path information from the original input location found in html_logo. This means that we could find the logo file in a predictable place: the logo file basename, relative to the output static directory.

However, now that we're no longer only taking the basename, the writer is expecting the file to account for the entire input file path to the logo file even though it doesn't write that full path into the output during building.

That is:

  • building takes .static/logo.png and copies it to _static/logo.png
  • writing expects to now find the logo in _static/.static/logo.png because it uses the entire input file path, and not just the basename

I'm really not sure how to fix this problem. There is a workaround -- if you put the logo (and favicon) in your file path in the same directory as the conf file, then there's no preceding relative path in the input declaration of html_logo, and therefore no relative path that gets re-used in the writer output when making the HTML. This seems like a sub-optimal workaround, however. It seems very useful to be able to specify a configurable path for the input file and not have that path used in the output when building the output HTML (but rather, expect to have the files directly within the _static output directory).

I'm quite sorry for the length of this explanation and for commenting on a closed PR.

@tk0miya --- please, what would you like me to do as a next step? Should I take this comment and turn it into a regression issue?

@tronical
Copy link
Contributor Author

Great problem description. Sounds like a valid use-case and therefore regression to me. I could make a change that applies basename again if the supplied values are not URLs. What do you think?

@ViktorHaag
Copy link
Contributor

I think that might do. The documentation for the Templating says this:

logo
The path to the HTML logo image in the static path, or URL to the logo, or ''.
Deprecated since version 4.0: Recommend to use logo_url instead.

logo_url
The relative path to the HTML logo image from the current document, or URL to the logo, or ''.
New in version 4.0.

This seems to indicate to me that we expect logo to be a file path relative to the static output directory for the logo file, and that we expect logo_url to be either a relative URL relative to the current page, or an absolute URL to the logo.

I suspect, therefore, that you're correct that base naming would work when building the values to passed down to the templating engine -- the writer output expects the simple "logo" file location to be relative to the output static directory when it's building either the path value, or the URL value.

@tupui
Copy link

tupui commented Jul 12, 2021

@tronical @ViktorHaag, could this be the cause of the missing logo in our recent builds over at SciPy? We did not change anything to the config and have html_logo = '_static/scipyshiny_small.png', and the missing logo started with yesterdays release (4.1).

scipy/scipy#14396

@ViktorHaag
Copy link
Contributor

@tupui I suspect it might. From what I can tell, if you set html_logo = '_static/scipyshiny_small.png', then I would expect that when HTML gets written to the output, it might actually be looking for the logo in /_static/_static/scipyshiny_small.png...?

@tupui
Copy link

tupui commented Jul 12, 2021

@tupui I suspect it might. From what I can tell, if you set html_logo = '_static/scipyshiny_small.png', then I would expect that when HTML gets written to the output, it might actually be looking for the logo in /_static/_static/scipyshiny_small.png...?

Just checked and this is the case! Thanks for your help. So I can also confirm the regression here.

@ViktorHaag
Copy link
Contributor

As we have a replication from SciPy, I've created an issue for going forward: #9438

sjtuhpc pushed a commit to SJTU-HPC/docs.hpc.sjtu.edu.cn that referenced this pull request Jul 13, 2021
refer to sphinx-doc/sphinx#9381

Signed-off-by: taleintervenor <taleintervenor@sjtu.edu.cn>
tronical added a commit to tronical/sphinx that referenced this pull request Jul 13, 2021
… conf.py

Merge request sphinx-doc#9381 broke support for local logos/favicons as it
retained the paths that are passed to the template engine. That's wrong
as the actual path will be in _static/.

This should fix sphinx-doc#9438
tronical added a commit to tronical/sphinx that referenced this pull request Jul 13, 2021
… conf.py

Merge request sphinx-doc#9381 broke support for local logos/favicons as it
retained the paths that are passed to the template engine. That's wrong
as the actual path will be in _static/.

This should fix sphinx-doc#9438
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants