infotexture / dita-bootstrap

DITA Open Toolkit plug-in for HTML5 output with extensible Bootstrap style
https://infotexture.github.io/dita-bootstrap
Apache License 2.0
16 stars 10 forks source link

Dark mode not working on topics in subfolders #141

Closed lakokkonen closed 1 year ago

lakokkonen commented 1 year ago

Using the latest dev version of the plugin.

If a topic is located in a subfolder more than one level deep from the output directory, the dark mode toggler doesn't work on the HTML page.

It looks like the path to the .js file is always ../js/dark-mode-toggler.js, and of course that only works for pages that are located one folder deep. I believe the issue is in the relpath variable, but that's where my XSLT skills end in this case.

EDIT:

Actually now I got it working by changing the regex in the replace function:

But as a result the file path contains both forward and backslashes. Seems to work, however, both on local files and via an http server.

EDIT 2:

I was able to switch the backslashes to forward ones with this monstrosity:

infotexture commented 1 year ago

@lakokkonen I can't reproduce this on macOS. The toggler works fine there regardless of hierarchy.

Are you running into this problem on Windows?

lakokkonen commented 1 year ago

@infotexture Yes, I'm using Windows and local files.

It seems like this issue stems from the Windows file path naming which uses backslashes.

jason-fox commented 1 year ago

@lakokkonen - I think the following regex simplifies your fix and continues to work on Linux - could you check

<xsl:value-of select="replace(replace($FILEDIR, '\\', '/') ,'[^/]+','..')"/>

see #142

lakokkonen commented 1 year ago

@jason-fox yes, now it's working on Windows.

By the way: This same issue also affects the lunr plugin's path to the JS file. Currently the search is not working on Windows if a topic is located in a subfolder. The new regex fixes this, too.

infotexture commented 1 year ago

Fixed by https://github.com/infotexture/dita-bootstrap/pull/142.