diff --git a/src/main.rs b/src/main.rs index 7705b5d..82c80da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -173,7 +173,7 @@ fn main() { .get("/world/") .unwrap_or_else(|| panic!("Section 'world' not found")); - render_section(&client, section, offset, 8) + render_section(&client, section, offset, settings.article_limit) } "/about" => render_about(), "/settings" => return handle_settings(request, &settings), @@ -195,7 +195,7 @@ fn main() { let offset = request .get_param("offset") .map_or(0, |s| s.parse::().unwrap_or(0)); - render_section(&client, section, offset, 8) + render_section(&client, section, offset, settings.article_limit) } else if path.starts_with("/authors/") { let offset = request .get_param("offset") diff --git a/src/routes/settings.rs b/src/routes/settings.rs index 6e18648..e171be3 100644 --- a/src/routes/settings.rs +++ b/src/routes/settings.rs @@ -3,7 +3,7 @@ use rouille::{post_input, try_or_400, Request, Response}; use crate::{ document, - settings::{Settings, EMBED_EMBEDS, EMBED_IMAGES, FAST_REDIRECT, PROXY_IMAGES, REDIRECT_TIMER}, + settings::{Settings, EMBED_EMBEDS, EMBED_IMAGES, FAST_REDIRECT, PROXY_IMAGES, REDIRECT_TIMER, ARTICLE_LIMIT}, }; fn render_settings( @@ -12,6 +12,7 @@ fn render_settings( proxy_images: bool, fast_redirect: bool, redirect_timer: u32, + article_limit: u32, ) -> Markup { document!( "Settings", @@ -46,6 +47,11 @@ fn render_settings( input type="number" id=(REDIRECT_TIMER) name=(REDIRECT_TIMER) value=(redirect_timer) {} } + label for=(ARTICLE_LIMIT) { + "Articles to display" + input type="number" id=(ARTICLE_LIMIT) name=(ARTICLE_LIMIT) value=(article_limit) {} + } + button type="submit" { "Save" } @@ -60,6 +66,7 @@ fn store_settings( proxy_images: bool, fast_redirect: bool, redirect_timer: u32, + article_limit: u32, ) -> Response { Response::redirect_303("/settings") .with_additional_header( @@ -77,7 +84,7 @@ fn store_settings( .with_additional_header( "Set-Cookie", format!("{FAST_REDIRECT}={}; Path=/; SameSite=Strict", fast_redirect), - ) + ) .with_additional_header( "Set-Cookie", format!( @@ -85,6 +92,13 @@ fn store_settings( redirect_timer ), ) + .with_additional_header( + "Set-Cookie", + format!( + "{ARTICLE_LIMIT}={}; Path=/; SameSite=Strict", + article_limit + ), + ) } pub fn handle_settings(request: &Request, settings: &Settings) -> Response { @@ -95,6 +109,7 @@ pub fn handle_settings(request: &Request, settings: &Settings) -> Response { proxy_images: bool, fast_redirect: bool, redirect_timer: i32, + article_limit: i32, })); store_settings( @@ -103,6 +118,7 @@ pub fn handle_settings(request: &Request, settings: &Settings) -> Response { settings.proxy_images, settings.fast_redirect, settings.redirect_timer.clamp(0, 600) as u32, + settings.article_limit.clamp(0, 100) as u32, ) } else { let page = render_settings( @@ -111,6 +127,7 @@ pub fn handle_settings(request: &Request, settings: &Settings) -> Response { settings.proxy_images, settings.fast_redirect, settings.redirect_timer, + settings.article_limit, ); Response::html(page).with_status_code(200) } diff --git a/src/settings.rs b/src/settings.rs index 3dc2a7d..4bd6031 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -5,6 +5,7 @@ pub const EMBED_EMBEDS: &str = "embed_embeds"; pub const PROXY_IMAGES: &str = "proxy_images"; pub const FAST_REDIRECT: &str = "fast_redirect"; pub const REDIRECT_TIMER: &str = "redirect_timer"; +pub const ARTICLE_LIMIT: &str = "article_limit"; pub struct Settings { pub embed_images: bool, @@ -12,6 +13,7 @@ pub struct Settings { pub proxy_images: bool, pub fast_redirect: bool, pub redirect_timer: u32, + pub article_limit: u32, } impl Settings { @@ -21,6 +23,7 @@ impl Settings { let mut proxy_images = true; let mut fast_redirect = false; let mut redirect_timer = 5; + let mut article_limit = 8; for (key, value) in input::cookies(request) { match key { EMBED_IMAGES => embed_images = value == "true", @@ -28,6 +31,7 @@ impl Settings { PROXY_IMAGES => proxy_images = value == "true", FAST_REDIRECT => fast_redirect = value == "true", REDIRECT_TIMER => redirect_timer = value.parse().unwrap_or(5), + ARTICLE_LIMIT => article_limit = value.parse().unwrap_or(5), _ => {} } } @@ -38,6 +42,7 @@ impl Settings { proxy_images, fast_redirect, redirect_timer, + article_limit } } } \ No newline at end of file