Browse Source

Merge branch 'rolling' into DOCS/439_revise-the-docs-to-remain-in-sync-with-the-current-changes

neon_arch 1 year ago
parent
commit
3b127d26a1

+ 3 - 0
flake.nix

@@ -39,8 +39,11 @@
             nodePackages_latest.stylelint
             nodePackages_latest.stylelint
             redis
             redis
             rustPackages.clippy
             rustPackages.clippy
+            cargo-watch
             rustc
             rustc
             yamllint
             yamllint
+            openssl
+            pkg-config
           ];
           ];
           RUST_SRC_PATH = rustPlatform.rustLibSrc;
           RUST_SRC_PATH = rustPlatform.rustLibSrc;
         };
         };

BIN
images/404_error_page.png


BIN
images/main_page.png


BIN
images/search_page.png


BIN
images/websurfx_logo.png


+ 15 - 0
public/static/animations/simple-frosted-glow.css

@@ -0,0 +1,15 @@
+.results_aggregated .result {
+  margin: 1rem;
+  padding: 1rem;
+  border-radius: 1rem;
+}
+
+.results_aggregated .result:hover {
+  box-shadow:
+    inset 0 0 3rem var(--color-two),
+    inset 0 0 6rem var(--color-five),
+    inset 0 0 9rem var(--color-three),
+    0 0 0.25rem var(--color-two),
+    0 0 0.5rem var(--color-five),
+    0 0 0.75rem var(--color-three);
+}

+ 47 - 7
public/static/settings.js

@@ -50,6 +50,9 @@ function setClientSettings() {
       case 'colorschemes':
       case 'colorschemes':
         cookie_dictionary['colorscheme'] = select_tag.value
         cookie_dictionary['colorscheme'] = select_tag.value
         break
         break
+      case 'animations':
+        cookie_dictionary['animation'] = select_tag.value || null
+        break
       case 'safe_search_levels':
       case 'safe_search_levels':
         cookie_dictionary['safe_search_level'] = Number(select_tag.value)
         cookie_dictionary['safe_search_level'] = Number(select_tag.value)
         break
         break
@@ -103,13 +106,50 @@ function getClientSettings() {
       .map((item) => item.split('='))
       .map((item) => item.split('='))
       .reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {})
       .reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {})
 
 
-    // Loop through all link tags and update their href values to match the user's preferences
-    Array.from(document.querySelectorAll('link')).forEach((item) => {
-      if (item.href.includes('static/themes')) {
-        item.href = `static/themes/${cookie_value['theme']}.css`
-      } else if (item.href.includes('static/colorschemes')) {
-        item.href = `static/colorschemes/${cookie_value['colorscheme']}.css`
+    let links = Array.from(document.querySelectorAll('link'))
+
+    // A check to determine whether the animation link exists under the head tag or not.
+    // If it does not exists then create and add a new animation link under the head tag
+    // and update the other link tags href according to the settings provided by the user
+    // via the UI. On the other hand if it does exist then just update all the link tags
+    // href according to the settings provided by the user via the UI.
+    if (!links.some((item) => item.href.includes('static/animations'))) {
+      if (cookie_value['animation']) {
+        let animation_link = document.createElement('link')
+        animation_link.href = `static/animations/${cookie_value['animation']}.css`
+        animation_link.rel = 'stylesheet'
+        animation_link.type = 'text/css'
+        document.querySelector('head').appendChild(animation_link)
       }
       }
-    })
+      // Loop through all link tags and update their href values to match the user's preferences
+      links.forEach((item) => {
+        if (item.href.includes('static/themes')) {
+          item.href = `static/themes/${cookie_value['theme']}.css`
+        } else if (item.href.includes('static/colorschemes')) {
+          item.href = `static/colorschemes/${cookie_value['colorscheme']}.css`
+        }
+      })
+    } else {
+      // Loop through all link tags and update their href values to match the user's preferences
+      links.forEach((item) => {
+        if (item.href.includes('static/themes')) {
+          item.href = `static/themes/${cookie_value['theme']}.css`
+        } else if (item.href.includes('static/colorschemes')) {
+          item.href = `static/colorschemes/${cookie_value['colorscheme']}.css`
+        } else if (
+          item.href.includes('static/animations') &&
+          cookie_value['animation']
+        ) {
+          item.href = `static/colorschemes/${cookie_value['animation']}.css`
+        }
+      })
+      if (!cookie_value['animation']) {
+        document
+          .querySelector('head')
+          .removeChild(
+            links.filter((item) => item.href.includes('static/animations')),
+          )
+      }
+    }
   }
   }
 }
 }

+ 1 - 1
public/static/themes/simple.css

