1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
use std::{
fs::{read_to_string, File},
io::Write,
};
use clap::{Parser, Subcommand};
use laby::{html, internal::Buffer, Render};
#[derive(Parser)]
struct Args {
#[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!(body))
}
fn article(md_source: String) {
}
|