diff --git a/bin/ring.ml b/bin/ring.ml index 872951c..782cf8e 100644 --- a/bin/ring.ml +++ b/bin/ring.ml @@ -3,7 +3,7 @@ let run_build target source log_level = let source = source let target = target end) in - Yocaml_eio.run ~level:log_level (Gem.Action.process_all (module Resolver)) + Yocaml_eio.run ~level:log_level (Gem.Action.All.run (module Resolver)) let run_watch target source log_level port = let module Resolver = Gem.Resolver.Make (struct @@ -11,7 +11,7 @@ let run_watch target source log_level port = let target = target end) in Yocaml_eio.serve ~target:Resolver.target ~level:log_level ~port - (Gem.Action.process_all (module Resolver)) + (Gem.Action.All.run (module Resolver)) open Cmdliner diff --git a/lib/action.ml b/lib/action.ml deleted file mode 100644 index f394af6..0000000 --- a/lib/action.ml +++ /dev/null @@ -1,106 +0,0 @@ -let process_css (module R : Sigs.RESOLVER) = - Yocaml.Action.batch ~only:`Files - ~where:(Yocaml.Path.has_extension "css") - R.Source.css - (Yocaml.Action.copy_file ~into:R.Target.css) - -let process_fonts (module R : Sigs.RESOLVER) = - Yocaml.Action.batch ~only:`Files R.Source.fonts - (Yocaml.Action.copy_file ~into:R.Target.fonts) - -let process_images (module R : Sigs.RESOLVER) cache = - cache - |> Yocaml.Action.batch ~only:`Files R.Source.static_images - (Yocaml.Action.copy_file ~into:R.Target.images) - -let init_chain (module R : Sigs.RESOLVER) = - let open Yocaml.Eff in - let* cache = Yocaml.Action.restore_cache ~on:`Target R.Target.cache in - let* chain = - Yocaml_yaml.Eff.read_file_as_metadata - (module Model.Chain.Metadata) - ~on:`Source R.Source.chain - in - let+ cache, members = - Yocaml.Action.fold ~only:`Files - ~where:(Yocaml.Path.has_extension "yml") - ~state:[] R.Source.members - (fun path state cache -> - let+ member = - Yocaml_yaml.Eff.read_file_as_metadata - (module Model.Member) - ~on:`Source path - in - (cache, member :: state)) - cache - in - (cache, Model.Chain.init ~chain ~members) - -let init_message (module R : Sigs.RESOLVER) = - Yocaml.Eff.logf ~level:`Debug "ring.muhokama [source: `%a`, target: `%a`]" - Yocaml.Path.pp R.source Yocaml.Path.pp R.target - -let final_message _cache = Yocaml.Eff.log ~level:`Debug "ring.muhokama done" - -let generate_opml (module R : Sigs.RESOLVER) chain = - Yocaml.Action.write_static_file R.Target.ring_opml - (let open Yocaml.Task in - R.track_common_dependencies - >>> Yocaml.Pipeline.track_file R.Source.members - >>> const chain - >>> Model.Chain.to_opml) - -let process_chain_member (module R : Sigs.RESOLVER) pred_or_succ current_member - target_member = - let target = - R.Target.member_redirection - ~id:(Model.Member.id current_member) - pred_or_succ - in - Yocaml.Action.write_static_file target - (let open Yocaml.Task in - R.track_common_dependencies - >>> const target_member - >>> empty_body () - >>> Yocaml_jingoo.Pipeline.as_template - (module Model.Member) - (R.Source.template "redirect.html") - >>> drop_first ()) - -let process_chain (module R : Sigs.RESOLVER) chain = - let process_chain_member = process_chain_member (module R) in - Yocaml.Action.batch_list (Model.Chain.to_list chain) - (fun (curr, (pred, succ)) cache -> - let open Yocaml.Eff in - cache - |> process_chain_member `Pred curr pred - >>= process_chain_member `Succ curr succ) - -let process_index (module R : Sigs.RESOLVER) _chain = - Yocaml.Action.write_static_file R.Target.index - (let open Yocaml.Task in - R.track_common_dependencies - >>> Yocaml.Pipeline.track_file R.Source.members - >>> Yocaml_yaml.Pipeline.read_file_with_metadata - (module Model.Page) - R.Source.index - >>> Yocaml_omd.content_to_html () - >>> Yocaml_jingoo.Pipeline.as_template - (module Model.Page) - (R.Source.template "layout.html") - >>> drop_first ()) - -let process_all (module R : Sigs.RESOLVER) () = - let open Yocaml.Eff in - let* () = init_message (module R) in - let* cache, chain = init_chain (module R) in - return cache - >>= Yocaml.Action.copy_file ~into:R.Target.root R.Source.cname - >>= process_fonts (module R) - >>= process_css (module R) - >>= process_images (module R) - >>= generate_opml (module R) chain - >>= process_chain (module R) chain - >>= process_index (module R) chain - >>= Yocaml.Action.store_cache R.Target.cache - >>= final_message diff --git a/lib/action.mli b/lib/action.mli deleted file mode 100644 index d36b3ba..0000000 --- a/lib/action.mli +++ /dev/null @@ -1,4 +0,0 @@ -(** All the actions used to build the ring. *) - -val process_all : (module Sigs.RESOLVER) -> unit -> unit Yocaml.Eff.t -(** Process all action in order to produce [ring.muhokama]. *) diff --git a/lib/action/all.ml b/lib/action/all.ml new file mode 100644 index 0000000..0c3ddcd --- /dev/null +++ b/lib/action/all.ml @@ -0,0 +1,20 @@ +let init_message (module R : Sigs.RESOLVER) = + Yocaml.Eff.logf ~level:`Debug "ring.muhokama [source: `%a`, target: `%a`]" + Yocaml.Path.pp R.source Yocaml.Path.pp R.target + +let final_message _cache = Yocaml.Eff.log ~level:`Debug "ring.muhokama done" + +let run (module R : Sigs.RESOLVER) () = + let open Yocaml.Eff in + let* () = init_message (module R) in + let* cache, chain = Init.run (module R) in + return cache + >>= Cname.run (module R) + >>= Fonts.run (module R) + >>= Css.run (module R) + >>= Images.run (module R) + >>= Opml.run (module R) chain + >>= Chain.run (module R) chain + >>= Index.run (module R) chain + >>= Yocaml.Action.store_cache R.Target.cache + >>= final_message diff --git a/lib/action/all.mli b/lib/action/all.mli new file mode 100644 index 0000000..8485656 --- /dev/null +++ b/lib/action/all.mli @@ -0,0 +1,3 @@ +(** The global process that executes all actions sequentially. *) + +val run : (module Sigs.RESOLVER) -> unit -> unit Yocaml.Eff.t diff --git a/lib/action/batch_copy.ml b/lib/action/batch_copy.ml new file mode 100644 index 0000000..0cd82ac --- /dev/null +++ b/lib/action/batch_copy.ml @@ -0,0 +1,8 @@ +let has_extension ext_list path = + List.exists (fun ext -> Yocaml.Path.has_extension ext path) ext_list + +let run ?extension ~source ~target cache = + let where = Option.map (fun ext -> has_extension ext) extension in + Yocaml.Action.batch ~only:`Files ?where source + (Yocaml.Action.copy_file ~into:target) + cache diff --git a/lib/action/batch_copy.mli b/lib/action/batch_copy.mli new file mode 100644 index 0000000..ec18bf7 --- /dev/null +++ b/lib/action/batch_copy.mli @@ -0,0 +1,8 @@ +(** An action that initiates the copying of files from a source directory to a + target directory. *) + +val run : + ?extension:string list -> + source:Yocaml.Path.t -> + target:Yocaml.Path.t -> + Yocaml.Action.t diff --git a/lib/action/chain.ml b/lib/action/chain.ml new file mode 100644 index 0000000..6ca6ddd --- /dev/null +++ b/lib/action/chain.ml @@ -0,0 +1,23 @@ +let member (module R : Sigs.RESOLVER) pred_or_succ current_member target_member + = + let target = + R.Target.member_redirection + ~id:(Model.Member.id current_member) + pred_or_succ + in + Yocaml.Action.write_static_file target + (let open Yocaml.Task in + R.track_common_dependencies + >>> const target_member + >>> empty_body () + >>> Yocaml_jingoo.Pipeline.as_template + (module Model.Member) + (R.Source.template "redirect.html") + >>> drop_first ()) + +let run (module R : Sigs.RESOLVER) chain = + let member = member (module R) in + Yocaml.Action.batch_list (Model.Chain.to_list chain) + (fun (curr, (pred, succ)) cache -> + let open Yocaml.Eff in + cache |> member `Pred curr pred >>= member `Succ curr succ) diff --git a/lib/action/chain.mli b/lib/action/chain.mli new file mode 100644 index 0000000..42b987f --- /dev/null +++ b/lib/action/chain.mli @@ -0,0 +1,3 @@ +(** An action that builds the chain of links for each member. *) + +val run : (module Sigs.RESOLVER) -> Model.Chain.t -> Yocaml.Action.t diff --git a/lib/action/cname.ml b/lib/action/cname.ml new file mode 100644 index 0000000..e90bb47 --- /dev/null +++ b/lib/action/cname.ml @@ -0,0 +1,2 @@ +let run (module R : Sigs.RESOLVER) = + Yocaml.Action.copy_file ~into:R.Target.root R.Source.cname diff --git a/lib/action/cname.mli b/lib/action/cname.mli new file mode 100644 index 0000000..d283e5f --- /dev/null +++ b/lib/action/cname.mli @@ -0,0 +1,3 @@ +(** An action that copies the CNAME of the existing webring. *) + +val run : (module Sigs.RESOLVER) -> Yocaml.Action.t diff --git a/lib/action/css.ml b/lib/action/css.ml new file mode 100644 index 0000000..0b325a9 --- /dev/null +++ b/lib/action/css.ml @@ -0,0 +1,2 @@ +let run (module R : Sigs.RESOLVER) = + Batch_copy.run ~extension:[ "css" ] ~source:R.Source.css ~target:R.Target.css diff --git a/lib/action/css.mli b/lib/action/css.mli new file mode 100644 index 0000000..a38d28c --- /dev/null +++ b/lib/action/css.mli @@ -0,0 +1,3 @@ +(** An action that copies all the CSS files from the source to the target. *) + +val run : (module Sigs.RESOLVER) -> Yocaml.Action.t diff --git a/lib/action/fonts.ml b/lib/action/fonts.ml new file mode 100644 index 0000000..5f56408 --- /dev/null +++ b/lib/action/fonts.ml @@ -0,0 +1,3 @@ +let run (module R : Sigs.RESOLVER) = + Batch_copy.run ~extension:[ "woff2" ] ~source:R.Source.fonts + ~target:R.Target.fonts diff --git a/lib/action/fonts.mli b/lib/action/fonts.mli new file mode 100644 index 0000000..3b0522c --- /dev/null +++ b/lib/action/fonts.mli @@ -0,0 +1,3 @@ +(** An action that copies all the font files from the source to the target. *) + +val run : (module Sigs.RESOLVER) -> Yocaml.Action.t diff --git a/lib/action/images.ml b/lib/action/images.ml new file mode 100644 index 0000000..2477e04 --- /dev/null +++ b/lib/action/images.ml @@ -0,0 +1,5 @@ +let run (module R : Sigs.RESOLVER) cache = + (* We pass [cache] in order to add more rules. *) + cache + |> Batch_copy.run ~extension:[ "svg"; "png" ] ~source:R.Source.static_images + ~target:R.Target.images diff --git a/lib/action/images.mli b/lib/action/images.mli new file mode 100644 index 0000000..6511e02 --- /dev/null +++ b/lib/action/images.mli @@ -0,0 +1,3 @@ +(** An action that copies all the images files from the source to the target. *) + +val run : (module Sigs.RESOLVER) -> Yocaml.Action.t diff --git a/lib/action/index.ml b/lib/action/index.ml new file mode 100644 index 0000000..a6e9d83 --- /dev/null +++ b/lib/action/index.ml @@ -0,0 +1,13 @@ +let run (module R : Sigs.RESOLVER) _chain = + Yocaml.Action.write_static_file R.Target.index + (let open Yocaml.Task in + R.track_common_dependencies + >>> Yocaml.Pipeline.track_file R.Source.members + >>> Yocaml_yaml.Pipeline.read_file_with_metadata + (module Model.Page) + R.Source.index + >>> Yocaml_omd.content_to_html () + >>> Yocaml_jingoo.Pipeline.as_template + (module Model.Page) + (R.Source.template "layout.html") + >>> drop_first ()) diff --git a/lib/action/index.mli b/lib/action/index.mli new file mode 100644 index 0000000..c007152 --- /dev/null +++ b/lib/action/index.mli @@ -0,0 +1,3 @@ +(** An action that builds the webring index. *) + +val run : (module Sigs.RESOLVER) -> Model.Chain.t -> Yocaml.Action.t diff --git a/lib/action/init.ml b/lib/action/init.ml new file mode 100644 index 0000000..ee2969f --- /dev/null +++ b/lib/action/init.ml @@ -0,0 +1,22 @@ +let run (module R : Sigs.RESOLVER) = + let open Yocaml.Eff in + let* cache = Yocaml.Action.restore_cache ~on:`Target R.Target.cache in + let* chain = + Yocaml_yaml.Eff.read_file_as_metadata + (module Model.Chain.Metadata) + ~on:`Source R.Source.chain + in + let+ cache, members = + Yocaml.Action.fold ~only:`Files + ~where:(Yocaml.Path.has_extension "yml") + ~state:[] R.Source.members + (fun path state cache -> + let+ member = + Yocaml_yaml.Eff.read_file_as_metadata + (module Model.Member) + ~on:`Source path + in + (cache, member :: state)) + cache + in + (cache, Model.Chain.init ~chain ~members) diff --git a/lib/action/init.mli b/lib/action/init.mli new file mode 100644 index 0000000..727459e --- /dev/null +++ b/lib/action/init.mli @@ -0,0 +1,5 @@ +(** An action (not in the Yocaml sense) which initializes the cache and builds + the chain. *) + +val run : + (module Sigs.RESOLVER) -> (Yocaml.Cache.t * Model.Chain.t) Yocaml.Eff.t diff --git a/lib/action/opml.ml b/lib/action/opml.ml new file mode 100644 index 0000000..943e0d4 --- /dev/null +++ b/lib/action/opml.ml @@ -0,0 +1,7 @@ +let run (module R : Sigs.RESOLVER) chain = + Yocaml.Action.write_static_file R.Target.ring_opml + (let open Yocaml.Task in + R.track_common_dependencies + >>> Yocaml.Pipeline.track_file R.Source.members + >>> const chain + >>> Model.Chain.to_opml) diff --git a/lib/action/opml.mli b/lib/action/opml.mli new file mode 100644 index 0000000..0c43766 --- /dev/null +++ b/lib/action/opml.mli @@ -0,0 +1,3 @@ +(** An action that builds the OPML file for the rss/atom feeds of ring members. *) + +val run : (module Sigs.RESOLVER) -> Model.Chain.t -> Yocaml.Action.t