now generate the title randomly
parent
c48a13265e
commit
464f991696
|
@ -1,3 +1,6 @@
|
||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
|
||||||
|
# Enviroment variables
|
||||||
|
.env
|
32
src/main.rs
32
src/main.rs
|
@ -1,3 +1,31 @@
|
||||||
fn main() {
|
#![feature(proc_macro_hygiene, decl_macro)]
|
||||||
println!("Hello, world!");
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rocket;
|
||||||
|
extern crate rand;
|
||||||
|
extern crate rocket_contrib;
|
||||||
|
|
||||||
|
use rand::Rng;
|
||||||
|
use rocket_contrib::serve::StaticFiles;
|
||||||
|
use rocket_contrib::templates::Template;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
const TITLES: [&str; 4] = ["/* {} */", "# {}", "// {}", "<!-- {} -->"];
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
fn index() -> Template {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
let mut context = HashMap::new();
|
||||||
|
let title_fmt = TITLES[rng.gen_range(0, TITLES.len())];
|
||||||
|
let title = str::replace(title_fmt, "{}", "CódigoComentado");
|
||||||
|
context.insert("title", title);
|
||||||
|
Template::render("index", context)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
rocket::ignite()
|
||||||
|
.attach(Template::fairing())
|
||||||
|
.mount("/", routes![index])
|
||||||
|
.mount("/static", StaticFiles::from("static"))
|
||||||
|
.launch();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue