Skip to content

Commit 63f57c5

Browse files
committed
Add frontmatter to page's root
This allows to load it without loading the whole content. Requires extracting the frontmatter types to avoid cyclic dependencies.
1 parent f40d773 commit 63f57c5

File tree

7 files changed

+27
-13
lines changed

7 files changed

+27
-13
lines changed

src/model/frontmatter.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type t = (string * string) list

src/model/lang.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,6 @@ end =
527527
module rec Page : sig
528528
type child = Page_child of string | Module_child of string
529529

530-
module Frontmatter : sig
531-
type t = (string * string) list
532-
end
533-
534530
type t = {
535531
name : Identifier.Page.t;
536532
root : Root.t;

src/model/root.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ end
2929
module Odoc_file = struct
3030
type compilation_unit = { name : string; hidden : bool }
3131

32-
type page = { name : string; title : Comment.link_content option }
32+
type page = {
33+
name : string;
34+
title : Comment.link_content option;
35+
frontmatter : Frontmatter.t option;
36+
}
3337

3438
type t =
3539
| Page of page
@@ -41,7 +45,7 @@ module Odoc_file = struct
4145
let hidden = force_hidden || Names.contains_double_underscore name in
4246
Compilation_unit { name; hidden }
4347

44-
let create_page name title = Page { name; title }
48+
let create_page name title frontmatter = Page { name; title; frontmatter }
4549

4650
let create_impl name = Impl name
4751

src/model/root.mli

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ end
2828
module Odoc_file : sig
2929
type compilation_unit = { name : string; hidden : bool }
3030

31-
type page = { name : string; title : Comment.link_content option }
31+
type page = {
32+
name : string;
33+
title : Comment.link_content option;
34+
frontmatter : Frontmatter.t option;
35+
}
3236

3337
type t =
3438
| Page of page
@@ -38,7 +42,8 @@ module Odoc_file : sig
3842

3943
val create_unit : force_hidden:bool -> string -> t
4044

41-
val create_page : string -> Comment.link_content option -> t
45+
val create_page :
46+
string -> Comment.link_content option -> Frontmatter.t option -> t
4247

4348
val create_impl : string -> t
4449

src/model_desc/lang_desc.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,10 @@ and page_t =
697697
[
698698
F ("name", (fun t -> t.name), identifier);
699699
F ("root", (fun t -> t.root), root);
700+
F
701+
( "frontmatter",
702+
(fun t -> t.frontmatter),
703+
Option (List (Pair (string, string))) );
700704
F ("content", (fun t -> t.content), docs);
701705
F ("digest", (fun t -> t.digest), Digest.t);
702706
]

src/odoc/compile.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ let mld ~parent_id ~parents_children ~output ~children ~warnings_options input =
240240
let zero_heading = Comment.find_zero_heading content in
241241
let frontmatter, content = Comment.extract_frontmatter content in
242242
let root =
243-
let file = Root.Odoc_file.create_page root_name zero_heading in
243+
let file =
244+
Root.Odoc_file.create_page root_name zero_heading frontmatter
245+
in
244246
{ Root.id = (name :> Paths.Identifier.OdocId.t); file; digest }
245247
in
246248
let page =

src/odoc/html_fragment.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ let from_mld ~xref_base_uri ~resolver ~output ~warnings_options input =
99
in
1010
let input_s = Fs.File.to_string input in
1111
let digest = Digest.file input_s in
12-
let root =
13-
let file = Odoc_model.Root.Odoc_file.create_page page_name None in
14-
{ Odoc_model.Root.id; file; digest }
15-
in
1612
let to_html content =
1713
(* This is a mess. *)
1814
let frontmatter, content = Odoc_model.Comment.extract_frontmatter content in
15+
let root =
16+
let file =
17+
Odoc_model.Root.Odoc_file.create_page page_name None frontmatter
18+
in
19+
{ Odoc_model.Root.id; file; digest }
20+
in
1921
let page =
2022
Odoc_model.Lang.Page.
2123
{

0 commit comments

Comments
 (0)