0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-10-18 06:22:53 -04:00

Merge branch 'rolling' into DOCS/430_new-preview-demo-images-of-the-search-engine-on-the-readme

This commit is contained in:
neon_arch 2023-12-14 15:21:32 +03:00 committed by GitHub
commit d61ab883d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 138 additions and 32 deletions

View File

@ -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);
}

View File

@ -50,6 +50,9 @@ function setClientSettings() {
case 'colorschemes':
cookie_dictionary['colorscheme'] = select_tag.value
break
case 'animations':
cookie_dictionary['animation'] = select_tag.value || null
break
case 'safe_search_levels':
cookie_dictionary['safe_search_level'] = Number(select_tag.value)
break
@ -103,13 +106,50 @@ function getClientSettings() {
.map((item) => item.split('='))
.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')),
)
}
}
}
}

View File

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

View File

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

View File

@ -17,6 +17,9 @@ pub struct Style {
/// It stores the parsed colorscheme option used to set a colorscheme for the
/// theme being used.
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 {
@ -27,8 +30,12 @@ impl Style {
/// * `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
/// 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,
}
}
}

View File

@ -13,7 +13,12 @@ use std::fs::read_to_string;
#[get("/")]
pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
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(
&config.style.colorscheme,
&config.style.theme,
&config.style.animation,
)
.0,
))
@ -47,7 +53,12 @@ pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std:
#[get("/about")]
pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
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(
&config.style.colorscheme,
&config.style.theme,
&config.style.animation,
&config
.upstream_search_engines
.keys()

View File

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

View File

@ -13,7 +13,7 @@ use maud::{html, Markup, PreEscaped, DOCTYPE};
/// # Returns
///
/// 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!(
(DOCTYPE)
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";
link href=(format!("static/colorschemes/{colorscheme}.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()\">"))

View File

@ -60,6 +60,17 @@ pub fn user_interface() -> Result<Markup, Box<dyn std::error::Error>> {
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)}
}
}
}
))
}

View File