@@ -348,7 +348,7 @@ footer div {
 }
 }
 
 
 .results_aggregated .result h1 a:visited {
 .results_aggregated .result h1 a:visited {
-  color: var(--background-color);
+  color: var(--color-five);
 }
 }
 
 
 .results_aggregated .result small {
 .results_aggregated .result small {

+ 1 - 0
src/config/parser.rs

@@ -115,6 +115,7 @@ impl Config {
             style: Style::new(
             style: Style::new(
                 globals.get::<_, String>("theme")?,
                 globals.get::<_, String>("theme")?,
                 globals.get::<_, String>("colorscheme")?,
                 globals.get::<_, String>("colorscheme")?,
+                globals.get::<_, Option<String>>("animation")?,
             ),
             ),
             #[cfg(feature = "redis-cache")]
             #[cfg(feature = "redis-cache")]
             redis_url: globals.get::<_, String>("redis_url")?,
             redis_url: globals.get::<_, String>("redis_url")?,

+ 2 - 2
src/engines/duckduckgo.rs

@@ -29,8 +29,8 @@ impl DuckDuckGo {
         Ok(Self {
         Ok(Self {
             parser: SearchResultParser::new(
             parser: SearchResultParser::new(
                 ".no-results",
                 ".no-results",
-                ".result",
-                ".result__a",
+                ".results>.result",
+                ".result__title>.result__a",
                 ".result__url",
                 ".result__url",
                 ".result__snippet",
                 ".result__snippet",
             )?,
             )?,

+ 9 - 2
src/models/parser_models.rs

@@ -17,6 +17,9 @@ pub struct Style {
     /// It stores the parsed colorscheme option used to set a colorscheme for the
     /// It stores the parsed colorscheme option used to set a colorscheme for the
     /// theme being used.
     /// theme being used.
     pub colorscheme: String,
     pub colorscheme: String,
+    /// It stores the parsed animation option used to set an animation for the
+    /// theme being used.
+    pub animation: Option<String>,
 }
 }
 
 
 impl Style {
 impl Style {
@@ -27,8 +30,12 @@ impl Style {
     /// * `theme` - It takes the parsed theme option used to set a theme for the website.
     /// * `theme` - It takes the parsed theme option used to set a theme for the website.
     /// * `colorscheme` - It takes the parsed colorscheme option used to set a colorscheme
     /// * `colorscheme` - It takes the parsed colorscheme option used to set a colorscheme
     /// for the theme being used.
     /// for the theme being used.
-    pub fn new(theme: String, colorscheme: String) -> Self {
-        Style { theme, colorscheme }
+    pub fn new(theme: String, colorscheme: String, animation: Option<String>) -> Self {
+        Style {
+            theme,
+            colorscheme,
+            animation,
+        }
     }
     }
 }
 }
 
 

+ 14 - 2
src/server/router.rs

@@ -13,7 +13,12 @@ use std::fs::read_to_string;
 #[get("/")]
 #[get("/")]
 pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
 pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
     Ok(HttpResponse::Ok().body(
     Ok(HttpResponse::Ok().body(
-        crate::templates::views::index::index(&config.style.colorscheme, &config.style.theme).0,
+        crate::templates::views::index::index(
+            &config.style.colorscheme,
+            &config.style.theme,
+            &config.style.animation,
+        )
+        .0,
     ))
     ))
 }
 }
 
 
@@ -28,6 +33,7 @@ pub async fn not_found(
             crate::templates::views::not_found::not_found(
             crate::templates::views::not_found::not_found(
                 &config.style.colorscheme,
                 &config.style.colorscheme,
                 &config.style.theme,
                 &config.style.theme,
+                &config.style.animation,
             )
             )
             .0,
             .0,
         ))
         ))
@@ -47,7 +53,12 @@ pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std:
 #[get("/about")]
 #[get("/about")]
 pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
 pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
     Ok(HttpResponse::Ok().body(
     Ok(HttpResponse::Ok().body(
-        crate::templates::views::about::about(&config.style.colorscheme, &config.style.theme).0,
+        crate::templates::views::about::about(
+            &config.style.colorscheme,
+            &config.style.theme,
+            &config.style.animation,
+        )
+        .0,
     ))
     ))
 }
 }
 
 
@@ -60,6 +71,7 @@ pub async fn settings(
         crate::templates::views::settings::settings(
         crate::templates::views::settings::settings(
             &config.style.colorscheme,
             &config.style.colorscheme,
             &config.style.theme,
             &config.style.theme,
+            &config.style.animation,
             &config
             &config
                 .upstream_search_engines
                 .upstream_search_engines
                 .keys()
                 .keys()

+ 1 - 0
src/server/routes/search.rs

@@ -72,6 +72,7 @@ pub async fn search(
                 crate::templates::views::search::search(
                 crate::templates::views::search::search(
                     &config.style.colorscheme,
                     &config.style.colorscheme,
                     &config.style.theme,
                     &config.style.theme,
+                    &config.style.animation,
                     query,
                     query,
                     &results?,
                     &results?,
                 )
                 )

+ 4 - 1
src/templates/partials/header.rs

@@ -13,7 +13,7 @@ use maud::{html, Markup, PreEscaped, DOCTYPE};
 /// # Returns
 /// # Returns
 ///
 ///
 /// It returns the compiled html markup code for the header as a result.
 /// It returns the compiled html markup code for the header as a result.
-pub fn header(colorscheme: &str, theme: &str) -> Markup {
+pub fn header(colorscheme: &str, theme: &str, animation: &Option<String>) -> Markup {
     html!(
     html!(
         (DOCTYPE)
         (DOCTYPE)
         html lang="en"
         html lang="en"
@@ -24,6 +24,9 @@ pub fn header(colorscheme: &str, theme: &str) -> Markup {
             meta name="viewport" content="width=device-width, initial-scale=1";
             meta name="viewport" content="width=device-width, initial-scale=1";
             link href=(format!("static/colorschemes/{colorscheme}.css")) rel="stylesheet" type="text/css";
             link href=(format!("static/colorschemes/{colorscheme}.css")) rel="stylesheet" type="text/css";
             link href=(format!("static/themes/{theme}.css")) rel="stylesheet" type="text/css";
             link href=(format!("static/themes/{theme}.css")) rel="stylesheet" type="text/css";
+            @if animation.is_some() {
+                    link href=(format!("static/animations/{}.css", animation.as_ref().unwrap())) rel="stylesheet" type="text/css";
+            }
         }
         }
 
 
         (PreEscaped("<body onload=\"getClientSettings()\">"))
         (PreEscaped("<body onload=\"getClientSettings()\">"))

+ 11 - 0
src/templates/partials/settings_tabs/user_interface.rs

@@ -60,6 +60,17 @@ pub fn user_interface() -> Result<Markup, Box<dyn std::error::Error>> {
                    option value=(k){(v)}
                    option value=(k){(v)}
                }
                }
            }
            }
+           h3{"select animation"}
+           p class="description"{
+               "Select the animation for your theme to be used in user interface"
+           }
+           select name="animations"{
+               option value=""{"none"}
+               @for (k,v) in style_option_list("animations")?{
+                   option value=(k){(v)}
+               }
+           }
+
         }
         }
     ))
     ))
 }
 }

