refactor: clean-up of some unused options after the template rework

This commit is contained in:
Lewis Wynne 2026-04-09 18:08:37 +01:00
parent f794fa3ce0
commit 7f86743f4a
6 changed files with 6 additions and 20 deletions

View file

@ -7,9 +7,6 @@ BOOK_DATA_DIR=./data
# Site title shown in nav and page title. # Site title shown in nav and page title.
BOOK_SITE_TITLE=guestbook BOOK_SITE_TITLE=guestbook
# Base URL of the main site (for absolute nav links).
BOOK_SITE_URL=https://example.com
# Telegram bot token. # Telegram bot token.
BOOK_TELEGRAM_BOT_TOKEN=your-bot-token-here BOOK_TELEGRAM_BOT_TOKEN=your-bot-token-here

View file

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2026 Llywelwyn Copyright (c) 2026 Lewis Wynne
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -30,11 +30,6 @@ in
description = "Site title shown in nav and page title."; description = "Site title shown in nav and page title.";
}; };
siteUrl = mkOption {
type = types.str;
description = "Base URL of the main site (for absolute nav links).";
};
telegramChatId = mkOption { telegramChatId = mkOption {
type = types.int; type = types.int;
description = "Telegram chat ID for moderation messages."; description = "Telegram chat ID for moderation messages.";
@ -174,7 +169,7 @@ in
BOOK_PORT = toString cfg.port; BOOK_PORT = toString cfg.port;
BOOK_DATA_DIR = cfg.dataDir; BOOK_DATA_DIR = cfg.dataDir;
BOOK_SITE_TITLE = cfg.siteTitle; BOOK_SITE_TITLE = cfg.siteTitle;
BOOK_SITE_URL = cfg.siteUrl;
BOOK_TELEGRAM_CHAT_ID = toString cfg.telegramChatId; BOOK_TELEGRAM_CHAT_ID = toString cfg.telegramChatId;
BOOK_HONEYPOT = if cfg.honeypot then "true" else "false"; BOOK_HONEYPOT = if cfg.honeypot then "true" else "false";
BOOK_MAX_NAME_LENGTH = toString cfg.maxNameLength; BOOK_MAX_NAME_LENGTH = toString cfg.maxNameLength;

View file

@ -6,7 +6,7 @@ pub struct Config {
pub port: u16, pub port: u16,
pub data_dir: PathBuf, pub data_dir: PathBuf,
pub site_title: String, pub site_title: String,
pub site_url: String,
pub telegram_bot_token: String, pub telegram_bot_token: String,
pub telegram_chat_id: i64, pub telegram_chat_id: i64,
pub honeypot: bool, pub honeypot: bool,
@ -41,7 +41,7 @@ impl Config {
.map(PathBuf::from) .map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from("./data")), .unwrap_or_else(|_| PathBuf::from("./data")),
site_title: env::var("BOOK_SITE_TITLE").unwrap_or_else(|_| "guestbook".into()), site_title: env::var("BOOK_SITE_TITLE").unwrap_or_else(|_| "guestbook".into()),
site_url: env::var("BOOK_SITE_URL").map_err(|_| "BOOK_SITE_URL is required")?,
telegram_bot_token: env::var("BOOK_TELEGRAM_BOT_TOKEN") telegram_bot_token: env::var("BOOK_TELEGRAM_BOT_TOKEN")
.map_err(|_| "BOOK_TELEGRAM_BOT_TOKEN is required")?, .map_err(|_| "BOOK_TELEGRAM_BOT_TOKEN is required")?,
telegram_chat_id: env::var("BOOK_TELEGRAM_CHAT_ID") telegram_chat_id: env::var("BOOK_TELEGRAM_CHAT_ID")
@ -115,7 +115,6 @@ mod tests {
env::set_var("BOOK_PORT", "9999"); env::set_var("BOOK_PORT", "9999");
env::set_var("BOOK_DATA_DIR", "/tmp/gb"); env::set_var("BOOK_DATA_DIR", "/tmp/gb");
env::set_var("BOOK_SITE_TITLE", "test.rs"); env::set_var("BOOK_SITE_TITLE", "test.rs");
env::set_var("BOOK_SITE_URL", "https://test.rs");
env::set_var("BOOK_TELEGRAM_BOT_TOKEN", "123:ABC"); env::set_var("BOOK_TELEGRAM_BOT_TOKEN", "123:ABC");
env::set_var("BOOK_TELEGRAM_CHAT_ID", "12345"); env::set_var("BOOK_TELEGRAM_CHAT_ID", "12345");
@ -124,14 +123,12 @@ mod tests {
assert_eq!(config.listen_addr(), "127.0.0.1:9999"); assert_eq!(config.listen_addr(), "127.0.0.1:9999");
assert_eq!(config.data_dir, PathBuf::from("/tmp/gb")); assert_eq!(config.data_dir, PathBuf::from("/tmp/gb"));
assert_eq!(config.site_title, "test.rs"); assert_eq!(config.site_title, "test.rs");
assert_eq!(config.site_url, "https://test.rs");
assert_eq!(config.telegram_chat_id, 12345); assert_eq!(config.telegram_chat_id, 12345);
// Clean up // Clean up
env::remove_var("BOOK_PORT"); env::remove_var("BOOK_PORT");
env::remove_var("BOOK_DATA_DIR"); env::remove_var("BOOK_DATA_DIR");
env::remove_var("BOOK_SITE_TITLE"); env::remove_var("BOOK_SITE_TITLE");
env::remove_var("BOOK_SITE_URL");
env::remove_var("BOOK_TELEGRAM_BOT_TOKEN"); env::remove_var("BOOK_TELEGRAM_BOT_TOKEN");
env::remove_var("BOOK_TELEGRAM_CHAT_ID"); env::remove_var("BOOK_TELEGRAM_CHAT_ID");
} }
@ -139,7 +136,6 @@ mod tests {
#[test] #[test]
fn test_defaults() { fn test_defaults() {
let _lock = ENV_LOCK.lock().unwrap(); let _lock = ENV_LOCK.lock().unwrap();
env::set_var("BOOK_SITE_URL", "https://test.rs");
env::set_var("BOOK_TELEGRAM_BOT_TOKEN", "123:ABC"); env::set_var("BOOK_TELEGRAM_BOT_TOKEN", "123:ABC");
env::set_var("BOOK_TELEGRAM_CHAT_ID", "12345"); env::set_var("BOOK_TELEGRAM_CHAT_ID", "12345");
@ -148,7 +144,6 @@ mod tests {
assert_eq!(config.data_dir, PathBuf::from("./data")); assert_eq!(config.data_dir, PathBuf::from("./data"));
assert_eq!(config.site_title, "guestbook"); assert_eq!(config.site_title, "guestbook");
env::remove_var("BOOK_SITE_URL");
env::remove_var("BOOK_TELEGRAM_BOT_TOKEN"); env::remove_var("BOOK_TELEGRAM_BOT_TOKEN");
env::remove_var("BOOK_TELEGRAM_CHAT_ID"); env::remove_var("BOOK_TELEGRAM_CHAT_ID");
} }
@ -156,7 +151,6 @@ mod tests {
#[test] #[test]
fn test_missing_required() { fn test_missing_required() {
let _lock = ENV_LOCK.lock().unwrap(); let _lock = ENV_LOCK.lock().unwrap();
env::remove_var("BOOK_SITE_URL");
env::remove_var("BOOK_TELEGRAM_BOT_TOKEN"); env::remove_var("BOOK_TELEGRAM_BOT_TOKEN");
env::remove_var("BOOK_TELEGRAM_CHAT_ID"); env::remove_var("BOOK_TELEGRAM_CHAT_ID");

View file

@ -81,7 +81,7 @@ mod tests {
port: 0, port: 0,
data_dir: PathBuf::from("./data"), data_dir: PathBuf::from("./data"),
site_title: "test".into(), site_title: "test".into(),
site_url: "https://test.rs".into(),
telegram_bot_token: "fake".into(), telegram_bot_token: "fake".into(),
telegram_chat_id: 0, telegram_chat_id: 0,
honeypot: true, honeypot: true,

View file

@ -129,7 +129,7 @@ mod tests {
port: 0, port: 0,
data_dir: dir.to_path_buf(), data_dir: dir.to_path_buf(),
site_title: "test".into(), site_title: "test".into(),
site_url: "https://test.rs".into(),
telegram_bot_token: "fake".into(), telegram_bot_token: "fake".into(),
telegram_chat_id: 0, telegram_chat_id: 0,
honeypot: true, honeypot: true,