|
| 1 | +module Test_Article = Test_article |
| 2 | + |
| 3 | +class resolver ~source ~target = |
| 4 | + object (self) |
| 5 | + val get_source : Yocaml.Path.t = source |
| 6 | + val get_target : Yocaml.Path.t = target |
| 7 | + method source = get_source |
| 8 | + method target = Yocaml.Path.(get_target / "_www") |
| 9 | + method cache = Yocaml.Path.(self#target / ".cache") |
| 10 | + method templates = Yocaml.Path.(self#source / "content" / "templates") |
| 11 | + method articles = Yocaml.Path.(self#target / "articles") |
| 12 | + |
| 13 | + method as_article path = |
| 14 | + path |
| 15 | + |> Yocaml.Path.move ~into:self#articles |
| 16 | + |> Yocaml.Path.change_extension "html" |
| 17 | + |
| 18 | + method as_template path = Yocaml.Path.(self#templates / path) |
| 19 | + end |
| 20 | + |
| 21 | +let article (resolver : resolver) file = |
| 22 | + Yocaml.Action.Static.write_file_with_metadata (resolver#as_article file) |
| 23 | + Yocaml.Task.( |
| 24 | + Yocaml_yaml.Pipeline.read_file_with_metadata (module Test_Article) file |
| 25 | + >>> Yocaml_cmarkit.content_to_html () |
| 26 | + >>> Yocaml_jingoo.Pipeline.as_template |
| 27 | + (module Test_Article) |
| 28 | + (resolver#as_template "article.html") |
| 29 | + >>> Yocaml_jingoo.Pipeline.as_template |
| 30 | + (module Test_Article) |
| 31 | + (resolver#as_template "layout.html")) |
| 32 | + |
| 33 | +let program (resolver : resolver) file () = |
| 34 | + Yocaml.Action.with_cache ~on:`Target resolver#cache (article resolver file) |
| 35 | + |
| 36 | +let setup () = |
| 37 | + let port, file = |
| 38 | + match Array.to_list Sys.argv with |
| 39 | + | _ :: port_str :: file :: _ -> (int_of_string port_str, file) |
| 40 | + | _ -> failwith "Usage: server_error.exe <port> <file>" |
| 41 | + in |
| 42 | + let cwd = Yocaml.Path.rel [] in |
| 43 | + let file = Yocaml.Path.rel [ file ] in |
| 44 | + let resolver = new resolver ~source:cwd ~target:cwd in |
| 45 | + (port, resolver, file) |
0 commit comments