diff options
author | metamuffin <metamuffin@disroot.org> | 2022-08-29 15:43:02 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-08-29 15:43:02 +0200 |
commit | 9ca6cc8c0acdd68d2c79f1f990c9dd81dd9fef4b (patch) | |
tree | 28fc79f6bd65ba53456d846fcb0462dc65892e17 /tools/src/main.rs | |
parent | ca1c303ae20370fff555c0b8fca1b66f946eee3e (diff) | |
download | metamuffin-blog-9ca6cc8c0acdd68d2c79f1f990c9dd81dd9fef4b.tar metamuffin-blog-9ca6cc8c0acdd68d2c79f1f990c9dd81dd9fef4b.tar.bz2 metamuffin-blog-9ca6cc8c0acdd68d2c79f1f990c9dd81dd9fef4b.tar.zst |
a
Diffstat (limited to 'tools/src/main.rs')
-rw-r--r-- | tools/src/main.rs | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/tools/src/main.rs b/tools/src/main.rs index 0167e3c..396d148 100644 --- a/tools/src/main.rs +++ b/tools/src/main.rs @@ -1,17 +1,50 @@ -use clap::Parser; -use laby::{html, Render}; + +use std::{ + fs::{read_to_string, File}, + io::Write, +}; + +use clap::{Parser, Subcommand}; +use laby::{html, internal::Buffer, Render}; #[derive(Parser)] struct Args { - input: String, - output: String, + #[clap(short, long)] + output: Option<String>, + #[clap(subcommand)] + action: ArgAction, +} + +#[derive(Subcommand)] +enum ArgAction { + RenderArticle { input: String }, } fn main() { let args = Args::parse(); - + match args.action { + ArgAction::RenderArticle { input } => { + let md_source = read_to_string(input).unwrap(); + let mut out = Buffer::new(); + article(md_source).render(&mut out); + write_output(&args.output, out.into_string()); + } + } +} + +fn write_output(t: &Option<String>, o: String) { + if let Some(f) = t { + let mut f = File::create(f).unwrap(); + f.write_fmt(format_args!("{o}")).unwrap() + } else { + println!("{o}") + } } fn scaffold(title: String, body: impl Render) -> impl Render { - html!(head!(title!(title)), body!()) + html!(head!(title!(title)), body!(body)) +} + +fn article(md_source: String) { + } |