Skip to content

Commit df9a7e3

Browse files
panglesdjonludlam
andcommitted
Docs breadcrumbs: use the one computed by odoc without processing
Co-authored-by: Jon Ludlam <[email protected]>
1 parent 57f0d6d commit df9a7e3

File tree

3 files changed

+32
-78
lines changed

3 files changed

+32
-78
lines changed

src/ocamlorg_frontend/components/package_breadcrumbs.eml

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ type path_item =
1111
| ClassType of breadcrumb
1212
| Page of breadcrumb
1313

14-
type docs_path =
15-
| Index
16-
| Page of string
17-
| Library of string * path_item list
18-
1914
let kind_tag (m : path_item) = match m with
2015
| Module _ ->
2116
<span tabindex="0" aria-label="module" class="breadcrumbs-tag module-tag">Module</span>
@@ -32,7 +27,7 @@ let kind_tag (m : path_item) = match m with
3227

3328
type path =
3429
| Overview of string option
35-
| Documentation of (docs_path)
30+
| Documentation of path_item list
3631

3732
let render_package_and_version
3833
~path
@@ -73,7 +68,6 @@ let path_item_to_breadcrumb = function
7368
let is_page : path_item -> bool = function Page _ -> true | _ -> false
7469

7570
let render_path_breadcrumbs
76-
~library_name
7771
~(path: path_item list) =
7872
let pages, modules = List.partition is_page path in
7973
let render_breadcrumb max i b =
@@ -87,11 +81,6 @@ let render_path_breadcrumbs
8781
| Some href ->
8882
<a href="<%s! href %>" aria-current="page" class="text-content dark:text-dark-title mr-2"><%s b.name %></a>
8983
in
90-
let library_name =
91-
<li>
92-
<span tabindex="0" class="text-content dark:text-dark-content"><%s library_name %> lib</span>
93-
</li>
94-
in
9584
let li content =
9685
<li class="flex flex-wrap items-center">
9786
<%s! content %>
@@ -103,31 +92,17 @@ let render_path_breadcrumbs
10392
<%s! String.concat "<span>.</span>" (List.mapi (render_breadcrumb (List.length modules - 1)) (List.map path_item_to_breadcrumb modules)) %>
10493
in
10594
let last = kind_tag (List.hd (List.rev path)) in
106-
library_name ^
10795
if List.length modules > 0 then
10896
page_items ^ li (ms ^ last)
10997
else
11098
page_items
11199

112100
let render_docs_path_breadcrumbs
113-
~(path: docs_path)
114-
(package: Package.package)
101+
~(path: path_item list)
115102
=
116-
let version = Package.url_version package in
117103
<nav aria-label="breadcrumb" class="flex mb-6 border-b pb-6">
118104
<ul class="flex flex-wrap gap-x-2 text-base leading-7 package-breadcrumbs">
119-
<li>
120-
<a class="underline font-semibold text-content dark:text-dark-title hover:text-primary dark:hover:text-dark-primary" href="<%s! Url.Package.documentation package.name ?version %>">Documentation</a>
121-
</li>
122-
<% (match path with
123-
| Index -> %>
124-
<% | Library (library_name, library_path) -> %>
125-
<%s! if library_path != [] then render_path_breadcrumbs ~library_name ~path:library_path else "ERROR: library path is []" %>
126-
<% | Page page_name -> %>
127-
<li>
128-
<span><%s page_name %></span>
129-
</li>
130-
<% ); %>
105+
<%s! if path != [] then render_path_breadcrumbs ~path else "ERROR: library path is []" %>
131106
</ul>
132107
</nav>
133108

@@ -145,8 +120,7 @@ let render_overview_breadcrumbs
145120

146121
let render
147122
~(path: path)
148-
(package: Package.package)
149123
=
150124
match path with
151125
| Overview page -> render_overview_breadcrumbs page
152-
| Documentation (docs_path) -> render_docs_path_breadcrumbs ~path:docs_path package
126+
| Documentation (docs_path) -> render_docs_path_breadcrumbs ~path:docs_path

