Skip to content

Commit

Permalink
Add frontmatter to page's root
Browse files Browse the repository at this point in the history
This allows to load it without loading the whole content. Requires extracting
the frontmatter types to avoid cyclic dependencies.
  • Loading branch information
panglesd committed Aug 19, 2024
1 parent 0f515dd commit 9dfe617
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/model/frontmatter.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type t = (string * string) list
4 changes: 0 additions & 4 deletions src/model/lang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,6 @@ module rec Page : sig
| Source_tree_child of string
| Asset_child of string

module Frontmatter : sig
type t = (string * string) list
end

type t = {
name : Identifier.Page.t;
root : Root.t;
Expand Down
8 changes: 6 additions & 2 deletions src/model/root.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ end
module Odoc_file = struct
type compilation_unit = { name : string; hidden : bool }

type page = { name : string; title : Comment.link_content option }
type page = {
name : string;
title : Comment.link_content option;
frontmatter : Frontmatter.t option;
}

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

let create_page name title = Page { name; title }
let create_page name title frontmatter = Page { name; title; frontmatter }

let create_impl name = Impl name

Expand Down
9 changes: 7 additions & 2 deletions src/model/root.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ end
module Odoc_file : sig
type compilation_unit = { name : string; hidden : bool }

type page = { name : string; title : Comment.link_content option }
type page = {
name : string;
title : Comment.link_content option;
frontmatter : Frontmatter.t option;
}

type t =
| Page of page
Expand All @@ -38,7 +42,8 @@ module Odoc_file : sig

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

val create_page : string -> Comment.link_content option -> t
val create_page :
string -> Comment.link_content option -> Frontmatter.t option -> t

val create_impl : string -> t

Expand Down
4 changes: 4 additions & 0 deletions src/model_desc/lang_desc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,10 @@ and page_t =
[
F ("name", (fun t -> t.name), identifier);
F ("root", (fun t -> t.root), root);
F
( "frontmatter",
(fun t -> t.frontmatter),
Option (List (Pair (string, string))) );
F ("content", (fun t -> t.content), docs);
F ("digest", (fun t -> t.digest), Digest.t);
]
Expand Down
4 changes: 3 additions & 1 deletion src/odoc/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ let mld ~parent_id ~parents_children ~output ~children ~warnings_options input =
let zero_heading = Comment.find_zero_heading content in
let frontmatter, content = Comment.extract_frontmatter content in
let root =
let file = Root.Odoc_file.create_page root_name zero_heading in
let file =
Root.Odoc_file.create_page root_name zero_heading frontmatter
in
{ Root.id = (name :> Paths.Identifier.OdocId.t); file; digest }
in
let page =
Expand Down
10 changes: 6 additions & 4 deletions src/odoc/html_fragment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ let from_mld ~xref_base_uri ~resolver ~output ~warnings_options input =
in
let input_s = Fs.File.to_string input in
let digest = Digest.file input_s in
let root =
let file = Odoc_model.Root.Odoc_file.create_page page_name None in
{ Odoc_model.Root.id; file; digest }
in
let to_html content =
(* This is a mess. *)
let frontmatter, content = Odoc_model.Comment.extract_frontmatter content in
let root =
let file =
Odoc_model.Root.Odoc_file.create_page page_name None frontmatter
in
{ Odoc_model.Root.id; file; digest }
in
let page =
Odoc_model.Lang.Page.
{
Expand Down
2 changes: 1 addition & 1 deletion src/odoc/source_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let compile ~resolver ~parent ~output ~warnings_options:_ input =
check_is_child_of_parent siblings root_name >>= fun () ->
parse_input_file input >>= fun (digest, source_tree) ->
let root =
let file = Root.Odoc_file.create_page root_name None in
let file = Root.Odoc_file.create_page root_name None None in
{ Root.id = (id :> Id.OdocId.t); file; digest }
in
let source_children = List.rev_map (source_child_id id) source_tree in
Expand Down

0 comments on commit 9dfe617

Please sign in to comment.