+ 2 - 2
src/templates/views/about.rs

@@ -14,9 +14,9 @@ use crate::templates::partials::{footer::footer, header::header};
 /// # Returns
 /// # Returns
 ///
 ///
 /// It returns the compiled html markup code as a result.
 /// It returns the compiled html markup code as a result.
-pub fn about(colorscheme: &str, theme: &str) -> Markup {
+pub fn about(colorscheme: &str, theme: &str, animation: &Option<String>) -> Markup {
     html!(
     html!(
-        (header(colorscheme, theme))
+        (header(colorscheme, theme, animation))
         main class="about-container"{
         main class="about-container"{
          article {
          article {
              div{
              div{

File diff suppressed because it is too large
+ 1 - 1
src/templates/views/index.rs


+ 2 - 2
src/templates/views/not_found.rs

@@ -13,9 +13,9 @@ use maud::{html, Markup};
 /// # Returns
 /// # Returns
 ///
 ///
 /// It returns the compiled html markup code as a result.
 /// It returns the compiled html markup code as a result.
-pub fn not_found(colorscheme: &str, theme: &str) -> Markup {
+pub fn not_found(colorscheme: &str, theme: &str, animation: &Option<String>) -> Markup {
     html!(
     html!(
-        (header(colorscheme, theme))
+        (header(colorscheme, theme, animation))
         main class="error_container"{
         main class="error_container"{
          img src="images/robot-404.svg" alt="Image of broken robot.";
          img src="images/robot-404.svg" alt="Image of broken robot.";
          .error_content{
          .error_content{

+ 2 - 1
src/templates/views/search.rs

@@ -22,11 +22,12 @@ use crate::{
 pub fn search(
 pub fn search(
     colorscheme: &str,
     colorscheme: &str,
     theme: &str,
     theme: &str,
+    animation: &Option<String>,
     query: &str,
     query: &str,
     search_results: &SearchResults,
     search_results: &SearchResults,
 ) -> Markup {
 ) -> Markup {
     html!(
     html!(
-        (header(colorscheme, theme))
+        (header(colorscheme, theme, animation))
         main class="results"{
         main class="results"{
            (search_bar(&search_results.engine_errors_info, search_results.safe_search_level, query))
            (search_bar(&search_results.engine_errors_info, search_results.safe_search_level, query))
            .results_aggregated{
            .results_aggregated{

+ 2 - 1
src/templates/views/settings.rs

@@ -25,10 +25,11 @@ use crate::templates::partials::{
 pub fn settings(
 pub fn settings(
     colorscheme: &str,
     colorscheme: &str,
     theme: &str,
     theme: &str,
+    animation: &Option<String>,
     engine_names: &[&String],
     engine_names: &[&String],
 ) -> Result<Markup, Box<dyn std::error::Error>> {
 ) -> Result<Markup, Box<dyn std::error::Error>> {
     Ok(html!(
     Ok(html!(
-        (header(colorscheme, theme))
+        (header(colorscheme, theme, animation))
         main class="settings"{
         main class="settings"{
            h1{"Settings"}
            h1{"Settings"}
            hr;
            hr;

+ 6 - 1
tests/index.rs

@@ -24,7 +24,12 @@ async fn test_index() {
     assert_eq!(res.status(), 200);
     assert_eq!(res.status(), 200);
 
 
     let config = Config::parse(true).unwrap();
     let config = Config::parse(true).unwrap();
-    let template = views::index::index(&config.style.colorscheme, &config.style.theme).0;
+    let template = views::index::index(
+        &config.style.colorscheme,
+        &config.style.theme,
+        &config.style.animation,
+    )
+    .0;
     assert_eq!(res.text().await.unwrap(), template);
     assert_eq!(res.text().await.unwrap(), template);
 }
 }
 
 

+ 18 - 9
websurfx/config.lua

@@ -1,18 +1,18 @@
 -- ### General ###
 -- ### General ###
 logging = true -- an option to enable or disable logs.
 logging = true -- an option to enable or disable logs.
-debug = false  -- an option to enable or disable debug mode.
-threads = 10   -- the amount of threads that the app will use to run (the value should be greater than 0).
+debug = false -- an option to enable or disable debug mode.
+threads = 10 -- the amount of threads that the app will use to run (the value should be greater than 0).
 
 
 -- ### Server ###
 -- ### Server ###
-port = "8080"            -- port on which server should be launched
+port = "8080" -- port on which server should be launched
 binding_ip = "127.0.0.1" --ip address on the which server should be launched.
 binding_ip = "127.0.0.1" --ip address on the which server should be launched.
-production_use = false   -- whether to use production mode or not (in other words this option should be used if it is to be used to host it on the server to provide a service to a large number of users (more than one))
+production_use = false -- whether to use production mode or not (in other words this option should be used if it is to be used to host it on the server to provide a service to a large number of users (more than one))
 -- if production_use is set to true
 -- if production_use is set to true
 -- There will be a random delay before sending the request to the search engines, this is to prevent DDoSing the upstream search engines from a large number of simultaneous requests.
 -- There will be a random delay before sending the request to the search engines, this is to prevent DDoSing the upstream search engines from a large number of simultaneous requests.
-request_timeout = 30      -- timeout for the search requests sent to the upstream search engines to be fetched (value in seconds).
+request_timeout = 30 -- timeout for the search requests sent to the upstream search engines to be fetched (value in seconds).
 rate_limiter = {
 rate_limiter = {
-    number_of_requests = 20, -- The number of request that are allowed within a provided time limit.
-    time_limit = 3,       -- The time limit in which the quantity of requests that should be accepted.
+	number_of_requests = 20, -- The number of request that are allowed within a provided time limit.
+	time_limit = 3, -- The time limit in which the quantity of requests that should be accepted.
 }
 }
 
 
 -- ### Search ###
 -- ### Search ###
@@ -43,11 +43,20 @@ safe_search = 2
 -- tomorrow-night
 -- tomorrow-night
 -- }}
 -- }}
 colorscheme = "catppuccin-mocha" -- the colorscheme name which should be used for the website theme
 colorscheme = "catppuccin-mocha" -- the colorscheme name which should be used for the website theme
-theme = "simple"                 -- the theme name which should be used for the website
+-- The different themes provided are:
+-- {{
+-- simple
+-- }}
+theme = "simple" -- the theme name which should be used for the website
+-- The different animations provided are:
+-- {{
+-- simple-frosted-glow
+-- }}
+animation = "simple-frosted-glow" -- the animation name which should be used with the theme or `nil` if you don't want any animations.
 
 
 -- ### Caching ###
 -- ### Caching ###
 redis_url = "redis://127.0.0.1:8082" -- redis connection url address on which the client should connect on.
 redis_url = "redis://127.0.0.1:8082" -- redis connection url address on which the client should connect on.
-cache_expiry_time = 600              -- This option takes the expiry time of the search results (value in seconds and the value should be greater than or equal to 60 seconds).
+cache_expiry_time = 600 -- This option takes the expiry time of the search results (value in seconds and the value should be greater than or equal to 60 seconds).
 -- ### Search Engines ###
 -- ### Search Engines ###
 upstream_search_engines = {
 upstream_search_engines = {
     DuckDuckGo = true,
     DuckDuckGo = true,

Some files were not shown because too many files changed in this diff