diff --git a/Cargo.lock b/Cargo.lock index d94b0d2..f128aa0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -647,9 +647,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" [[package]] name = "lock_api" diff --git a/Cargo.toml b/Cargo.toml index f02c2ce..c064211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" bincode = "1.3.1" dirs = "3.0.1" handlebars = "3.5.1" -serde = { version = "1.0.116", features = ["derive"] } +serde = { version = "1.0.117", features = ["derive"] } serde_json = "1.0.59" sha2 = "0.9.1" sled = "0.34.4" diff --git a/src/server.rs b/src/server.rs index 1c351cf..86c072f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -21,15 +21,15 @@ pub async fn start_server( let templates = Arc::new(templates); let ads = vec![]; - + let mut data = Map::::new(); data.insert("lang".into(), to_json("fr")); data.insert("ads".into(), to_json(ads.clone())); - + let ads = Arc::new(RwLock::new(ads)); let data = Arc::new(RwLock::new(data)); - + let handle_index = { let data = data.clone(); move || { @@ -46,28 +46,26 @@ pub async fn start_server( .and(warp::get()) .and(warp::fs::dir(opt.dir.0.join(static_files::STATIC_DIR))); - let route_index = warp::path::end() - .and( - warp::get() - .map(handle_index.clone()) - .or(warp::post() - .and(warp::body::form::()) - .map(move |ad: NewAdQuery| { - let mut hasher = Sha512Trunc256::new(); - hasher.update(ad.password); - ads.write().unwrap().push(Ad { - author: ad.author, - password: hasher.finalize()[..].try_into().unwrap(), - pubkey: (!ad.pubkey.is_empty()).then_some(ad.pubkey), - time: 0, - title: ad.title, - }); - data.write().unwrap().insert("ads".into(), to_json(&*ads.read().unwrap())); - handle_index() - }) - ) - ); - + let route_index = warp::path::end().and( + warp::get().map(handle_index.clone()).or(warp::post() + .and(warp::body::form::()) + .map(move |ad: NewAdQuery| { + let mut hasher = Sha512Trunc256::new(); + hasher.update(ad.password); + ads.write().unwrap().push(Ad { + author: ad.author, + password: hasher.finalize()[..].try_into().unwrap(), + pubkey: (!ad.pubkey.is_empty()).then_some(ad.pubkey), + time: 0, + title: ad.title, + }); + data.write() + .unwrap() + .insert("ads".into(), to_json(&*ads.read().unwrap())); + handle_index() + })), + ); + warp::serve(route_static.or(route_index)) .run(config.listen) .await; diff --git a/src/static_files.rs b/src/static_files.rs index b4529cd..9ceeeea 100644 --- a/src/static_files.rs +++ b/src/static_files.rs @@ -1,8 +1,11 @@ use std::path::Path; pub const STATIC_DIR: &'static str = "static"; -static STATIC_FILES: &'static [(&str, &[u8])] = - &[("style1.css", include_bytes!("../static/style1.css")), ("standgm.png", include_bytes!("../static/standgm.png"))]; +static STATIC_FILES: &'static [(&str, &[u8])] = &[ + ("style1.css", include_bytes!("../static/style1.css")), + ("standgm.png", include_bytes!("../static/standgm.png")), + ("banner.jpg", include_bytes!("../static/banner.jpg")), +]; pub fn init_static_files(dir: &Path) { let dir = dir.join(STATIC_DIR); diff --git a/static/banner.jpg b/static/banner.jpg new file mode 100644 index 0000000..ffa34c2 Binary files /dev/null and b/static/banner.jpg differ diff --git a/static/style1.css b/static/style1.css index c32d5b2..bc3d6c2 100644 --- a/static/style1.css +++ b/static/style1.css @@ -1,8 +1,24 @@ html, body { + width: 100%; margin: 0; padding: 0; } -#logo { +#banner { + width: 100%; +} + +#stand { width: 200px; } + +.center { + padding: 4px; +} + +@media screen and (min-width: 801px) { + .center { + width: 800px; + margin: auto; + } +} diff --git a/templates/index.html b/templates/index.html index 671538e..0d32aaa 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,39 +6,48 @@ -

ĞMarché

- - - -

Ceci est une démo du nouveau site ĞMarché en développement. C'est très moche et il n'y a pas tellement de fonctionnalités mais ça avance. ;)

- - - - - - - {{#each ads}} - - - - - {{/each}} - -
AnnonceVendeur
{{this.title}}{{#if this.pubkey}}
{{this.author}}
{{this.pubkey}}
{{else}}{{this.author}}{{/if}}
- -
-
- Nouvelle annonce - -
- -
- -
- -
- -
-
+
+ + +

ĞMarché

+ +

Ceci est une démo du nouveau site ĞMarché en développement. C'est très moche et il n'y a pas tellement de fonctionnalités mais ça avance. ;)

+ + + + + + + {{#each ads}} + + + + + {{/each}} + +
AnnonceVendeur
{{this.title}}{{#if this.pubkey}}
{{this.author}}
{{this.pubkey}}
{{else}}{{this.author}}{{/if}}
+ + Marché + +
+
+ Nouvelle annonce + +
+ +
+ +
+ +
+ +
+
+ +
+ +

Code source sous licence GNU AGPL v3. 🦀 Écrit en Rust. Images de Attilax.
+ CopyLeft 2020 Pascal Engélibert

+