Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use markdown::*;
- use rocket::response::content;
- use rocket::response::content::Html;
- use rocket::*;
- use serde_derive::Deserialize;
- use std::fs::File;
- use std::io::Read;
- use std::ops::Add;
- use tokio::*;
- use toml;
- #[derive(Deserialize)]
- struct Config {
- pubdir: String,
- cssfile: String,
- }
- #[launch]
- async fn rocket() -> _ {
- rocket::build().mount("/", routes![getmd, getcssfile])
- }
- #[get("/<path>")]
- fn getmd(path: &str) -> Html<String> {
- let mdp = getconf().unwrap().pubdir + path;
- println!("{}", mdp);
- let mut mdf = File::open(&mdp);
- let mut md = String::new();
- mdf.unwrap().read_to_string(&mut md);
- let html = addcss(gethtm(&md));
- println!("{}", html);
- return content::Html(html);
- }
- #[get("/css.css")]
- fn getcssfile() -> String {
- let css = File::open(getconf().unwrap().cssfile);
- let mut csstext = String::new();
- css.unwrap().read_to_string(&mut csstext);
- println!("{}", csstext);
- csstext
- }
- fn getconf() -> Result<Config, toml::de::Error> {
- let mut cFile = File::open("config.toml");
- let mut cString = String::new();
- cFile.unwrap().read_to_string(&mut cString);
- println!("a");
- //let config: Result<Config, toml::de::Error> = toml::from_str(&cString);
- return toml::from_str(&cString);
- }
- fn gethtm(md: &str) -> String {
- println!("b");
- return markdown::to_html(md);
- }
- fn addcss(htm: String) -> String {
- println!("{}", htm);
- let mut ohtml = htm.clone();
- let mut h = String::new();
- let hh = h.clone().add(&("
- <head>
- <link rel=\u{0022}stylesheet\u{0022} type=\u{0022}text/css\u{0022} href=\u{0022}css.css\u{0022}>
- </head>
- <body>".to_owned()
- +
- &htm
- +
- &"</body>".to_owned()));
- //h.add(&htm);
- //h.add("</body>");
- ohtml.insert_str(htm.len(), "</body>");
- println!("{}", ohtml);
- return hh;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement