feat: add preferences page with theme toggle
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 6s
Mirror to GitHub / mirror (push) Failing after 3s
Tests / test (push) Failing after 18s

- Simple preferences page with engine selection
- Light/dark theme toggle with localStorage persistence
- Clean form layout without complex JS dependencies
- Add dark theme CSS variables

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ashisgreat22 2026-03-22 22:27:38 +01:00
parent 030b4a8508
commit 77a41834a5
3 changed files with 355 additions and 166 deletions

View file

@ -24,6 +24,22 @@
--font-mono: "IBM Plex Mono", ui-monospace, monospace; --font-mono: "IBM Plex Mono", ui-monospace, monospace;
} }
[data-theme="dark"] {
--bg: #0f0f0f;
--bg-secondary: #1a1a1a;
--bg-tertiary: #242424;
--border: #2e2e2e;
--border-focus: #404040;
--text-primary: #e8eaed;
--text-secondary: #9aa0a6;
--text-muted: #6b7280;
--accent: #14b8a6;
--accent-hover: #2dd4bf;
--accent-soft: #134e4a;
--shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
--shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}
*, *::before, *::after { *, *::before, *::after {
box-sizing: border-box; box-sizing: border-box;
margin: 0; margin: 0;
@ -592,3 +608,224 @@ footer a:hover {
gap: 0.5rem; gap: 0.5rem;
} }
} }
/* ============================================================
Preferences Page
============================================================ */
.preferences-container {
max-width: 640px;
margin: 2rem auto;
padding: 0 1.5rem;
}
.preferences-title {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 2rem;
color: var(--text-primary);
}
.preferences-form {
display: flex;
flex-direction: column;
gap: 2rem;
}
.pref-section {
background: var(--bg);
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: 1.25rem;
}
.pref-section-title {
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--text-muted);
margin-bottom: 1rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid var(--border);
}
.pref-desc {
font-size: 0.8rem;
color: var(--text-muted);
margin-bottom: 1rem;
}
.pref-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 0.75rem 0;
border-bottom: 1px solid var(--border);
}
.pref-row:last-child {
border-bottom: none;
padding-bottom: 0;
}
.pref-row label:first-child {
font-size: 0.9rem;
color: var(--text-primary);
}
.pref-row-info {
flex: 1;
}
.pref-row-info label {
font-weight: 500;
}
.pref-row select {
padding: 0.5rem 0.75rem;
font-size: 0.85rem;
font-family: inherit;
border: 1px solid var(--border);
border-radius: var(--radius-sm);
background: var(--bg);
color: var(--text-primary);
cursor: pointer;
min-width: 120px;
}
.pref-row select:focus {
outline: none;
border-color: var(--accent);
}
.theme-buttons {
display: flex;
gap: 0.5rem;
}
.theme-btn {
padding: 0.5rem 1rem;
border: 1px solid var(--border);
border-radius: var(--radius-sm);
background: var(--bg);
color: var(--text-secondary);
font-size: 0.85rem;
font-family: inherit;
cursor: pointer;
transition: all 0.15s;
}
.theme-btn:hover {
background: var(--bg-secondary);
}
.theme-btn.active {
background: var(--accent-soft);
border-color: var(--accent);
color: var(--accent);
font-weight: 500;
}
.engine-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 0.5rem;
margin-top: 0.75rem;
}
.engine-toggle {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 0.75rem;
background: var(--bg-secondary);
border-radius: var(--radius-sm);
font-size: 0.85rem;
cursor: pointer;
transition: background 0.15s;
}
.engine-toggle:hover {
background: var(--bg-tertiary);
}
.engine-toggle input[type="checkbox"] {
width: 16px;
height: 16px;
accent-color: var(--accent);
cursor: pointer;
}
.engine-toggle span {
color: var(--text-secondary);
}
.pref-actions {
display: flex;
gap: 1rem;
justify-content: flex-end;
padding-top: 1rem;
}
.btn-primary,
.btn-secondary {
padding: 0.65rem 1.25rem;
border-radius: var(--radius-sm);
font-size: 0.9rem;
font-family: inherit;
cursor: pointer;
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
transition: all 0.15s;
}
.btn-primary {
background: var(--accent);
color: #fff;
border: none;
}
.btn-primary:hover {
background: var(--accent-hover);
}
.btn-secondary {
background: var(--bg);
color: var(--text-secondary);
border: 1px solid var(--border);
}
.btn-secondary:hover {
background: var(--bg-secondary);
color: var(--text-primary);
}
@media (max-width: 600px) {
.engine-grid {
grid-template-columns: 1fr 1fr;
}
.pref-row {
flex-direction: column;
align-items: flex-start;
gap: 0.5rem;
}
.pref-row select {
width: 100%;
}
.pref-actions {
flex-direction: column;
}
.btn-primary,
.btn-secondary {
width: 100%;
text-align: center;
}
}

View file

@ -1,6 +1,6 @@
{{define "base"}} {{define "base"}}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en" data-theme="light">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@ -11,6 +11,7 @@
<link rel="stylesheet" href="/static/css/kafka.css"> <link rel="stylesheet" href="/static/css/kafka.css">
<link rel="icon" href="/static/img/favicon.svg" type="image/svg+xml"> <link rel="icon" href="/static/img/favicon.svg" type="image/svg+xml">
<link title="kafka" type="application/opensearchdescription+xml" rel="search" href="/opensearch.xml"> <link title="kafka" type="application/opensearchdescription+xml" rel="search" href="/opensearch.xml">
<script>var s=document.documentElement;s.setAttribute('data-theme',localStorage.getItem('kafka-theme')||'light');</script>
</head> </head>
<body> <body>
<header class="site-header"> <header class="site-header">

View file

@ -1,191 +1,142 @@
{{define "title"}}Preferences{{end}} {{define "title"}}Preferences{{end}}
{{define "content"}} {{define "content"}}
<div class="preferences-layout"> <div class="preferences-container">
<!-- Preferences Navigation --> <h1 class="preferences-title">Preferences</h1>
<nav class="preferences-nav" id="preferences-nav">
<div class="preferences-nav-title">Settings</div>
<button class="preferences-nav-item active" data-section="search">🔍 Search</button>
<button class="preferences-nav-item" data-section="privacy">🔒 Privacy</button>
<button class="preferences-nav-item" data-section="tabs">📑 Tabs</button>
<button class="preferences-nav-item" data-section="appearance">🎨 Appearance</button>
<button class="preferences-nav-item" data-section="sidebar">📐 Sidebar</button>
<button class="preferences-nav-item" data-section="content">📄 Content</button>
<button class="preferences-nav-item" data-section="languages">🌍 Languages</button>
<button class="preferences-nav-item" data-section="regional">📍 Regional</button>
</nav>
<!-- Preferences Content --> <form class="preferences-form" method="POST" action="/preferences">
<div class="preferences-content"> <input type="hidden" name="theme" id="theme-input" value="light">
<!-- Search Section -->
<section class="pref-section" id="section-search"> <section class="pref-section">
<h2 class="pref-section-title">Search</h2> <h2 class="pref-section-title">Appearance</h2>
<div class="pref-row"> <div class="pref-row">
<label for="pref-default-engine">Default engine</label> <label>Theme</label>
<select id="pref-default-engine"> <div class="theme-buttons">
<option value="">All engines</option> <button type="button" class="theme-btn active" data-theme="light">Light</button>
<option value="wikipedia">Wikipedia</option> <button type="button" class="theme-btn" data-theme="dark">Dark</button>
<option value="arxiv">arXiv</option>
<option value="braveapi">Brave API</option>
<option value="duckduckgo">DuckDuckGo</option>
<option value="github">GitHub</option>
<option value="reddit">Reddit</option>
<option value="bing">Bing</option>
</select>
</div> </div>
<div class="pref-row">
<label for="pref-safesearch">Safe search</label>
<select id="pref-safesearch">
<option value="moderate">Moderate</option>
<option value="strict">Strict</option>
<option value="off">Off</option>
</select>
</div>
<div class="pref-row">
<label for="pref-search-lang">Search language</label>
<select id="pref-search-lang">
<option value="">All languages</option>
<option value="en">English</option>
<option value="de">Deutsch</option>
<option value="fr">Français</option>
<option value="es">Español</option>
<option value="zh">中文</option>
</select>
</div> </div>
</section> </section>
<!-- Privacy Section --> <section class="pref-section">
<section class="pref-section" id="section-privacy" style="display:none;"> <h2 class="pref-section-title">Search Engines</h2>
<p class="pref-desc">Select which engines to use for searches.</p>
<div class="engine-grid">
<label class="engine-toggle">
<input type="checkbox" name="engine" value="google" checked>
<span>Google</span>
</label>
<label class="engine-toggle">
<input type="checkbox" name="engine" value="duckduckgo" checked>
<span>DuckDuckGo</span>
</label>
<label class="engine-toggle">
<input type="checkbox" name="engine" value="bing" checked>
<span>Bing</span>
</label>
<label class="engine-toggle">
<input type="checkbox" name="engine" value="brave" checked>
<span>Brave</span>
</label>
<label class="engine-toggle">
<input type="checkbox" name="engine" value="wikipedia" checked>
<span>Wikipedia</span>
</label>
<label class="engine-toggle">
<input type="checkbox" name="engine" value="github">
<span>GitHub</span>
</label>
<label class="engine-toggle">
<input type="checkbox" name="engine" value="reddit">
<span>Reddit</span>
</label>
<label class="engine-toggle">
<input type="checkbox" name="engine" value="youtube">
<span>YouTube</span>
</label>
</div>
</section>
<section class="pref-section">
<h2 class="pref-section-title">Privacy</h2> <h2 class="pref-section-title">Privacy</h2>
<div class="pref-row"> <div class="pref-row">
<div class="pref-row-info"> <div class="pref-row-info">
<label>Tracking protection</label> <label>Safe Search</label>
<p class="pref-desc">Block trackers and scripts that follow you across the web.</p> <p class="pref-desc">Filter explicit content from results</p>
</div> </div>
<input type="checkbox" id="pref-tracking" checked disabled> <select name="safesearch">
</div> <option value="0">Off</option>
<div class="pref-row"> <option value="1" selected>Moderate</option>
<div class="pref-row-info"> <option value="2">Strict</option>
<label>Send Do Not Track header</label>
<p class="pref-desc">Ask websites not to track you.</p>
</div>
<input type="checkbox" id="pref-dnt">
</div>
</section>
<!-- Tabs Section -->
<section class="pref-section" id="section-tabs" style="display:none;">
<h2 class="pref-section-title">Tabs</h2>
<div class="pref-row">
<div class="pref-row-info">
<label>New tab behavior</label>
<p class="pref-desc">Choose what happens when you open a new tab.</p>
</div>
<select id="pref-newtab">
<option value="blank">Blank page</option>
<option value="home">Homepage</option>
</select> </select>
</div> </div>
</section> </section>
<!-- Appearance Section --> <section class="pref-section">
<section class="pref-section" id="section-appearance" style="display:none;"> <h2 class="pref-section-title">Language</h2>
<h2 class="pref-section-title">Appearance</h2>
<div class="pref-row"> <div class="pref-row">
<label for="pref-theme">Theme</label> <label for="search-lang">Interface &amp; Search Language</label>
<select id="pref-theme"> <select name="language" id="search-lang">
<option value="system">System</option> <option value="all" selected>All languages</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</div>
<div class="pref-row">
<label for="pref-fontsize">Results font size</label>
<select id="pref-fontsize">
<option value="small">Small</option>
<option value="medium" selected>Medium</option>
<option value="large">Large</option>
</select>
</div>
</section>
<!-- Sidebar Section -->
<section class="pref-section" id="section-sidebar" style="display:none;">
<h2 class="pref-section-title">Sidebar</h2>
<div class="pref-row">
<div class="pref-row-info">
<label>Show sidebar on results page</label>
<p class="pref-desc">Display the left navigation sidebar on search results.</p>
</div>
<input type="checkbox" id="pref-show-sidebar" checked>
</div>
</section>
<!-- Content Section -->
<section class="pref-section" id="section-content" style="display:none;">
<h2 class="pref-section-title">Content</h2>
<div class="pref-row">
<div class="pref-row-info">
<label>Filter explicit results</label>
<p class="pref-desc">Hide explicit content from search results (SafeSearch).</p>
</div>
<input type="checkbox" id="pref-explicit-filter" checked>
</div>
<div class="pref-row">
<div class="pref-row-info">
<label>Auto-play media</label>
<p class="pref-desc">Automatically play video content when visible.</p>
</div>
<input type="checkbox" id="pref-autoplay">
</div>
</section>
<!-- Languages Section -->
<section class="pref-section" id="section-languages" style="display:none;">
<h2 class="pref-section-title">Languages</h2>
<div class="pref-row">
<label for="pref-ui-lang">Interface language</label>
<select id="pref-ui-lang">
<option value="en" selected>English</option>
</select>
</div>
<div class="pref-row">
<label for="pref-search-lang-full">Search language</label>
<select id="pref-search-lang-full">
<option value="">All languages</option>
<option value="en">English</option> <option value="en">English</option>
<option value="de">Deutsch</option> <option value="de">Deutsch</option>
<option value="fr">Français</option> <option value="fr">Français</option>
<option value="es">Español</option> <option value="es">Español</option>
<option value="zh">中文</option> <option value="zh">中文</option>
<option value="ja">日本語</option>
<option value="ru">Русский</option>
</select> </select>
</div> </div>
</section> </section>
<!-- Regional Section --> <div class="pref-actions">
<section class="pref-section" id="section-regional" style="display:none;"> <a href="/" class="btn-secondary">Cancel</a>
<h2 class="pref-section-title">Regional</h2> <button type="submit" class="btn-primary">Save Preferences</button>
<div class="pref-row">
<label for="pref-region">Country/Region</label>
<select id="pref-region">
<option value="">All regions</option>
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
<option value="de">Germany</option>
<option value="fr">France</option>
<option value="cn">China</option>
</select>
</div>
<div class="pref-row">
<label for="pref-timezone">Timezone</label>
<select id="pref-timezone">
<option value="">Auto-detect</option>
<option value="utc">UTC</option>
<option value="us-eastern">US/Eastern</option>
<option value="us-pacific">US/Pacific</option>
<option value="europe">Europe</option>
</select>
</div>
</section>
</div> </div>
</form>
</div> </div>
<script>
(function() {
// Theme buttons
var themeInput = document.getElementById('theme-input');
var themeButtons = document.querySelectorAll('.theme-btn');
// Load saved theme
var savedTheme = localStorage.getItem('kafka-theme') || 'light';
themeInput.value = savedTheme;
document.querySelectorAll('.theme-btn').forEach(function(btn) {
btn.classList.toggle('active', btn.dataset.theme === savedTheme);
});
document.documentElement.setAttribute('data-theme', savedTheme);
themeButtons.forEach(function(btn) {
btn.addEventListener('click', function() {
var theme = btn.dataset.theme;
themeInput.value = theme;
themeButtons.forEach(function(b) { b.classList.remove('active'); });
btn.classList.add('active');
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('kafka-theme', theme);
});
});
// Load saved engine preferences
var savedEngines = JSON.parse(localStorage.getItem('kafka-engines') || 'null');
if (savedEngines) {
savedEngines.forEach(function(engine) {
var checkbox = document.querySelector('input[name="engine"][value="' + engine.id + '"]');
if (checkbox) checkbox.checked = engine.enabled;
});
}
// Save on submit
document.querySelector('.preferences-form').addEventListener('submit', function() {
var engines = [];
document.querySelectorAll('input[name="engine"]').forEach(function(cb) {
engines.push({ id: cb.value, enabled: cb.checked });
});
localStorage.setItem('kafka-engines', JSON.stringify(engines));
});
})();
</script>
{{end}} {{end}}