Skip to content

Commit e6df934

Browse files
committed
Fix package files appearing in global toc
1 parent ec205f1 commit e6df934

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

src/ocamlorg_package/lib/documentation_status.ml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ let has_file (v : t) (options : string list) : string option =
1919
children
2020
with Not_found -> None
2121

22-
let license (v : t) = has_file v [ "LICENSE"; "LICENCE" ]
23-
let readme (v : t) = has_file v [ "README"; "Readme"; "readme" ]
22+
let license_names = [ "LICENSE"; "LICENCE" ]
23+
let readme_names = [ "README"; "Readme"; "readme" ]
2424

25-
let changelog (v : t) =
26-
has_file v
27-
[ "CHANGELOG"; "Changelog"; "changelog"; "CHANGES"; "Changes"; "changes" ]
25+
let changelog_names =
26+
[ "CHANGELOG"; "Changelog"; "changelog"; "CHANGES"; "Changes"; "changes" ]
27+
28+
let is_special =
29+
let names = license_names @ readme_names @ changelog_names in
30+
fun x -> List.mem x names
31+
32+
let license (v : t) = has_file v license_names
33+
let readme (v : t) = has_file v readme_names
34+
let changelog (v : t) = has_file v changelog_names

src/ocamlorg_package/lib/documentation_status.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ type t = {
1616
val readme : t -> string option
1717
val license : t -> string option
1818
val changelog : t -> string option
19+
val is_special : string -> bool

src/ocamlorg_web/lib/handler.ml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,8 @@ let package_documentation t kind req =
12821282
else response_404_page
12831283
| Some doc ->
12841284
let map_url = Option.map (fun url -> "/" ^ url) in
1285-
let rec navmap_of_sidebar (sidebar : Ocamlorg_package.Sidebar.tree) =
1285+
let rec navmap_of_sidebar ?(first_layer = false)
1286+
(sidebar : Ocamlorg_package.Sidebar.tree) =
12861287
Ocamlorg_frontend.Navmap.
12871288
{
12881289
title = sidebar.node.content;
@@ -1303,7 +1304,24 @@ let package_documentation t kind req =
13031304
| None -> Page
13041305
| _ -> File);
13051306
href = map_url sidebar.node.url;
1306-
children = List.map navmap_of_sidebar sidebar.children;
1307+
children =
1308+
(let children =
1309+
List.map
1310+
(navmap_of_sidebar ~first_layer:false)
1311+
sidebar.children
1312+
in
1313+
(* The docs CI generates readme files in the wring place, and
1314+
they end up in the toc, so we filter them out here *)
1315+
if first_layer then
1316+
List.filter
1317+
(function
1318+
| Ocamlorg_frontend.Navmap.{ title; _ }
1319+
when Ocamlorg_package.Documentation_status.is_special
1320+
title ->
1321+
false
1322+
| _ -> true)
1323+
children
1324+
else children);
13071325
}
13081326
in
13091327
let* sidebar = Ocamlorg_package.sidebar ~kind package in
@@ -1312,7 +1330,7 @@ let package_documentation t kind req =
13121330
in
13131331
let local_toc = Package_helper.frontend_toc doc.toc in
13141332
let (global_toc : Ocamlorg_frontend.Navmap.toc list) =
1315-
List.map navmap_of_sidebar sidebar
1333+
List.map (navmap_of_sidebar ~first_layer:true) sidebar
13161334
in
13171335
let (breadcrumb_path : Ocamlorg_frontend.Package_breadcrumbs.path) =
13181336
let breadcrumbs = doc.breadcrumbs in

0 commit comments

Comments
 (0)