neon_arch commited on
Commit
64c4d2c
·
1 Parent(s): 0ec8914

♻️ refactor(routes): serve new the maud files instead of handlebars files (#302)

Browse files
Files changed (1) hide show
  1. src/server/router.rs +27 -20
src/server/router.rs CHANGED
@@ -7,30 +7,30 @@ use crate::{
7
  handler::paths::{file_path, FileType},
8
  };
9
  use actix_web::{get, web, HttpRequest, HttpResponse};
10
- use handlebars::Handlebars;
11
  use std::fs::read_to_string;
12
 
13
  /// Handles the route of index page or main page of the `websurfx` meta search engine website.
14
  #[get("/")]
15
- pub async fn index(
16
- hbs: web::Data<Handlebars<'_>>,
17
- config: web::Data<Config>,
18
- ) -> Result<HttpResponse, Box<dyn std::error::Error>> {
19
- let page_content: String = hbs.render("index", &config.style).unwrap();
20
- Ok(HttpResponse::Ok().body(page_content))
21
  }
22
 
23
  /// Handles the route of any other accessed route/page which is not provided by the
24
  /// website essentially the 404 error page.
25
  pub async fn not_found(
26
- hbs: web::Data<Handlebars<'_>>,
27
  config: web::Data<Config>,
28
  ) -> Result<HttpResponse, Box<dyn std::error::Error>> {
29
- let page_content: String = hbs.render("404", &config.style)?;
30
-
31
  Ok(HttpResponse::Ok()
32
  .content_type("text/html; charset=utf-8")
33
- .body(page_content))
 
 
 
 
 
 
34
  }
35
 
36
  /// Handles the route of robots.txt page of the `websurfx` meta search engine website.
@@ -45,20 +45,27 @@ pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std:
45
 
46
  /// Handles the route of about page of the `websurfx` meta search engine website.
47
  #[get("/about")]
48
- pub async fn about(
49
- hbs: web::Data<Handlebars<'_>>,
50
- config: web::Data<Config>,
51
- ) -> Result<HttpResponse, Box<dyn std::error::Error>> {
52
- let page_content: String = hbs.render("about", &config.style)?;
53
- Ok(HttpResponse::Ok().body(page_content))
54
  }
55
 
56
  /// Handles the route of settings page of the `websurfx` meta search engine website.
57
  #[get("/settings")]
58
  pub async fn settings(
59
- hbs: web::Data<Handlebars<'_>>,
60
  config: web::Data<Config>,
61
  ) -> Result<HttpResponse, Box<dyn std::error::Error>> {
62
- let page_content: String = hbs.render("settings", &config.style)?;
63
- Ok(HttpResponse::Ok().body(page_content))
 
 
 
 
 
 
 
 
 
 
64
  }
 
7
  handler::paths::{file_path, FileType},
8
  };
9
  use actix_web::{get, web, HttpRequest, HttpResponse};
 
10
  use std::fs::read_to_string;
11
 
12
  /// Handles the route of index page or main page of the `websurfx` meta search engine website.
13
  #[get("/")]
14
+ pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
15
+ Ok(HttpResponse::Ok().body(
16
+ crate::templates::views::index::index(&config.style.colorscheme, &config.style.theme, "").0,
17
+ ))
 
 
18
  }
19
 
20
  /// Handles the route of any other accessed route/page which is not provided by the
21
  /// website essentially the 404 error page.
22
  pub async fn not_found(
 
23
  config: web::Data<Config>,
24
  ) -> Result<HttpResponse, Box<dyn std::error::Error>> {
 
 
25
  Ok(HttpResponse::Ok()
26
  .content_type("text/html; charset=utf-8")
27
+ .body(
28
+ crate::templates::views::not_found::not_found(
29
+ &config.style.colorscheme,
30
+ &config.style.theme,
31
+ )
32
+ .0,
33
+ ))
34
  }
35
 
36
  /// Handles the route of robots.txt page of the `websurfx` meta search engine website.
 
45
 
46
  /// Handles the route of about page of the `websurfx` meta search engine website.
47
  #[get("/about")]
48
+ pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
49
+ Ok(HttpResponse::Ok().body(
50
+ crate::templates::views::about::about(&config.style.colorscheme, &config.style.theme).0,
51
+ ))
 
 
52
  }
53
 
54
  /// Handles the route of settings page of the `websurfx` meta search engine website.
55
  #[get("/settings")]
56
  pub async fn settings(
 
57
  config: web::Data<Config>,
58
  ) -> Result<HttpResponse, Box<dyn std::error::Error>> {
59
+ Ok(HttpResponse::Ok().body(
60
+ crate::templates::views::settings::settings(
61
+ &config.style.colorscheme,
62
+ &config.style.theme,
63
+ &config
64
+ .upstream_search_engines
65
+ .iter()
66
+ .map(|(engine, _)| engine)
67
+ .collect::<Vec<&String>>(),
68
+ )?
69
+ .0,
70
+ ))
71
  }