vsajip / sphinx_sizzle_theme

This is a theme for Sphinx. It was inspired by the Guzzle theme, but has diverged quite a bit.
https://docs.red-dove.com/sphinx_sizzle_theme/
Other
4 stars 1 forks source link

Incorrect app-data.js path for pages in subdirectories #16

Closed vsajip closed 3 years ago

vsajip commented 3 years ago

Original report by Indian Sunset (Bitbucket: idnsunset, GitHub: idnsunset).


With a page subdir/page.html , I got the error message like sizzle.app_data undefined in the browser console.

For any page in the top output directory, e.g. index.html, context['pathto']('search') returns search.html and replace('search.html', 'app-data.js') works as expected. However, for sub/page.html, context['pathto']('search') returns ../search.html and the replace part will return it as is.

Now let’s look at the js_tag function, it calls pathto function which further calls sphinx.util.osutil.relative_uri function to return a relative path for the target page. When taking ../search.html as target uri, it returns ../../app-data.js which is incorrectly relative to sub/page.html. So the calculation for relative path should be handled by pathto itself, the following code in __init__.py may need to be changed, simply setting app_data_path to app-data.js.

if pagename != ‘search':
    app_data_path = context'pathto'.replace(’search.html', 'app-data.js')`

vsajip commented 3 years ago

Original comment by Indian Sunset (Bitbucket: idnsunset, GitHub: idnsunset).


By the way, I am using Sphinx 3.4, maybe your code works with Sphinx 2.0? Sphinx 3 also changed its searchtools which causes the breakage of search functionality for some old themes. For example, the links to matched files on the search page are now constructed with LINK_SUFFIX instead of the FILE_SUFFIX:

linkUrl = item[0] + DOCUMENTATION_OPTIONS.LINK_SUFFIX;

This requires the definition of DOCUMENTATION.OPTIONS.FILE_SUFFIX or simply loading the officaldocumentation_optoins.js in the layout template.

Will this theme be updated for compatibility with Sphinx 3?

vsajip commented 3 years ago

Will this theme be updated for compatibility with Sphinx 3?

I plan to do so. Will take a look at the other things you’ve mentioned. Thanks.

vsajip commented 3 years ago

The logic of computing app_data_path is that app-data.js is always in the same directory as search.html, so context['pathto']('search') should always give the correct URL to search.html, and then we just replace that part with app-data.js. However, it appears that the problem is due to using js_tag() to output the URL - this appears to add an extra ../, for some reason. I’ve removed usage of that, and the problem seems to go away.

vsajip commented 3 years ago

Fixes #16: Add LINK_SUFFIX to better support Sphinx 3, and avoid using js_tag to output the tag for app-data.js.

vsajip commented 3 years ago

A version of Whoosh documentation (which includes subpages) built with these changes and Sphinx 3.4.2 can be found here.

vsajip commented 3 years ago

Original changes by Indian Sunset (Bitbucket: idnsunset, GitHub: idnsunset).


changed content from "With a page subdir/page.html , I got the error message like sizzle.app_data undefined in the browser console.

For any page in the top output directory, e.g. index.html, context['pathto']('search') returns search.html and replace('search.html', 'app-data.js') works as expected. However, for sub/page.html, context['pathto']('search') returns ../search.html and the replace part will return it as is.

Now let’s look at the pathto function, it calls sphinx.util.osutil.relative_uri function to return a relative path for the target page. When taking ../search.html as target uri, it returns ../../app-data.js which is incorrectly relative to sub/page.html.

When with sub/sub/page.html, context['pathto']('search') will even return ../../app-data.js, so the following code in __init__.py may need to be changed to regex version?

if pagename != ‘search':
    app_data_path = context'pathto'.replace(’search.html', 'app-data.js')`

‌" to "With a page subdir/page.html , I got the error message like sizzle.app_data undefined in the browser console.

For any page in the top output directory, e.g. index.html, context['pathto']('search') returns search.html and replace('search.html', 'app-data.js') works as expected. However, for sub/page.html, context['pathto']('search') returns ../search.html and the replace part will return it as is.

Now let’s look at the js_tag function, it calls pathto function which further calls sphinx.util.osutil.relative_uri function to return a relative path for the target page. When taking ../search.html as target uri, it returns ../../app-data.js which is incorrectly relative to sub/page.html. So the calculation for relative path should be handled by pathto itself, the following code in __init__.py may need to be changed, simply setting app_data_path to app-data.js.

if pagename != ‘search':
    app_data_path = context'pathto'.replace(’search.html', 'app-data.js')`

‌"

vsajip commented 3 years ago

Original changes by Vinay Sajip (Bitbucket: vinay.sajip, GitHub: vsajip).


changed state from "new" to "resolved"