Source file support_files.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
open Odoc_utils
let should_include ~without_theme file =
if without_theme then
match file with
| "odoc.css" | "fonts/FiraMono-Regular.woff2"
| "fonts/FiraSans-Regular.woff2" | "fonts/NoticiaText-Regular.ttf" ->
false
| _ -> true
else true
let write ?(without_theme = false) output_directory =
let file name content =
let name = Fs.File.create ~directory:output_directory ~name in
let dir = Fs.File.dirname name in
Fs.Directory.mkdir_p dir;
let name = Fs.File.to_string name in
Io_utils.with_open_out name (fun oc -> output_string oc content)
in
let files = Odoc_html_support_files.file_list in
List.iter
(fun f ->
match Odoc_html_support_files.read f with
| Some content when should_include ~without_theme f -> file f content
| _ -> ())
files;
let extension_files = Odoc_extension_registry.list_support_files () in
List.iter
(fun (ext_file : Odoc_extension_registry.support_file) ->
match ext_file.content with
| Inline content -> file ext_file.filename content
| Copy_from src_path ->
let dst = Fs.File.create ~directory:output_directory ~name:ext_file.filename in
let dir = Fs.File.dirname dst in
Fs.Directory.mkdir_p dir;
let src = Fs.File.of_string src_path in
(match Fs.File.copy ~src ~dst with
| Ok () -> ()
| Error (`Msg msg) ->
Printf.eprintf "Warning: could not copy %s: %s\n" src_path msg))
extension_files
let print_filenames ?(without_theme = false) output_directory =
let files = Odoc_html_support_files.file_list in
List.iter
(fun f ->
match Odoc_html_support_files.read f with
| Some _ when should_include ~without_theme f ->
let name = Fs.File.create ~directory:output_directory ~name:f in
print_endline (Fs.File.to_string name)
| _ -> ())
files;
let extension_files = Odoc_extension_registry.list_support_files () in
List.iter
(fun (ext_file : Odoc_extension_registry.support_file) ->
let name = Fs.File.create ~directory:output_directory ~name:ext_file.filename in
print_endline (Fs.File.to_string name))
extension_files