···77 | `Module | `Page | `LeafPage | `Class -> name
88 | _ -> Format.asprintf "%a-%s" Odoc_document.Url.Path.pp_kind kind name
991010-let as_filename (url : Url.Path.t) =
1010+let as_filename ?(add_ext = true) (url : Url.Path.t) =
1111 let components = Url.Path.to_list url in
1212 let dir, path =
1313 Url.Path.split
···1717 let dir = List.map segment_to_string dir in
1818 let path = String.concat "." (List.map segment_to_string path) in
1919 let str_path = String.concat Fpath.dir_sep (dir @ [ path ]) in
2020- Fpath.(v str_path + ".3o")
2020+ if add_ext then Fpath.(v str_path + ".3o") else Fpath.v str_path
21212222let rec is_class_or_module_path (url : Url.Path.t) =
2323 match url.kind with
+34-11
src/odoc/fs.ml
···21212222type file = Fpath.t
23232424+let mkdir_p dir =
2525+ let mkdir d =
2626+ try Unix.mkdir (Fpath.to_string d) 0o755 with
2727+ | Unix.Unix_error (Unix.EEXIST, _, _) -> ()
2828+ | exn -> raise exn
2929+ in
3030+ let rec dirs_to_create p acc =
3131+ if Sys.file_exists (Fpath.to_string p) then acc
3232+ else dirs_to_create (Fpath.parent p) (p :: acc)
3333+ in
3434+ List.iter (dirs_to_create dir []) ~f:mkdir
3535+2436module File = struct
2537 type t = file
2638···92104 Result.Error (`Msg err)
93105 with Sys_error e -> Result.Error (`Msg e)
94106107107+ let copy ~src ~dst =
108108+ let with_ open_ close filename f =
109109+ let c = open_ (Fpath.to_string filename) in
110110+ Odoc_utils.Fun.protect ~finally:(fun () -> close c) (fun () -> f c)
111111+ in
112112+ let with_ic = with_ open_in_bin close_in_noerr in
113113+ let with_oc = with_ open_out_bin close_out_noerr in
114114+ try
115115+ with_ic src (fun ic ->
116116+ mkdir_p (dirname dst);
117117+ with_oc dst (fun oc ->
118118+ let len = 1024 in
119119+ let buf = Bytes.create len in
120120+ let rec loop () =
121121+ let read = input ic buf 0 len in
122122+ output oc buf 0 read;
123123+ if read = len then loop ()
124124+ in
125125+ Ok (loop ())))
126126+ with Sys_error e -> Result.Error (`Msg e)
127127+95128 let exists file = Sys.file_exists (Fpath.to_string file)
9612997130 let rec of_segs_tl acc = function
···140173141174 let contains ~parentdir f = Fpath.is_rooted ~root:parentdir f
142175143143- let mkdir_p dir =
144144- let mkdir d =
145145- try Unix.mkdir (Fpath.to_string d) 0o755 with
146146- | Unix.Unix_error (Unix.EEXIST, _, _) -> ()
147147- | exn -> raise exn
148148- in
149149- let rec dirs_to_create p acc =
150150- if Sys.file_exists (Fpath.to_string p) then acc
151151- else dirs_to_create (Fpath.parent p) (p :: acc)
152152- in
153153- List.iter (dirs_to_create dir []) ~f:mkdir
176176+ let mkdir_p dir = mkdir_p dir
154177155178 let to_string = Fpath.to_string
156179
+2
src/odoc/fs.mli
···91919292 val read : t -> (string, [> msg ]) result
93939494+ val copy : src:t -> dst:t -> (unit, [> msg ]) result
9595+9496 val exists : t -> bool
95979698 val of_segs : string list -> t
···4242 match doc with
4343 | Odoc_document.Types.Document.Page { url; _ } -> url
4444 | Source_page { url; _ } -> url
4545- | Asset { url; _ } -> url
4645 in
4746 let sidebar =
4847 Odoc_utils.Option.map
···120119 Odoc_file.load file >>= fun unit ->
121120 match unit.content with
122121 | Odoc_file.Asset_content unit ->
123123- let doc = Renderer.document_of_asset asset_file unit in
124124- render_document renderer ~output ~sidebar:None ~extra_suffix ~extra doc;
125125- Ok ()
122122+ let url = Odoc_document.Url.Path.from_identifier unit.name in
123123+ let filename = renderer.Renderer.filepath extra url in
124124+ let filename =
125125+ match extra_suffix with
126126+ | Some s -> Fpath.add_ext s filename
127127+ | None -> filename
128128+ in
129129+130130+ let dst = Fs.File.append output filename in
131131+ Fs.File.copy ~src:asset_file ~dst
126132 | Page_content _ | Unit_content _ | Impl_content _ ->
127133 Error (`Msg "Expected an asset unit")
128134
+19
src/utils/odoc_utils.ml
···8080module Option = struct
8181 let map f = function None -> None | Some x -> Some (f x)
8282end
8383+8484+module Fun = struct
8585+ include Fun
8686+ let protect ~(finally : unit -> unit) work =
8787+ let finally_no_exn () =
8888+ try finally ()
8989+ with e ->
9090+ let bt = Printexc.get_raw_backtrace () in
9191+ Printexc.raise_with_backtrace (Finally_raised e) bt
9292+ in
9393+ match work () with
9494+ | result ->
9595+ finally_no_exn ();
9696+ result
9797+ | exception work_exn ->
9898+ let work_bt = Printexc.get_raw_backtrace () in
9999+ finally_no_exn ();
100100+ Printexc.raise_with_backtrace work_exn work_bt
101101+end