diff --git a/lib/page.ml b/lib/page.ml index b1d8bc0..f9ecf8b 100644 --- a/lib/page.ml +++ b/lib/page.ml @@ -1,3 +1,12 @@ +let ( let* ) = Result.bind + module UserPage = struct type t = { frontmatter : Frontmatter.t; content : string } + + let of_string md = + let yaml, content = Frontmatter.extract_frontmatter md in + let* frontmatter = Frontmatter.parse_frontmatter yaml in + Ok { frontmatter; content } + + let of_file filepath = Eio.Path.load filepath |> of_string end diff --git a/lib/page.mli b/lib/page.mli new file mode 100644 index 0000000..24c795e --- /dev/null +++ b/lib/page.mli @@ -0,0 +1,6 @@ +module UserPage : sig + type t = { frontmatter : Frontmatter.t; content : string } + + val of_string : string -> (t, string) Result.t + val of_file : 'a Eio.Path.t -> (t, string) Result.t +end diff --git a/package.json b/package.json index e036aa2..51b216b 100644 --- a/package.json +++ b/package.json @@ -22,4 +22,4 @@ "@opam/ocaml-lsp-server": "1.21.0", "@opam/ocamlformat": "0.27.0" } -} \ No newline at end of file +}