Skip to content

Commit

Permalink
Search urls links to the definition point and not the expansion
Browse files Browse the repository at this point in the history
Otherwise, we can end up with 404 links. See #1106.

Signed-off-by: Paul-Elliot <[email protected]>
  • Loading branch information
panglesd committed May 2, 2024
1 parent d60175b commit 72bc8c4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
9 changes: 4 additions & 5 deletions src/search/html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ type html = Html_types.div_content Tyxml.Html.elt
open Odoc_model
open Lang

let url id =
match
Odoc_document.Url.from_identifier ~stop_before:false
(id :> Odoc_model.Paths.Identifier.t)
with
let url { Entry.id; kind; doc = _ } =
let open Entry in
let stop_before = match kind with Doc _ -> false | _ -> true in
match Odoc_document.Url.from_identifier ~stop_before id with
| Ok url ->
let config =
Odoc_html.Config.v ~search_result:true ~semantic_uris:false
Expand Down
4 changes: 1 addition & 3 deletions src/search/html.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ type html = Html_types.div_content Tyxml.Html.elt

val of_entry : Entry.t -> html list

val url :
Odoc_model.Paths.Identifier.Any.t ->
(string, Odoc_document.Url.Error.t) Result.result
val url : Entry.t -> (string, Odoc_document.Url.Error.t) Result.result

(** The below is intended for search engine that do not use the Json output but
Odoc as a library. Most search engine will use their own representation
Expand Down
4 changes: 2 additions & 2 deletions src/search/json_index/json_display.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Odoc_search

let of_entry { Entry.id; doc = _; kind = _ } h =
match Html.url id with
let of_entry entry h =
match Html.url entry with
| Result.Ok url ->
let html =
h
Expand Down
6 changes: 3 additions & 3 deletions test/search/html_search.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ The index file, one entry per line:
{"id":[{"kind":"Page","name":"page"},{"kind":"Label","name":"a-title"}],"doc":"A title","kind":{"kind":"Doc","subkind":"Heading"},"display":{"url":"page/index.html#a-title","html":"<code class=\"entry-kind\">doc</code><code class=\"entry-title\"><span class=\"prefix-name\">page.</span><span class=\"entry-name\">a-title</span></code><div class=\"entry-comment\"><div><p>A title</p></div></div>"}}
{"id":[{"kind":"Root","name":"J"}],"doc":"a paragraph one","kind":{"kind":"Module"},"display":{"url":"page/J/index.html","html":"<code class=\"entry-kind\">mod</code><code class=\"entry-title\"><span class=\"entry-name\">J</span></code><div class=\"entry-comment\"><div><p>a paragraph one</p></div></div>"}}
{"id":[{"kind":"Root","name":"Main"}],"doc":"","kind":{"kind":"Module"},"display":{"url":"page/Main/index.html","html":"<code class=\"entry-kind\">mod</code><code class=\"entry-title\"><span class=\"entry-name\">Main</span></code><div class=\"entry-comment\"><div></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Module","name":"I"}],"doc":"","kind":{"kind":"Module"},"display":{"url":"page/Main/I/index.html","html":"<code class=\"entry-kind\">mod</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.</span><span class=\"entry-name\">I</span></code><div class=\"entry-comment\"><div></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Module","name":"M"}],"doc":"","kind":{"kind":"Module"},"display":{"url":"page/Main/M/index.html","html":"<code class=\"entry-kind\">mod</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.</span><span class=\"entry-name\">M</span></code><div class=\"entry-comment\"><div></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Module","name":"X"}],"doc":"","kind":{"kind":"Module"},"display":{"url":"page/Main/X/index.html","html":"<code class=\"entry-kind\">mod</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.</span><span class=\"entry-name\">X</span></code><div class=\"entry-comment\"><div></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Module","name":"I"}],"doc":"","kind":{"kind":"Module"},"display":{"url":"page/Main/index.html#module-I","html":"<code class=\"entry-kind\">mod</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.</span><span class=\"entry-name\">I</span></code><div class=\"entry-comment\"><div></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Module","name":"M"}],"doc":"","kind":{"kind":"Module"},"display":{"url":"page/Main/index.html#module-M","html":"<code class=\"entry-kind\">mod</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.</span><span class=\"entry-name\">M</span></code><div class=\"entry-comment\"><div></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Module","name":"X"}],"doc":"","kind":{"kind":"Module"},"display":{"url":"page/Main/index.html#module-X","html":"<code class=\"entry-kind\">mod</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.</span><span class=\"entry-name\">X</span></code><div class=\"entry-comment\"><div></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Type","name":"t"}],"doc":"A comment","kind":{"kind":"TypeDecl","private":false,"manifest":"int","constraints":[]},"display":{"url":"page/Main/index.html#type-t","html":"<code class=\"entry-kind\">type</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.</span><span class=\"entry-name\">t</span><code class=\"entry-rhs\"> = int</code></code><div class=\"entry-comment\"><div><p>A comment</p></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Type","name":"tdzdz"}],"doc":"A comment aaaaaaaaaa","kind":{"kind":"TypeDecl","private":false,"manifest":null,"constraints":[]},"display":{"url":"page/Main/index.html#type-tdzdz","html":"<code class=\"entry-kind\">type</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.</span><span class=\"entry-name\">tdzdz</span><code class=\"entry-rhs\"> = A of int * int | B of int list * int</code></code><div class=\"entry-comment\"><div><p>A comment aaaaaaaaaa</p></div></div>"}}
{"id":[{"kind":"Root","name":"Main"},{"kind":"Module","name":"M"},{"kind":"Type","name":"t"}],"doc":"dsdsd","kind":{"kind":"TypeDecl","private":false,"manifest":null,"constraints":[]},"display":{"url":"page/Main/M/index.html#type-t","html":"<code class=\"entry-kind\">type</code><code class=\"entry-title\"><span class=\"prefix-name\">Main.M.</span><span class=\"entry-name\">t</span></code><div class=\"entry-comment\"><div><p>dsdsd</p></div></div>"}}
Expand Down
14 changes: 14 additions & 0 deletions test/search/module_aliases.t/main.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
module X = struct
let x = 1

(** some comment *)
end

module Y = X
module Z = Y

module L = Stdlib.List

module type X = sig
val x : int
end

module type Y = X
module type Z = Y

module type L = module type of Stdlib.List
23 changes: 15 additions & 8 deletions test/search/module_aliases.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ Compile and link the documentation
$ odoc link main.odoc
$ odoc compile-index main.odocl

We have a problem: The ID for Y generates an URL to a file which is not
generated (as the module does not have an expansion).
Search results only redirect to their definition point (not the
expansions). Comments link to the expansion they are in.

$ cat index.json | jq | grep url |grep Y
"url": "Main/Y/index.html",

$ odoc html-generate -o html main.odocl && ls Main/Y/index.html
ls: cannot access 'Main/Y/index.html': No such file or directory
[2]
$ cat index.json | jq -r '.[] | "\(.id[-1].name) -> \(.display.url)"'
Main -> Main/index.html
X -> Main/index.html#module-X
x -> Main/X/index.html#val-x
X -> Main/X/index.html
Y -> Main/index.html#module-Y
Z -> Main/index.html#module-Z
L -> Main/index.html#module-L
X -> Main/index.html#module-type-X
x -> Main/module-type-X/index.html#val-x
Y -> Main/index.html#module-type-Y
Z -> Main/index.html#module-type-Z
L -> Main/index.html#module-type-L

0 comments on commit 72bc8c4

Please sign in to comment.