Skip to content

Commit

Permalink
Add a 'Home' link to breadcrumbs when no sidebar is given
Browse files Browse the repository at this point in the history
  • Loading branch information
panglesd authored and jonludlam committed Dec 10, 2024
1 parent e6aa530 commit a650013
Show file tree
Hide file tree
Showing 392 changed files with 715 additions and 256 deletions.
62 changes: 35 additions & 27 deletions src/html/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,19 @@ end

module Breadcrumbs = struct
open Types

let page_parent (page : Url.Path.t) =
let page =
match page with
| { parent = Some parent; name = "index"; kind = `LeafPage } -> parent
| _ -> page
in
match page with
| { parent = None; name = "index"; kind = `LeafPage } -> None
| { parent = Some parent; _ } -> Some parent
| { parent = None; _ } ->
Some { Url.Path.parent = None; name = "index"; kind = `LeafPage }

let gen_breadcrumbs_no_sidebar ~config ~url =
let url =
match url with
Expand Down Expand Up @@ -536,24 +549,31 @@ module Breadcrumbs = struct
in
match List.rev parent_paths with
| [] -> assert false
| [ current ] ->
let current =
{
href = None;
name = [ Html.txt current.name ];
kind = current.kind;
}
in
{ parents = []; up_url = None; current }
| current :: (up :: _ as parents) ->
let current = to_breadcrumb current in
| current :: parents ->
let up_url =
Some
(Link.href ~config ~resolve:(Current url)
(Odoc_document.Url.from_path up))
match page_parent current with
| None -> None
| Some up ->
Some
(Link.href ~config ~resolve:(Current url)
(Odoc_document.Url.from_path up))
in
let current = to_breadcrumb current in
let parents = List.map to_breadcrumb parents |> List.rev in
{ current; parents; up_url })
let home =
let href =
Some
(Link.href ~config ~resolve:(Current url)
(Odoc_document.Url.from_path
{
Url.Path.name = "index";
parent = None;
kind = `LeafPage;
}))
in
{ href; name = [ Html.txt "🏠" ]; kind = `LeafPage }
in
{ current; parents = home :: parents; up_url })

let gen_breadcrumbs_with_sidebar ~config ~sidebar ~url:current_url =
let find_parent =
Expand Down Expand Up @@ -601,18 +621,6 @@ module Breadcrumbs = struct
{ Types.current; parents; up_url }
in
let escape =
let page_parent (page : Url.Path.t) =
let page =
match page with
| { parent = Some parent; name = "index"; kind = `LeafPage } -> parent
| _ -> page
in
match page with
| { parent = None; name = "index"; kind = `LeafPage } -> None
| { parent = Some parent; _ } -> Some parent
| { parent = None; _ } ->
Some { Url.Path.parent = None; name = "index"; kind = `LeafPage }
in
match (Config.escape_breadcrumb config, find_parent sidebar) with
| true, Some { node; _ } -> (
match page_parent node.url.page with
Expand Down
5 changes: 4 additions & 1 deletion src/odoc/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,10 @@ module Odoc_html_args = struct
end

let escape_breadcrumb =
let doc = "URL to use to escape from the breadcrumbs" in
let doc =
"Wether to add a 'Home' breadcrumb to go up the root of the given \
sidebar."
in
Arg.(value & flag & info ~docv:"escape" ~doc [ "escape-breadcrumb" ])

let theme_uri =
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Alerts-Top1.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Alerts.html">Up</a>
<a href="Alerts.html">Alerts</a> &#x00BB; Top1
<a href="index.html">🏠</a> &#x00BB; <a href="Alerts.html">Alerts</a>
&#x00BB; Top1
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Alerts.Top1</span></code></h1>
Expand Down
5 changes: 4 additions & 1 deletion test/generators/html/Alerts.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc"><nav class="odoc-nav">Alerts</nav>
<body class="odoc">
<nav class="odoc-nav"><a href="index.html">Up</a>
<a href="index.html">🏠</a> &#x00BB; Alerts
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Alerts</span></code></h1>
</header>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Alias-X.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Alias.html">Up</a>
<a href="Alias.html">Alias</a> &#x00BB; X
<a href="index.html">🏠</a> &#x00BB; <a href="Alias.html">Alias</a>
&#x00BB; X
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Alias.X</span></code></h1>
Expand Down
5 changes: 4 additions & 1 deletion test/generators/html/Alias.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc"><nav class="odoc-nav">Alias</nav>
<body class="odoc">
<nav class="odoc-nav"><a href="index.html">Up</a>
<a href="index.html">🏠</a> &#x00BB; Alias
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Alias</span></code></h1>
</header>
Expand Down
5 changes: 4 additions & 1 deletion test/generators/html/Bugs.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc"><nav class="odoc-nav">Bugs</nav>
<body class="odoc">
<nav class="odoc-nav"><a href="index.html">Up</a>
<a href="index.html">🏠</a> &#x00BB; Bugs
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Bugs</span></code></h1>
</header>
Expand Down
1 change: 1 addition & 0 deletions test/generators/html/Bugs_post_406-class-let_open'.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Bugs_post_406.html">Up</a>
<a href="index.html">🏠</a> &#x00BB;
<a href="Bugs_post_406.html">Bugs_post_406</a> &#x00BB; let_open'
</nav>
<header class="odoc-preamble">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Bugs_post_406.html">Up</a>
<a href="index.html">🏠</a> &#x00BB;
<a href="Bugs_post_406.html">Bugs_post_406</a> &#x00BB; let_open
</nav>
<header class="odoc-preamble">
Expand Down
5 changes: 4 additions & 1 deletion test/generators/html/Bugs_post_406.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc"><nav class="odoc-nav">Bugs_post_406</nav>
<body class="odoc">
<nav class="odoc-nav"><a href="index.html">Up</a>
<a href="index.html">🏠</a> &#x00BB; Bugs_post_406
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Bugs_post_406</span></code></h1>
<p>Let-open in class types, https://github.com/ocaml/odoc/issues/543
Expand Down
5 changes: 4 additions & 1 deletion test/generators/html/Bugs_pre_410.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc"><nav class="odoc-nav">Bugs_pre_410</nav>
<body class="odoc">
<nav class="odoc-nav"><a href="index.html">Up</a>
<a href="index.html">🏠</a> &#x00BB; Bugs_pre_410
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Bugs_pre_410</span></code></h1>
</header>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-empty_virtual'.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; empty_virtual'
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; empty_virtual'
</nav>
<header class="odoc-preamble">
<h1>Class <code><span>Class.empty_virtual'</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-mutually'.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; mutually'
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; mutually'
</nav>
<header class="odoc-preamble">
<h1>Class <code><span>Class.mutually'</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-polymorphic'.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; polymorphic'
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; polymorphic'
</nav>
<header class="odoc-preamble">
<h1>Class <code><span>Class.polymorphic'</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-recursive'.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; recursive'
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; recursive'
</nav>
<header class="odoc-preamble">
<h1>Class <code><span>Class.recursive'</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-type-empty.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; empty
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; empty
</nav>
<header class="odoc-preamble">
<h1>Class type <code><span>Class.empty</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-type-empty_virtual.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; empty_virtual
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; empty_virtual
</nav>
<header class="odoc-preamble">
<h1>Class type <code><span>Class.empty_virtual</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-type-mutually.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; mutually
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; mutually
</nav>
<header class="odoc-preamble">
<h1>Class type <code><span>Class.mutually</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-type-polymorphic.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; polymorphic
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; polymorphic
</nav>
<header class="odoc-preamble">
<h1>Class type <code><span>Class.polymorphic</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Class-class-type-recursive.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class.html">Up</a>
<a href="Class.html">Class</a> &#x00BB; recursive
<a href="index.html">🏠</a> &#x00BB; <a href="Class.html">Class</a>
&#x00BB; recursive
</nav>
<header class="odoc-preamble">
<h1>Class type <code><span>Class.recursive</span></code></h1>
Expand Down
5 changes: 4 additions & 1 deletion test/generators/html/Class.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc"><nav class="odoc-nav">Class</nav>
<body class="odoc">
<nav class="odoc-nav"><a href="index.html">Up</a>
<a href="index.html">🏠</a> &#x00BB; Class
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Class</span></code></h1>
</header>
Expand Down
1 change: 1 addition & 0 deletions test/generators/html/Class_comments-class-c.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class_comments.html">Up</a>
<a href="index.html">🏠</a> &#x00BB;
<a href="Class_comments.html">Class_comments</a> &#x00BB; c
</nav>
<header class="odoc-preamble">
Expand Down
1 change: 1 addition & 0 deletions test/generators/html/Class_comments-class-x.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Class_comments.html">Up</a>
<a href="index.html">🏠</a> &#x00BB;
<a href="Class_comments.html">Class_comments</a> &#x00BB; x
</nav>
<header class="odoc-preamble">
Expand Down
5 changes: 4 additions & 1 deletion test/generators/html/Class_comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc"><nav class="odoc-nav">Class_comments</nav>
<body class="odoc">
<nav class="odoc-nav"><a href="index.html">Up</a>
<a href="index.html">🏠</a> &#x00BB; Class_comments
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Class_comments</span></code></h1>
</header>
Expand Down
5 changes: 4 additions & 1 deletion test/generators/html/External.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="odoc"><nav class="odoc-nav">External</nav>
<body class="odoc">
<nav class="odoc-nav"><a href="index.html">Up</a>
<a href="index.html">🏠</a> &#x00BB; External
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>External</span></code></h1>
</header>
Expand Down
4 changes: 2 additions & 2 deletions test/generators/html/Functor-F1-argument-1-Arg.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Functor-F1.html">Up</a>
<a href="Functor.html">Functor</a> &#x00BB;
<a href="Functor-F1.html">F1</a> &#x00BB; Arg
<a href="index.html">🏠</a> &#x00BB; <a href="Functor.html">Functor</a>
&#x00BB; <a href="Functor-F1.html">F1</a> &#x00BB; Arg
</nav>
<header class="odoc-preamble">
<h1>Parameter <code><span>F1.Arg</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Functor-F1.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Functor.html">Up</a>
<a href="Functor.html">Functor</a> &#x00BB; F1
<a href="index.html">🏠</a> &#x00BB; <a href="Functor.html">Functor</a>
&#x00BB; F1
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Functor.F1</span></code></h1>
Expand Down
4 changes: 2 additions & 2 deletions test/generators/html/Functor-F2-argument-1-Arg.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Functor-F2.html">Up</a>
<a href="Functor.html">Functor</a> &#x00BB;
<a href="Functor-F2.html">F2</a> &#x00BB; Arg
<a href="index.html">🏠</a> &#x00BB; <a href="Functor.html">Functor</a>
&#x00BB; <a href="Functor-F2.html">F2</a> &#x00BB; Arg
</nav>
<header class="odoc-preamble">
<h1>Parameter <code><span>F2.Arg</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Functor-F2.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Functor.html">Up</a>
<a href="Functor.html">Functor</a> &#x00BB; F2
<a href="index.html">🏠</a> &#x00BB; <a href="Functor.html">Functor</a>
&#x00BB; F2
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Functor.F2</span></code></h1>
Expand Down
4 changes: 2 additions & 2 deletions test/generators/html/Functor-F3-argument-1-Arg.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Functor-F3.html">Up</a>
<a href="Functor.html">Functor</a> &#x00BB;
<a href="Functor-F3.html">F3</a> &#x00BB; Arg
<a href="index.html">🏠</a> &#x00BB; <a href="Functor.html">Functor</a>
&#x00BB; <a href="Functor-F3.html">F3</a> &#x00BB; Arg
</nav>
<header class="odoc-preamble">
<h1>Parameter <code><span>F3.Arg</span></code></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/generators/html/Functor-F3.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body class="odoc">
<nav class="odoc-nav"><a href="Functor.html">Up</a>
<a href="Functor.html">Functor</a> &#x00BB; F3
<a href="index.html">🏠</a> &#x00BB; <a href="Functor.html">Functor</a>
&#x00BB; F3
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Functor.F3</span></code></h1>
Expand Down
Loading

0 comments on commit a650013

Please sign in to comment.