Skip to content

Commit 72bc8c4

Browse files
committed
Search urls links to the definition point and not the expansion
Otherwise, we can end up with 404 links. See #1106. Signed-off-by: Paul-Elliot <peada@free.fr>
1 parent d60175b commit 72bc8c4

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

src/search/html.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ type html = Html_types.div_content Tyxml.Html.elt
33
open Odoc_model
44
open Lang
55

6-
let url id =
7-
match
8-
Odoc_document.Url.from_identifier ~stop_before:false
9-
(id :> Odoc_model.Paths.Identifier.t)
10-
with
6+
let url { Entry.id; kind; doc = _ } =
7+
let open Entry in
8+
let stop_before = match kind with Doc _ -> false | _ -> true in
9+
match Odoc_document.Url.from_identifier ~stop_before id with
1110
| Ok url ->
1211
let config =
1312
Odoc_html.Config.v ~search_result:true ~semantic_uris:false

src/search/html.mli

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ type html = Html_types.div_content Tyxml.Html.elt
44

55
val of_entry : Entry.t -> html list
66

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

119
(** The below is intended for search engine that do not use the Json output but
1210
Odoc as a library. Most search engine will use their own representation

src/search/json_index/json_display.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Odoc_search
22

3-
let of_entry { Entry.id; doc = _; kind = _ } h =
4-
match Html.url id with
3+
let of_entry entry h =
4+
match Html.url entry with
55
| Result.Ok url ->
66
let html =
77
h

test/search/html_search.t/run.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ The index file, one entry per line:
108108
{"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>"}}
109109
{"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>"}}
110110
{"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>"}}
111-
{"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>"}}
112-
{"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>"}}
113-
{"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>"}}
111+
{"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>"}}
112+
{"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>"}}
113+
{"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>"}}
114114
{"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>"}}
115115
{"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>"}}
116116
{"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>"}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
module X = struct
22
let x = 1
3+
4+
(** some comment *)
35
end
46

57
module Y = X
8+
module Z = Y
9+
10+
module L = Stdlib.List
11+
12+
module type X = sig
13+
val x : int
14+
end
15+
16+
module type Y = X
17+
module type Z = Y
18+
19+
module type L = module type of Stdlib.List

test/search/module_aliases.t/run.t

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ Compile and link the documentation
88
$ odoc link main.odoc
99
$ odoc compile-index main.odocl
1010

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

14-
$ cat index.json | jq | grep url |grep Y
15-
"url": "Main/Y/index.html",
16-
17-
$ odoc html-generate -o html main.odocl && ls Main/Y/index.html
18-
ls: cannot access 'Main/Y/index.html': No such file or directory
19-
[2]
14+
$ cat index.json | jq -r '.[] | "\(.id[-1].name) -> \(.display.url)"'
15+
Main -> Main/index.html
16+
X -> Main/index.html#module-X
17+
x -> Main/X/index.html#val-x
18+
X -> Main/X/index.html
19+
Y -> Main/index.html#module-Y
20+
Z -> Main/index.html#module-Z
21+
L -> Main/index.html#module-L
22+
X -> Main/index.html#module-type-X
23+
x -> Main/module-type-X/index.html#val-x
24+
Y -> Main/index.html#module-type-Y
25+
Z -> Main/index.html#module-type-Z
26+
L -> Main/index.html#module-type-L

0 commit comments

Comments
 (0)