initial commit
This commit is contained in:
46
src/main.rs
Normal file
46
src/main.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use std::fs::File;
|
||||
use std::io::{Write, BufReader, BufRead, Error};
|
||||
use chrono;
|
||||
use std::time::Instant;
|
||||
|
||||
const PUBLISH_PATH: &str = "./pub/";
|
||||
const TEMPLATE_PATH: &str = "./src/templates/";
|
||||
|
||||
fn render_html(file: &str, template: &str, data: Vec<i32>) -> Result<(), Error> {
|
||||
let output_path = &format!("{}{}", PUBLISH_PATH, file);
|
||||
let template_path = &format!("{}{}", TEMPLATE_PATH, template);
|
||||
|
||||
let now = Instant::now();
|
||||
// TODO: Templating with template and data
|
||||
let html_string = "<h1>Hello!</h1>";
|
||||
let elapsed = now.elapsed();
|
||||
|
||||
let mut output_file = File::create(output_path)?;
|
||||
write!(output_file,
|
||||
"{}\n
|
||||
<!--\n
|
||||
{}\n
|
||||
{}\n
|
||||
generated in {:.2?}\n
|
||||
-->",
|
||||
html_string,
|
||||
template,
|
||||
chrono::offset::Local::now(),
|
||||
elapsed
|
||||
)?;
|
||||
|
||||
let input = File::open(output_path)?;
|
||||
let buffered = BufReader::new(input);
|
||||
|
||||
for line in buffered.lines() {
|
||||
println!("{}", line?);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
render_html("index.html", "index.tmpl", vec![1, 2, 3]);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user