@ -14,9 +14,9 @@ use crate::templates::partials::{footer::footer, header::header};
/// # Returns
///
/// 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!(
(header(colorscheme, theme))
(header(colorscheme, theme, animation))
main class="about-container"{
article {
div{

View File

@ -14,7 +14,7 @@ use crate::templates::partials::{bar::bar, footer::footer, header::header};
/// # Returns
///
/// It returns the compiled html markup code as a result.
pub fn index(colorscheme: &str, theme: &str) -> Markup {
pub fn index(colorscheme: &str, theme: &str, animation: &Option<String>) -> Markup {
let logo_svg = r#"
<svg viewBox="0 0 173 57" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path d="M77.8201 21.4277L73.4513 35.5049H70.3855L67.5496 25.1067L64.7137 35.5049H61.6479L57.2536 21.4277H60.2172L63.1553 32.7457L66.1444 21.4277H69.1847L72.0461 32.6946L74.9586 21.4277H77.8201ZM92.8986 28.1214C92.8986 28.6494 92.8645 29.1263 92.7964 29.5521H82.0405C82.1257 30.6762 82.543 31.5789 83.2924 32.2602C84.0418 32.9415 84.9616 33.2822 86.0516 33.2822C87.6186 33.2822 88.7257 32.6264 89.3729 31.3149H92.5154C92.0896 32.6094 91.3146 33.6739 90.1905 34.5085C89.0834 35.326 87.7038 35.7348 86.0516 35.7348C84.7061 35.7348 83.4968 35.4368 82.4238 34.8406C81.3678 34.2275 80.5332 33.3758 79.92 32.2858C79.3239 31.1787 79.0258 29.9013 79.0258 28.4535C79.0258 27.0058 79.3154 25.7369 79.8945 24.6468C80.4906 23.5397 81.3167 22.6881 82.3727 22.092C83.4457 21.4958 84.672 21.1978 86.0516 21.1978C87.3801 21.1978 88.5639 21.4873 89.6029 22.0664C90.6418 22.6455 91.4509 23.4631 92.03 24.5191C92.6091 25.558 92.8986 26.7588 92.8986 28.1214ZM89.8583 27.2016C89.8413 26.1286 89.4581 25.2685 88.7087 24.6213C87.9592 23.974 87.031 23.6504 85.9239 23.6504C84.919 23.6504 84.0589 23.974 83.3435 24.6213C82.6281 25.2515 82.2023 26.1116 82.0661 27.2016H89.8583ZM98.6773 23.5227C99.1713 22.8414 99.844 22.2878 100.696 21.862C101.564 21.4192 102.527 21.1978 103.583 21.1978C104.826 21.1978 105.95 21.4958 106.955 22.092C107.96 22.6881 108.752 23.5397 109.331 24.6468C109.91 25.7369 110.2 26.9887 110.2 28.4024C110.2 29.8161 109.91 31.085 109.331 32.2091C108.752 33.3162 107.951 34.1849 106.929 34.8151C105.925 35.4282 104.809 35.7348 103.583 35.7348C102.493 35.7348 101.522 35.5219 100.67 35.0961C99.8355 34.6703 99.1713 34.1253 98.6773 33.461V35.5049H95.7648V16.5991H98.6773V23.5227ZM107.236 28.4024C107.236 27.4316 107.032 26.597 106.623 25.8987C106.231 25.1833 105.703 24.6468 105.039 24.2891C104.392 23.9144 103.693 23.7271 102.944 23.7271C102.212 23.7271 101.513 23.9144 100.849 24.2891C100.202 24.6638 99.6737 25.2089 99.265 25.9242C98.8732 26.6396 98.6773 27.4827 98.6773 28.4535C98.6773 29.4244 98.8732 30.276 99.265 31.0084C99.6737 31.7237 100.202 32.2688 100.849 32.6435C101.513 33.0182 102.212 33.2055 102.944 33.2055C103.693 33.2055 104.392 33.0182 105.039 32.6435C105.703 32.2517 106.231 31.6897 106.623 30.9573C107.032 30.2249 107.236 29.3733 107.236 28.4024ZM118.19 35.7348C117.082 35.7348 116.086 35.5389 115.2 35.1472C114.332 34.7384 113.642 34.1934 113.131 33.5121C112.62 32.8138 112.347 32.0388 112.313 31.1872H115.328C115.379 31.7833 115.66 32.2858 116.171 32.6946C116.699 33.0863 117.355 33.2822 118.138 33.2822C118.956 33.2822 119.586 33.1289 120.029 32.8223C120.489 32.4987 120.719 32.0899 120.719 31.596C120.719 31.068 120.463 30.6762 119.952 30.4207C119.458 30.1653 118.666 29.8842 117.576 29.5777C116.52 29.2881 115.66 29.0071 114.996 28.7346C114.332 28.462 113.753 28.0447 113.259 27.4827C112.782 26.9206 112.543 26.1797 112.543 25.26C112.543 24.5105 112.765 23.8293 113.208 23.2161C113.65 22.5859 114.281 22.092 115.098 21.7343C115.933 21.3766 116.887 21.1978 117.96 21.1978C119.561 21.1978 120.847 21.6065 121.817 22.4241C122.805 23.2246 123.333 24.3232 123.401 25.7198H120.489C120.438 25.0896 120.182 24.5872 119.722 24.2125C119.263 23.8378 118.641 23.6504 117.857 23.6504C117.091 23.6504 116.503 23.7952 116.095 24.0847C115.686 24.3743 115.481 24.7575 115.481 25.2344C115.481 25.6091 115.618 25.9242 115.89 26.1797C116.163 26.4352 116.495 26.6396 116.887 26.7929C117.278 26.9291 117.857 27.108 118.624 27.3294C119.646 27.6019 120.48 27.8829 121.128 28.1725C121.792 28.445 122.362 28.8538 122.839 29.3988C123.316 29.9438 123.563 30.6677 123.58 31.5704C123.58 32.3709 123.359 33.0863 122.916 33.7165C122.473 34.3467 121.843 34.8406 121.025 35.1983C120.225 35.556 119.28 35.7348 118.19 35.7348ZM139.476 21.4277V35.5049H136.563V33.8442C136.104 34.4233 135.499 34.8832 134.75 35.2239C134.017 35.5475 133.234 35.7093 132.399 35.7093C131.292 35.7093 130.296 35.4793 129.41 35.0195C128.541 34.5596 127.851 33.8783 127.34 32.9756C126.847 32.0729 126.6 30.9828 126.6 29.7054V21.4277H129.487V29.2711C129.487 30.5315 129.802 31.5023 130.432 32.1836C131.062 32.8478 131.922 33.18 133.012 33.18C134.102 33.18 134.962 32.8478 135.593 32.1836C136.24 31.5023 136.563 30.5315 136.563 29.2711V21.4277H139.476ZM146.231 23.4716C146.657 22.7562 147.219 22.2027 147.918 21.8109C148.633 21.4022 149.476 21.1978 150.447 21.1978V24.2125H149.706C148.565 24.2125 147.696 24.502 147.1 25.0811C146.521 25.6602 146.231 26.6651 146.231 28.0958V35.5049H143.319V21.4277H146.231V23.4716ZM159.026 23.8037H156.42V35.5049H153.482V23.8037H151.821V21.4277H153.482V20.4313C153.482 18.8133 153.907 17.638 154.759 16.9056C155.628 16.1562 156.982 15.7815 158.821 15.7815V18.2086C157.936 18.2086 157.314 18.3789 156.956 18.7196C156.599 19.0432 156.42 19.6138 156.42 20.4313V21.4277H159.026V23.8037ZM167.636 28.3769L172.184 35.5049H168.888L165.848 30.7273L162.986 35.5049H159.946L164.494 28.5813L159.946 21.4277H163.242L166.282 26.2053L169.144 21.4277H172.184L167.636 28.3769Z" fill="currentColor"/>
@ -26,7 +26,7 @@ pub fn index(colorscheme: &str, theme: &str) -> Markup {
"#;
html!(
(header(colorscheme, theme))
(header(colorscheme, theme, animation))
main class="search-container"{
(PreEscaped(logo_svg))
(bar(&String::default()))

View File

@ -13,9 +13,9 @@ use maud::{html, Markup};
/// # Returns
///
/// 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!(
(header(colorscheme, theme))
(header(colorscheme, theme, animation))
main class="error_container"{
img src="images/robot-404.svg" alt="Image of broken robot.";
.error_content{

View File

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

View File

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

View File

@ -24,7 +24,12 @@ async fn test_index() {
assert_eq!(res.status(), 200);
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);
}

View File

@ -1,18 +1,18 @@
-- ### General ###
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 ###
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.
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
-- 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 = {
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 ###
@ -43,11 +43,20 @@ safe_search = 2
-- tomorrow-night
-- }}
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 ###
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 ###
upstream_search_engines = {
DuckDuckGo = true,