Handle Jekyll-format files in OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 67 lines 1.4 kB view raw view rendered
1# frontmatter - Parse YAML Frontmatter from Markdown 2 3An OCaml library for parsing YAML frontmatter (Jekyll-format) from Markdown files. Supports extracting structured metadata and body content from files with YAML headers delimited by `---` markers. 4 5## Key Features 6 7- Parse Jekyll-style YAML frontmatter from Markdown documents 8- Type-safe extraction of metadata fields using jsont codecs 9- Support for common frontmatter fields (title, date, tags, etc.) 10- Eio-based file I/O support via `frontmatter-eio` package 11 12## Usage 13 14```ocaml 15(* Parse frontmatter from a string *) 16let content = {|--- 17title: My Post 18date: 2025-01-15 19tags: 20 - ocaml 21 - tutorial 22--- 23 24# Hello World 25 26This is the body content. 27|} 28 29let () = 30 match Frontmatter.of_string content with 31 | Ok doc -> 32 let title = Frontmatter.get_string "title" doc in 33 let body = Frontmatter.body doc in 34 Printf.printf "Title: %s\nBody: %s\n" 35 (Option.value ~default:"untitled" title) 36 body 37 | Error e -> 38 Printf.eprintf "Parse error: %s\n" e 39``` 40 41With Eio file I/O: 42 43```ocaml 44let () = 45 Eio_main.run @@ fun env -> 46 let doc = Frontmatter_eio.read_file env#fs "posts/my-post.md" in 47 (* ... process document ... *) 48``` 49 50## Installation 51 52``` 53opam install frontmatter frontmatter-eio 54``` 55 56## Documentation 57 58API documentation is available via: 59 60``` 61opam install frontmatter 62odig doc frontmatter 63``` 64 65## License 66 67ISC