diff --git a/src/model/frontmatter.ml b/src/model/frontmatter.ml new file mode 100644 index 0000000000..f50e98da1b --- /dev/null +++ b/src/model/frontmatter.ml @@ -0,0 +1 @@ +type t = (string * string) list diff --git a/src/model/lang.ml b/src/model/lang.ml index 7d9a5af913..06d5377291 100644 --- a/src/model/lang.ml +++ b/src/model/lang.ml @@ -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; diff --git a/src/model/root.ml b/src/model/root.ml index 34eb873b58..25587ef414 100644 --- a/src/model/root.ml +++ b/src/model/root.ml @@ -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 @@ -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 diff --git a/src/model/root.mli b/src/model/root.mli index 2fe2d4f2c1..79d55c33b7 100644 --- a/src/model/root.mli +++ b/src/model/root.mli @@ -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 @@ -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 diff --git a/src/model_desc/lang_desc.ml b/src/model_desc/lang_desc.ml index 810a23f8a7..084068f952 100644 --- a/src/model_desc/lang_desc.ml +++ b/src/model_desc/lang_desc.ml @@ -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); ] diff --git a/src/odoc/compile.ml b/src/odoc/compile.ml index 6501acf614..ad05059c31 100644 --- a/src/odoc/compile.ml +++ b/src/odoc/compile.ml @@ -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 = diff --git a/src/odoc/html_fragment.ml b/src/odoc/html_fragment.ml index e1c4b8bbe7..fe4fe9663d 100644 --- a/src/odoc/html_fragment.ml +++ b/src/odoc/html_fragment.ml @@ -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. { diff --git a/src/odoc/source_tree.ml b/src/odoc/source_tree.ml index 1278306849..9746403af1 100644 --- a/src/odoc/source_tree.ml +++ b/src/odoc/source_tree.ml @@ -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