ocaml
0
fork

Configure Feed

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

implanting foreign forests

+41 -37
+10 -10
bin/forester/main.ml
··· 22 22 let config = Forester_frontend.Config.parse_forest_config_file config_filename in 23 23 let tree_dirs = paths_of_dirs ~env config.trees in 24 24 let asset_dirs = paths_of_dirs ~env config.assets in 25 - let foreign_dirs = paths_of_dirs ~env config.foreign in 26 - Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev ~tree_dirs ~asset_dirs ~foreign_dirs; 25 + let foreign_paths = paths_of_dirs ~env config.foreign in 26 + Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev ~tree_dirs ~asset_dirs ~foreign_paths; 27 27 Forester.render_forest ~env ~dev ~host: config.host ~home: config.home; 28 28 let dirs_to_copy = 29 29 (if not no_theme then [config.theme] else []) @ ··· 36 36 let config = Forester_frontend.Config.parse_forest_config_file config_filename in 37 37 let tree_dirs = paths_of_dirs ~env config.trees in 38 38 let asset_dirs = paths_of_dirs ~env config.assets in 39 - let foreign_dirs = paths_of_dirs ~env config.foreign in 40 - Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev: false ~tree_dirs ~asset_dirs ~foreign_dirs; 39 + let foreign_paths = paths_of_dirs ~env config.foreign in 40 + Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev: false ~tree_dirs ~asset_dirs ~foreign_paths; 41 41 let host = config.host in 42 42 Forester.export ~env ~host 43 43 ··· 46 46 let config = Forester_frontend.Config.parse_forest_config_file config_filename in 47 47 let tree_dirs = paths_of_dirs ~env config.trees in 48 48 let asset_dirs = paths_of_dirs ~env config.assets in 49 - let foreign_dirs = paths_of_dirs ~env config.foreign in 50 - Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev: true ~tree_dirs ~asset_dirs ~foreign_dirs; 49 + let foreign_paths = paths_of_dirs ~env config.foreign in 50 + Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev: true ~tree_dirs ~asset_dirs ~foreign_paths; 51 51 let mode = if random then `Random else `Sequential in 52 52 let dest = path_of_dir ~env dest_dir in 53 53 let addr = Forester.create_tree ~env ~dest ~prefix ~template ~mode in ··· 58 58 let config = Forester_frontend.Config.parse_forest_config_file config_filename in 59 59 let tree_dirs = paths_of_dirs ~env config.trees in 60 60 let asset_dirs = paths_of_dirs ~env config.assets in 61 - let foreign_dirs = paths_of_dirs ~env config.foreign in 62 - Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev: true ~tree_dirs ~asset_dirs ~foreign_dirs; 61 + let foreign_paths = paths_of_dirs ~env config.foreign in 62 + Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev: true ~tree_dirs ~asset_dirs ~foreign_paths; 63 63 let@ iri, title = Seq.iter @~ Forester.complete ~host: config.host title in 64 64 Format.printf "%a, %s\n" pp_iri iri title 65 65 ··· 68 68 let config = Forester_frontend.Config.parse_forest_config_file config_filename in 69 69 let tree_dirs = paths_of_dirs ~env config.trees in 70 70 let asset_dirs = paths_of_dirs ~env config.assets in 71 - let foreign_dirs = paths_of_dirs ~env config.foreign in 72 - Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev: true ~tree_dirs ~asset_dirs ~foreign_dirs; 71 + let foreign_paths = paths_of_dirs ~env config.foreign in 72 + Forester.plant_raw_forest_from_dirs ~env ~host: config.host ~dev: true ~tree_dirs ~asset_dirs ~foreign_paths; 73 73 Forester.json_manifest ~host: config.host ~home: config.home ~dev: true |> Format.printf "%s" 74 74 75 75 let default_config_str =
+1 -1
lib/core/Base.ml
··· 1 1 type iri = Iri.t 2 2 3 - let iri_t = Repr.map Repr.string Iri.of_string (Iri.to_string ~pctencode: false) 3 + let iri_t = Repr.map Repr.string (Iri.of_string ~pctdecode: true) (Iri.to_string ~pctencode: true) 4 4 5 5 let pp_iri (fmt : Format.formatter) (iri : Iri.t) = 6 6 Format.fprintf fmt "%s" @@
+2
lib/core/Reporter.ml
··· 18 18 | Profiling 19 19 | External_error 20 20 | Resource_not_found 21 + | IO_error 21 22 | Log 22 23 [@@deriving show] 23 24 ··· 41 42 | External_error -> Error 42 43 | Log -> Info 43 44 | Resource_not_found -> Error 45 + | IO_error -> Error 44 46 45 47 let short_code : t -> string = 46 48 show
+3
lib/core/Xml_tree.ml
··· 91 91 | Asset of asset 92 92 [@@deriving show, repr] 93 93 94 + type 'content forest = 'content resource list 95 + [@@deriving show, repr] 96 + 94 97 type 'content content_target = 95 98 | Full of section_flags 96 99 | Mainmatter
-1
lib/forest/Forester_forest.ml
··· 5 5 module Plain_text_client = Plain_text_client 6 6 7 7 module Json_manifest_client = Json_manifest_client 8 - module Json_client = Json_client
-11
lib/forest/Json_client.ml
··· 1 - open Forester_core 2 - module T = Xml_tree 3 - 4 - type t = { 5 - host: string; 6 - resources: T.content T.resource list; 7 - } 8 - [@@deriving repr] 9 - 10 - let render ~host resources = 11 - Repr.to_json_string t { host; resources }
-6
lib/forest/Json_client.mli
··· 1 - open Forester_core 2 - 3 - val render : 4 - host: string -> 5 - Xml_tree.content Xml_tree.resource list -> 6 - string
+1 -1
lib/forest/Legacy_xml_client.ml
··· 92 92 else 93 93 bare_route ^ suffix 94 94 else 95 - "foreign-" ^ host ^ bare_route ^ suffix 95 + "foreign-" ^ host ^ "-" ^ bare_route ^ suffix 96 96 end 97 97 98 98 let route iri =
+1 -1
lib/frontend/Config.ml
··· 58 58 get tbl (forest |-- key "trees" |-- array |-- strings) 59 59 in 60 60 let foreign = 61 - Option.value ~default: default_forest_config.trees @@ 61 + Option.value ~default: default_forest_config.foreign @@ 62 62 get tbl (forest |-- key "foreign" |-- array |-- strings) 63 63 in 64 64 let assets =
+1
lib/frontend/Config.mli
··· 7 7 foreign: string list; 8 8 theme: string; 9 9 } 10 + [@@deriving show] 10 11 end 11 12 12 13 val default_forest_config : Forest_config.t
+21 -5
lib/frontend/Forester.ml
··· 124 124 | exception exn -> 125 125 if ignore_malformed then None else raise exn 126 126 127 - let plant_raw_forest_from_dirs ~env ~host ~dev ~tree_dirs ~asset_dirs ~foreign_dirs : unit = 127 + let plant_raw_forest_from_dirs ~env ~host ~dev ~tree_dirs ~asset_dirs ~foreign_paths : unit = 128 + begin 129 + let@ path = List.iter @~ foreign_paths in 130 + let path_str = EP.native_exn path in 131 + let@ () = Reporter.profile @@ Format.sprintf "Implant foreign forest from `%s'" path_str in 132 + let blob = try EP.load path with _ -> Reporter.fatalf IO_error "Could not read foreign forest blob at `%s`" path_str in 133 + match Repr.of_json_string (T.forest_t T.content_t) blob with 134 + | Ok forest -> 135 + List.iter F.plant_resource forest 136 + | Error (`Msg err) -> 137 + Reporter.fatalf Parse_error "Could not parse foreign forest blob: %s" err 138 + | exception (Iri.Error err) -> 139 + Reporter.fatalf Parse_error "Encountered error while decoding foreign forest blob: %s" (Iri.string_of_error err) 140 + | exception exn -> 141 + Reporter.fatalf Parse_error "Encountered unknown error while decoding foreign forest blob: %s" (Printexc.to_string exn) 142 + end; 128 143 let parsed_trees = parse_trees_in_dirs ~dev tree_dirs in 129 144 begin 130 145 let@ () = Reporter.profile "Read assets" in ··· 142 157 F.plant_resource @@ T.Article article 143 158 end; 144 159 begin 145 - let@ _foreign_dir = List.iter @~ foreign_dirs in 160 + let@ _foreign_dir = List.iter @~ foreign_paths in 146 161 (* TODO: plant the trees & assets from the foreign directory *) 147 162 () 148 163 end ··· 202 217 | _ -> false 203 218 in 204 219 let cwd = Eio.Stdenv.cwd env in 205 - let result = Json_client.render ~host @@ List.of_seq local_resources in 206 - let dir = Eio.Path.(cwd / "export" / host) in 220 + let result = Repr.to_json_string ~minify: true (T.forest_t T.content_t) @@ List.of_seq local_resources in 221 + let dir = Eio.Path.(cwd / "export") in 222 + let filename = host ^ ".json" in 207 223 Eio.Path.mkdirs ~exists_ok: true ~perm: 0o755 dir; 208 - Eio.Path.save ~create: (`Or_truncate 0o644) Eio.Path.(dir / "forest.json") result 224 + Eio.Path.save ~create: (`Or_truncate 0o644) Eio.Path.(dir / filename) result
+1 -1
lib/frontend/Forester.mli
··· 9 9 dev: bool -> 10 10 tree_dirs: dir list -> 11 11 asset_dirs: dir list -> 12 - foreign_dirs: dir list -> 12 + foreign_paths: dir list -> 13 13 unit 14 14 15 15 val render_forest :