jimporter / mike

Manage multiple versions of your MkDocs-powered documentation via Git
BSD 3-Clause "New" or "Revised" License
534 stars 47 forks source link

Redirect selected version to target file v2.0/index.html #71

Closed vhristev closed 2 years ago

vhristev commented 2 years ago

Hello team ,

First to tell that I'm aware mike is more focused on Github pages.

The problem: Short: Web server require target file like 'index.html' it will not load index.html if you open target folder.

Long: My static site is hosted on JFrog artifactory and JFrog can serve static content but it's not working as a normal Web server ( apache / nginx ).

Lets assume you use a regular Web server like Apache and you configure DirectoryIndex index.html In JFrog if you open the URL it will create an Index page if you click on the index.html your site is rendered. So far so good. The problem comes when you start clicking on other pages where you see Index page and you need to click on index.html to render it.

The solution for MKDocs is to use an option use_directory_urls: false . This setting controls the style used for linking to pages within the documentation.The alternate style can be useful if you want your documentation to remain properly linked when opening pages directly from the file system, because it creates links that point directly to the target file rather than the target directory.

When i build doc with mike I modify the main index.html to redirect to my default folder + index.html file

<script>
    window.location.replace("v1.0/index.html" + window.location.hash);
  </script>

The question is how i can do the same thing when i choose from the drop down menu version 2.0 / 3.0 ...etc I want to redirect to file v2.0/index.html instead of folder v2.0/

I tried modifying versions.json but i got an error:

{
  "errors" : [ {
    "status" : 404,
    "message" : "{\"error\":\"Expected a folder but found a file, at: XXXXX:YYYYYY/public/v2.0/index.html\"}"
  } ]
}
jimporter commented 2 years ago

Hmm, this sounds to me more like it's a bug in JFrog's code. I'd certainly expect any simple web server to understand directory indices like index.html, and to do the obvious thing if a browser requests such a directory.

On mike's end, I don't think the default version selection logic should change, since the current way is correct: version X doesn't know how version Y's docs are structured, so it can't even be sure that the index page is index.html (as opposed to index.htm, for example*). Redirecting to the directory itself allows each version to be slightly different in this regard, so long as the directory index is set up correctly on the server.

In your case, I think the best workaround would be to disable mike's automatic insertion of the version selector and to use your own implementation. If you do the following in mkdocs.yml:

plugins:
  - mike:
      version_selector: false
      # ...

extra_css:
  - css/version-select.css
extra_javascript:
  - js/version-select.js

And then copy the appropriate CSS and JS for your theme (for example, here are the files for the mkdocs theme), you should be able to tweak the JS to your liking.

* This is more likely to be an issue when older versions of docs were generated with a different tool entirely, and the user has connected them all together via mike.

vhristev commented 2 years ago

Thank you @jimporter for the fast response.

I don't think it's a JFrog bug it's more likely to be a feature (: it acts like FTP which can serve HTML. They are a couple of public tickets raised to JFrog about that but there is no response from them.

From mike perspective i totally agree with your explanation and its logical to be like that. Thank you very much for the suggestion to use my own CSS and JS and implement a selection but i dont think i will go that way i will just move to a real web server. I was just wondering if there is some kind of tricky hack i can use to overcome the JFrog web serving 'feature'