@@ -2,6 +2,17 @@ open Odoc_document
2
2
open Or_error
3
3
open Odoc_model
4
4
5
+ let prepare ~extra_suffix ~output_dir filename =
6
+ let filename =
7
+ match extra_suffix with
8
+ | Some s -> Fpath. add_ext s filename
9
+ | None -> filename
10
+ in
11
+ let filename = Fpath. normalize @@ Fs.File. append output_dir filename in
12
+ let directory = Fs.File. dirname filename in
13
+ Fs.Directory. mkdir_p directory;
14
+ filename
15
+
5
16
let document_of_odocl ~syntax input =
6
17
Odoc_file. load input >> = fun unit ->
7
18
match unit .content with
@@ -50,14 +61,7 @@ let render_document renderer ~sidebar ~output:root_dir ~extra_suffix ~extra doc
50
61
in
51
62
let pages = renderer.Renderer. render extra sidebar doc in
52
63
Renderer. traverse pages ~f: (fun filename content ->
53
- let filename =
54
- match extra_suffix with
55
- | Some s -> Fpath. add_ext s filename
56
- | None -> filename
57
- in
58
- let filename = Fpath. normalize @@ Fs.File. append root_dir filename in
59
- let directory = Fs.File. dirname filename in
60
- Fs.Directory. mkdir_p directory;
64
+ let filename = prepare ~extra_suffix ~output_dir: root_dir filename in
61
65
let oc = open_out (Fs.File. to_string filename) in
62
66
let fmt = Format. formatter_of_out_channel oc in
63
67
Format. fprintf fmt " %t@?" content;
@@ -121,13 +125,7 @@ let generate_asset_odoc ~warnings_options:_ ~renderer ~output ~asset_file
121
125
| Odoc_file. Asset_content unit ->
122
126
let url = Odoc_document.Url.Path. from_identifier unit .name in
123
127
let filename = renderer.Renderer. filepath extra url in
124
- let filename =
125
- match extra_suffix with
126
- | Some s -> Fpath. add_ext s filename
127
- | None -> filename
128
- in
129
-
130
- let dst = Fs.File. append output filename in
128
+ let dst = prepare ~extra_suffix ~output_dir: output filename in
131
129
Fs.File. copy ~src: asset_file ~dst
132
130
| Page_content _ | Unit_content _ | Impl_content _ ->
133
131
Error (`Msg " Expected an asset unit" )
0 commit comments