src/ocamlorg_frontend/pages/package_documentation.eml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ let render
3434
let str_path =
3535
match path with
3636
| Overview _ -> []
37-
| Documentation (docs_path) -> (match docs_path with
38-
| Package_breadcrumbs.Index -> []
39-
| Library (s, p) -> s :: List.map (function
40-
| Package_breadcrumbs.Module { name ; _ } -> name
41-
| ModuleType { name ; _ } -> name
42-
| Parameter ({ name ; _ }, _) -> name
43-
| Class { name ; _ } -> name
44-
| ClassType { name ; _ } -> name
45-
| Page { name; _ } -> name
46-
) p
47-
| Page s -> [""; s])
37+
| Documentation (docs_path) ->
38+
List.map (function
39+
| Package_breadcrumbs.Module { name ; _ }
40+
| ModuleType { name ; _ }
41+
| Parameter ({ name ; _ }, _)
42+
| Class { name ; _ }
43+
| ClassType { name ; _ }
44+
| Page { name; _ } -> name
45+
) docs_path |> List.tl
4846
in
4947
Package_layout.render
5048
~title:(Printf.sprintf "%s %s · OCaml Package" package.name (Package.render_version package))
@@ -58,7 +56,7 @@ Package_layout.render
5856
~left_sidebar_html:(sidebar ~str_path ~local_toc ~global_toc package)
5957
~right_sidebar_html:(right_sidebar ~local_toc) @@
6058
<div id="htmx-content">
61-
<%s! Package_breadcrumbs.render ~path package %>
59+
<%s! Package_breadcrumbs.render ~path %>
6260
<div class="odoc prose dark:prose-invert prose-orange">
6361
<%s! content %>
6462
</div>

src/ocamlorg_web/lib/handler.ml

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ let package_documentation t kind req =
12361236
Dream.html ~code:404
12371237
(Ocamlorg_frontend.package_documentation_not_found ~page:path
12381238
~search_index_digest:None
1239-
~path:(Ocamlorg_frontend.Package_breadcrumbs.Documentation Index)
1239+
~path:(Ocamlorg_frontend.Package_breadcrumbs.Documentation [])
12401240
frontend_package)
12411241
in
12421242
if version_from_url = "latest" then
@@ -1287,43 +1287,25 @@ let package_documentation t kind req =
12871287
in
12881288
let (breadcrumb_path : Ocamlorg_frontend.Package_breadcrumbs.path) =
12891289
let breadcrumbs = doc.breadcrumbs in
1290-
if breadcrumbs != [] then
1291-
let first_path_item = List.hd breadcrumbs in
1292-
let doc_breadcrumb_to_library_path_item
1293-
(p : Ocamlorg_package.Documentation.breadcrumb) =
1294-
let breadcrumb : Ocamlorg_frontend.Package_breadcrumbs.breadcrumb =
1295-
{ name = p.name; href = p.href }
1296-
in
1297-
match p.kind with
1298-
| Module -> Ocamlorg_frontend.Package_breadcrumbs.Module breadcrumb
1299-
| ModuleType -> ModuleType breadcrumb
1300-
| Parameter number -> Parameter (breadcrumb, number)
1301-
| Class -> Class breadcrumb
1302-
| ClassType -> ClassType breadcrumb
1303-
| Page | LeafPage | File ->
1304-
failwith "library paths do not contain Page, LeafPage or File"
1290+
let doc_breadcrumb_to_library_path_item
1291+
(p : Ocamlorg_package.Documentation.breadcrumb) =
1292+
let b =
1293+
{
1294+
Ocamlorg_frontend.Package_breadcrumbs.name = p.name;
1295+
href = p.href;
1296+
}
13051297
in
1298+
match p.kind with
1299+
| Module -> Ocamlorg_frontend.Package_breadcrumbs.Module b
1300+
| ModuleType -> ModuleType b
1301+
| Parameter i -> Parameter (b, i)
1302+
| Class -> Class b
1303+
| ClassType -> ClassType b
1304+
| Page | LeafPage | File -> Page b
1305+
in
13061306

1307-
match first_path_item.kind with
1308-
| Page | LeafPage | File ->
1309-
Ocamlorg_frontend.Package_breadcrumbs.Documentation
1310-
(Page first_path_item.name)
1311-
| Module | ModuleType | Parameter _ | Class | ClassType ->
1312-
let library =
1313-
List.find_opt
1314-
(fun (toc : Ocamlorg_frontend.Navmap.toc) ->
1315-
List.exists
1316-
(fun (t : Ocamlorg_frontend.Navmap.toc) ->
1317-
t.title = first_path_item.name)
1318-
toc.children)
1319-
global_toc
1320-
in
1321-
1322-
Ocamlorg_frontend.Package_breadcrumbs.Documentation
1323-
(Library
1324-
( (match library with Some l -> l.title | None -> "unknown"),
1325-
List.map doc_breadcrumb_to_library_path_item breadcrumbs ))
1326-
else Ocamlorg_frontend.Package_breadcrumbs.Documentation Index
1307+
Ocamlorg_frontend.Package_breadcrumbs.Documentation
1308+
(List.map doc_breadcrumb_to_library_path_item breadcrumbs)
13271309
in
13281310
Dream.html
13291311
(Ocamlorg_frontend.package_documentation ~page:(Some path)

0 commit comments

Comments
 (0)