Skip to content

Commit

Permalink
WIP cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileTrotignon committed Aug 31, 2023
1 parent d766f62 commit e70a34b
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 143 deletions.
2 changes: 1 addition & 1 deletion src/document/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ module Make (Syntax : SYNTAX) = struct
Utils.filter_map
(function
| `Resolved (`Identifier id) ->
Some Url.(from_path @@ Path.from_identifier id)
Some (Url.from_path @@ Url.Path.from_identifier id)
| _ -> None)
t.search_assets
in
Expand Down
15 changes: 12 additions & 3 deletions src/html/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ let mk_anchor_link id =
let mk_anchor config anchor =
match anchor with
| None -> ([], [], [])
| _ when Config.search_result config -> ([], [], [])
| _ when Config.search_result config ->
(* When displaying for a search result, anchor are not added as it would
make no sense to add them. *)
([], [], [])
| Some { Url.Anchor.anchor; _ } ->
let link = mk_anchor_link anchor in
let extra_attr = [ Html.a_id anchor ] in
Expand Down Expand Up @@ -101,7 +104,10 @@ let rec internallink ~config ~emph_level ~resolve ?(a = [])
| Resolved uri ->
let href = Link.href ~config ~resolve uri in
let content = inline_nolink ~emph_level content in
if Config.search_result config then Html.span ~a content
if Config.search_result config then
(* When displaying for a search result, links are displayed as regular
text. *)
Html.span ~a content
else
let a =
Html.a_href href :: (a :> Html_types.a_attrib Html.attrib list)
Expand Down Expand Up @@ -172,7 +178,10 @@ and inline_nolink ?(emph_level = 0) (l : Inline.t) :
let heading ~config ~resolve (h : Heading.t) =
let a, anchor =
match h.label with
| Some _ when Config.search_result config -> ([], [])
| Some _ when Config.search_result config ->
(* When displaying for a search result, anchor are not added as it would
make no sense to add them. *)
([], [])
| Some id -> ([ Html.a_id id ], mk_anchor_link id)
| None -> ([], [])
in
Expand Down
21 changes: 10 additions & 11 deletions src/html_support_files/odoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ a:hover {

*:hover > a.anchor {
visibility: visible;
z-index: -1;
}

a.anchor:before {
Expand Down Expand Up @@ -554,14 +553,7 @@ div.odoc-spec,.odoc-include {
margin-bottom: 2em;
}

.odoc-include {
/* Otherwise it will appear above search results */
z-index: -1;
position: relative;
}

.spec.type .variant p,
.spec.type .record p {
.spec.type .variant p, .spec.type .record p {
margin: 5px;
}

Expand Down Expand Up @@ -793,6 +785,7 @@ td.def-doc *:first-child {
background: var(--main-background);
width: 100%;
padding-top: 1rem;
z-index: 1;
}


Expand All @@ -804,6 +797,8 @@ td.def-doc *:first-child {
}

.odoc-search:focus-within .search-inner {
/* Search inner is bigger than its parent, but the overflow needs to be
centered. */
left: 50%;
transform: translateX(-50%);
width: 110%;
Expand All @@ -812,7 +807,7 @@ td.def-doc *:first-child {
.odoc-search .search-bar {
position: relative;
z-index: 2;
font-size: 1;
font-size: 1em;
transition: font-size 0.3s;
}

Expand All @@ -834,7 +829,6 @@ td.def-doc *:first-child {
position: absolute;
left: 0;
right: 0;
z-index: 1;
}

.odoc-search .search-result-inner {
Expand All @@ -849,12 +843,17 @@ td.def-doc *:first-child {
}

.search-bar {
/* inputs are of fixed size by default, even if you display:block them */
width: 100%;
}

.odoc-search .search-entry {
color: var(--color);
display: grid;
/* This constant of 59px was carefully chosen to accomodate every possible
"kind". We cannot ask CSS to compute it because not every kind will be
present in every search result list, and we do not want the size of the
column to change with different results. */
grid-template-columns: [kinds] 59px [titles] 1fr;
flex-wrap: nowrap;
flex-direction: row;
Expand Down
4 changes: 3 additions & 1 deletion src/model/fold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ and module_type ~f acc mt =
and simple_expansion ~f acc s_e =
match s_e with
| Signature sg -> signature ~f acc sg
| Functor (_, s_e) -> simple_expansion ~f acc s_e
| Functor (p, s_e) ->
let acc = functor_parameter ~f acc p in
simple_expansion ~f acc s_e

and module_type_expr ~f acc mte =
match mte with
Expand Down
6 changes: 5 additions & 1 deletion src/model/fold.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(** This module allows to fold over odoc values. It is notably used to construct
a search database of every relevant item. *)
a search database of every relevant item. It appear to be very generic but
in reality it is quite specialized to fold over searchable items, and not
every kind of odoc value you could fold over.*)

open Lang

Expand All @@ -22,6 +24,8 @@ type item =

val unit : f:('a -> item -> 'a) -> 'a -> Compilation_unit.t -> 'a
val page : f:('a -> item -> 'a) -> 'a -> Page.t -> 'a


val signature : f:('a -> item -> 'a) -> 'a -> Signature.t -> 'a
val signature_item : f:('a -> item -> 'a) -> 'a -> Signature.item -> 'a
val docs : f:('a -> item -> 'a) -> 'a -> Comment.docs_or_stop -> 'a
Expand Down
6 changes: 3 additions & 3 deletions src/odoc/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ module Indexing = struct
| Some file -> Fs.File.of_string file
| None -> Fs.File.of_string "index.json"

let index directories dst warnings_options =
let index directories dst =
let output = output_file ~dst in
Indexing.compile ~output ~warnings_options ~resolver:() ~parent:()
Indexing.compile ~output
directories

let cmd =
Expand All @@ -401,7 +401,7 @@ module Indexing = struct
in
Term.(
const handle_error
$ (const index $ odoc_file_directories $ dst $ warnings_options))
$ (const index $ odoc_file_directories $ dst ))

let info ~docs =
let doc =
Expand Down
6 changes: 3 additions & 3 deletions src/odoc/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ let compile ~resolver ~parent_cli_spec ~hidden ~children ~output
parent resolver parent_cli_spec >>= fun parent_spec ->
let search_assets : Paths.Reference.Asset.t list =
List.map (fun a -> `Root (a, `TAsset)) search_assets
(* Assets references are considered as "simple" reference, no way to specify
the parent page of an asset. Therefore, seach assets need to be children
of a page ancestor. *)
(* Assets references are considered as "simple" reference, there is no way
to specify the parent page of an asset. Therefore, search assets need to
be children of a page ancestor. *)
in
let ext = Fs.File.get_ext input in
if ext = ".mld" then
Expand Down
2 changes: 1 addition & 1 deletion src/odoc/indexing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let fold_dirs ~dirs ~unit ~page ~init =
acc dir)
(Ok init)

let compile ~resolver:_ ~parent:_ ~output ~warnings_options:_ dirs =
let compile ~output dirs =
let output_channel =
Fs.Directory.mkdir_p (Fs.File.dirname output);
open_out_bin (Fs.File.to_string output)
Expand Down
3 changes: 0 additions & 3 deletions src/odoc/indexing.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ val handle_file :
to generate their search index *)

val compile :
resolver:'a ->
parent:'b ->
output:Fs.file ->
warnings_options:Odoc_model.Error.warnings_options ->
Fs.directory list ->
(unit, [> msg ]) result
6 changes: 3 additions & 3 deletions src/odoc/support_files.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
location. *)

val write : ?without_theme:bool -> Fs.Directory.t -> unit
(** [write ?without_theme search_files output_dir] copies the support and search
files to the [output_dir]. If [without_theme] is [true] the theme will {e
not} be copied, the default value is [false]. *)
(** [write ?without_theme output_dir] copies the support files to the
[output_dir]. If [without_theme] is [true] the theme will {e not} be
copied, the default value is [false]. *)

val print_filenames : ?without_theme:bool -> Fs.Directory.t -> unit
(** Prints, to STDOUT, the names of the files that calling [Support_files.write]
Expand Down
2 changes: 0 additions & 2 deletions src/search/entry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ type t = {
kind : kind;
}

type with_html = { entry : t; html : [ `Code | `Div ] Tyxml.Html.elt list }

let entry ~id ~doc ~kind =
let id = (id :> Odoc_model.Paths.Identifier.Any.t) in
{ id; kind; doc }
Expand Down
3 changes: 0 additions & 3 deletions src/search/entry.mli
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,5 @@ type t = {
kind : kind;
}

type with_html = { entry : t; html : [ `Code | `Div ] Tyxml.Html.elt list }
(** You can use {!Generator.with_html} to get a value of this type. *)

val entries_of_item :
Odoc_model.Paths.Identifier.Any.t -> Odoc_model.Fold.item -> t list
51 changes: 0 additions & 51 deletions src/search/generator.mli

This file was deleted.

Loading

0 comments on commit e70a34b

Please sign in to comment.