art-w / sherlodoc

Fuzzy type search for OCaml documentation
MIT License
70 stars 6 forks source link

Customize DB base URL #41

Closed dlesbre closed 4 months ago

dlesbre commented 4 months ago

Hi ! Thanks for this awesome project, I've added it to my latest library and it seems like a wonderful addition.

Unfortunately, it doesn't quite work with my setup, since I've changed odoc structure a bit. The package page is ultra-bare so I've removed it. I've instead replaced it with a custom page that has more information and allows selecting which version of the library you want to browse documentation for.

In doing so, I've essentially changed the URL structure from root/package-name/... to root/version/.... This avoids the needless package page per version (and also avoids having to copy all odoc's css and js files to all versions).

However, while the searchbar works, the links are all broken because of this. I realize this is a niche case, and probably not something you'll want to specifically work on, but I was wondering if anyone knew of an any easy way to fix this (even a hacky one) without having to reintroduce the package level in there?

EmileTrotignon commented 4 months ago

I think a very hacky fix would be to edit odoc_search.js to substitute the urls for you. Its not written in js_of_ocaml so you can likely do that by hand without recompiling anything.

dlesbre commented 4 months ago

Thanks for the suggestion, that indeed how I fixed it.

For the record: I changed line 47:

search_result.href = base_url + entry.url;

into

search_result.href = base_url.replace(/^\.\.\//, "") + entry.url.replace(/^patricia\-tree\//, "");

(In https://github.com/codex-semantics-library/patricia-tree/commit/78ac5a38980379a6e8f32fe0b1700ffb55476ff5)