Draft conversion function
This commit is contained in:
parent
281a2fc78f
commit
16fd44139e
@ -55,7 +55,7 @@ let init force =
|
||||
in
|
||||
create_dirs dirs;
|
||||
let config_file = open_out ".logarion/config.toml" in
|
||||
output_bytes config_file (Toml.Printer.string_of_table toml_data);
|
||||
output_bytes config_file (Toml.Printer.string_of_table toml_data |> Bytes.of_string);
|
||||
close_out config_file
|
||||
|
||||
let init_term =
|
||||
@ -92,12 +92,45 @@ let create_term =
|
||||
~doc:"create a new article"
|
||||
~man:[ `S "DESCRIPTION"; `P "Create a new article, with title 'Draft' when none provided"]
|
||||
|
||||
let convert () =
|
||||
let module Config = Confix.Config.Make (Confix.ConfixToml) in
|
||||
|
||||
let toml_config =
|
||||
let open Confix.Config in
|
||||
Path.with_file ".logarion/config.toml"
|
||||
|> function Ok cfg -> Config.from_path cfg | Error str -> prerr_endline str; exit 1
|
||||
in
|
||||
let config =
|
||||
toml_config |> Config.to_record Logarion.Archive.Configuration.of_config
|
||||
|> function Ok cfg -> cfg | Error str -> prerr_endline str; exit 1
|
||||
in
|
||||
|
||||
let module L = Logarion.Archive.Make(File) in
|
||||
let store = File.store config.repository in
|
||||
let archive = L.{ config; store } in
|
||||
let notes = File.to_list L.note_lens archive.store in
|
||||
|
||||
let page_of_note = Converters.Html.of_note "test" config in
|
||||
let path_of_note note = "html/" ^ Meta.string_alias Note.(note.meta.Meta.title) ^ ".html" in
|
||||
let file_creation note =
|
||||
let out = open_out @@ path_of_note note in
|
||||
output_string out @@ page_of_note note;
|
||||
close_out out
|
||||
in
|
||||
List.iter file_creation notes
|
||||
|
||||
let convert_term =
|
||||
Term.(const convert $ const ()),
|
||||
Term.info
|
||||
"convert" ~doc:"convert archive to HTML"
|
||||
~man:[ `S "DESCRIPTION"; `P "Create a repository in current directory" ]
|
||||
|
||||
let default_cmd =
|
||||
Term.(ret (const (`Help (`Pager, None)))),
|
||||
Term.info "logarion" ~version:"0.2" ~doc:"an article collection & publishing system"
|
||||
~man:[ `S "BUGS"; `P "Submit bugs https://gitlab.com/orbifx/logarion/issues/new."; ]
|
||||
|
||||
let cmds = [ init_term; create_term ]
|
||||
let cmds = [ init_term; create_term; convert_term ]
|
||||
|
||||
let () = match Term.eval_choice default_cmd cmds with
|
||||
| `Error _ -> exit 1 | _ -> exit 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user