From f7cece9648945a6a38a8c22e2eb8a3e007dc3946 Mon Sep 17 00:00:00 2001 From: Franz Kafka Date: Sun, 22 Mar 2026 08:06:31 +0000 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20complete=20UI=20redesign=20?= =?UTF-8?q?=E2=80=94=20modern,=20clean=20search=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New CSS: complete design system with CSS variables, modern color palette - Homepage: full-viewport hero with centered search, logo, tagline - Result cards: rounded, shadowed, with favicons via Google Favicon API - Layout: sidebar + results grid, responsive - Typography: proper font stack, variable weights - Settings panel: polished popover with animations - Autocomplete: modern dropdown with keyboard nav - Dark mode: full color palette via data-theme attribute - Favicon: clean search icon SVG --- internal/views/static/css/kafka.css | 1463 +++++++++++-------- internal/views/templates/base.html | 43 +- internal/views/templates/index.html | 24 +- internal/views/templates/result_item.html | 9 +- internal/views/templates/results.html | 51 +- internal/views/templates/results_inner.html | 95 +- internal/views/templates/video_item.html | 10 +- 7 files changed, 940 insertions(+), 755 deletions(-) diff --git a/internal/views/static/css/kafka.css b/internal/views/static/css/kafka.css index b637860..8ae97ea 100644 --- a/internal/views/static/css/kafka.css +++ b/internal/views/static/css/kafka.css @@ -1,71 +1,49 @@ -/* kafka — clean, minimal search engine CSS */ +/* ============================================================ + kafka — modern, clean search UI + ============================================================ */ :root { - --color-base: #f5f5f5; - --color-base-font: #444; - --color-base-background: #fff; - --color-header-background: #f7f7f7; - --color-header-border: #ddd; - --color-search-border: #bbb; - --color-search-focus: #3498db; - --color-result-url: #1a0dab; - --color-result-url-visited: #609; - --color-result-content: #545454; - --color-result-title: #1a0dab; - --color-result-title-visited: #609; - --color-result-engine: #666; - --color-result-border: #eee; - --color-link: #3498db; - --color-link-visited: #609; - --color-sidebar-background: #f7f7f7; - --color-sidebar-border: #ddd; - --color-infobox-background: #f9f9f9; - --color-infobox-border: #ddd; - --color-pagination-current: #3498db; - --color-pagination-border: #ddd; - --color-error: #c0392b; - --color-error-background: #fdecea; - --color-suggestion: #666; - --color-footer: #888; - --color-btn-background: #fff; - --color-btn-border: #ddd; - --color-btn-hover: #eee; - --radius: 4px; - --max-width: 800px; + /* Light theme */ + --bg: #ffffff; + --bg-secondary: #f8f9fa; + --bg-tertiary: #f1f3f5; + --border: #e9ecef; + --border-focus: #cad1d8; + --text-primary: #1a1a1a; + --text-secondary: #5c6370; + --text-muted: #8b929e; + --accent: #2563eb; + --accent-hover: #1d4ed8; + --accent-soft: #eff6ff; + --accent-glow: rgba(37, 99, 235, 0.15); + --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04); + --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04); + --shadow-lg: 0 12px 32px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06); + --radius-sm: 8px; + --radius-md: 12px; + --radius-lg: 16px; + --radius-full: 9999px; + --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif; + --max-width: 880px; + --header-height: 56px; } -@media (prefers-color-scheme: dark) { - :root { - --color-base: #222; - --color-base-font: #dcdcdc; - --color-base-background: #2b2b2b; - --color-header-background: #333; - --color-header-border: #444; - --color-search-border: #555; - --color-search-focus: #5dade2; - --color-result-url: #8ab4f8; - --color-result-url-visited: #b39ddb; - --color-result-content: #b0b0b0; - --color-result-title: #8ab4f8; - --color-result-title-visited: #b39ddb; - --color-result-engine: #999; - --color-result-border: #3a3a3a; - --color-link: #5dade2; - --color-link-visited: #b39ddb; - --color-sidebar-background: #333; - --color-sidebar-border: #444; - --color-infobox-background: #333; - --color-infobox-border: #444; - --color-pagination-current: #5dade2; - --color-pagination-border: #444; - --color-error: #e74c3c; - --color-error-background: #3b1a1a; - --color-suggestion: #999; - --color-footer: #666; - --color-btn-background: #333; - --color-btn-border: #555; - --color-btn-hover: #444; - } +[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: #60a5fa; + --accent-hover: #93c5fd; + --accent-soft: #1e3a5f; + --accent-glow: rgba(96, 165, 250, 0.2); + --shadow-sm: 0 1px 3px rgba(0,0,0,0.3); + --shadow-md: 0 4px 12px rgba(0,0,0,0.4); + --shadow-lg: 0 12px 32px rgba(0,0,0,0.5); } *, *::before, *::after { @@ -76,35 +54,491 @@ html { font-size: 16px; + scroll-behavior: smooth; } body { - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; - color: var(--color-base-font); - background: var(--color-base); - line-height: 1.6; + font-family: var(--font); + background: var(--bg); + color: var(--text-primary); + line-height: 1.5; min-height: 100vh; - display: flex; - flex-direction: column; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; } -main { - flex: 1; - max-width: var(--max-width); - width: 100%; - margin: 0 auto; - padding: 1rem; +/* ============================================================ + Header + ============================================================ */ + +.site-header { + position: sticky; + top: 0; + z-index: 100; + height: var(--header-height); + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 1.5rem; + background: var(--bg); + border-bottom: 1px solid var(--border); + backdrop-filter: blur(12px); + background: color-mix(in srgb, var(--bg) 90%, transparent); } +.site-logo { + display: flex; + align-items: center; + gap: 0.5rem; + text-decoration: none; + color: var(--text-primary); +} + +.site-logo-mark { + width: 28px; + height: 28px; + color: var(--accent); +} + +.site-name { + font-size: 1.1rem; + font-weight: 600; + letter-spacing: -0.01em; +} + +.settings-trigger { + background: none; + border: none; + width: 36px; + height: 36px; + border-radius: var(--radius-sm); + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + color: var(--text-secondary); + transition: background 0.15s, color 0.15s; +} +.settings-trigger:hover { + background: var(--bg-tertiary); + color: var(--text-primary); +} + +/* ============================================================ + Main Layout + ============================================================ */ + +main { + max-width: var(--max-width); + margin: 0 auto; + padding: 0 1.5rem; +} + +/* ============================================================ + Homepage — Hero Search + ============================================================ */ + +.page-home { + min-height: calc(100vh - var(--header-height)); + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 4rem 1.5rem; + text-align: center; +} + +.hero-logo { + margin-bottom: 2rem; +} + +.hero-logo svg { + width: 64px; + height: 64px; + color: var(--accent); +} + +.hero-tagline { + font-size: 1rem; + color: var(--text-muted); + margin-bottom: 2.5rem; + max-width: 400px; +} + +.search-hero { + width: 100%; + max-width: 640px; +} + +.search-box { + position: relative; + width: 100%; +} + +.search-box input[type="text"], +#q { + width: 100%; + padding: 1rem 3.5rem 1rem 1.25rem; + font-size: 1.1rem; + font-family: inherit; + border: 2px solid var(--border); + border-radius: var(--radius-full); + background: var(--bg); + color: var(--text-primary); + outline: none; + transition: border-color 0.2s, box-shadow 0.2s; +} + +.search-box input[type="text"]:focus, +#q:focus { + border-color: var(--accent); + box-shadow: var(--shadow-lg), 0 0 0 4px var(--accent-glow); +} + +.search-box input[type="text"]::placeholder, +#q::placeholder { + color: var(--text-muted); +} + +.search-box-submit { + position: absolute; + right: 6px; + top: 50%; + transform: translateY(-50%); + width: 40px; + height: 40px; + border: none; + border-radius: var(--radius-full); + background: var(--accent); + color: #fff; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; + transition: background 0.15s, transform 0.15s; +} + +.search-box-submit:hover { + background: var(--accent-hover); + transform: translateY(-50%) scale(1.05); +} + +.search-box-submit:active { + transform: translateY(-50%) scale(0.97); +} + +/* ============================================================ + Results Page + ============================================================ */ + +.page-results { + padding-top: 1.5rem; +} + +.results-layout { + display: grid; + grid-template-columns: 1fr 220px; + gap: 2rem; + align-items: start; +} + +@media (max-width: 700px) { + .results-layout { + grid-template-columns: 1fr; + gap: 1rem; + } +} + +/* Compact search bar on results page */ +.search-compact { + grid-column: 1 / -1; +} + +.search-compact .search-box { + max-width: 100%; +} + +.search-compact input { + font-size: 1rem; + padding: 0.75rem 2.75rem 0.75rem 1rem; +} + +.search-compact .search-box-submit { + width: 34px; + height: 34px; +} + +/* ============================================================ + Results Column + ============================================================ */ + +.results-column { + min-width: 0; +} + +/* Result count + meta */ +.results-meta { + display: flex; + align-items: center; + gap: 0.75rem; + margin-bottom: 1rem; + font-size: 0.85rem; + color: var(--text-muted); +} + +/* Individual result card */ +.result { + background: var(--bg); + border: 1px solid var(--border); + border-radius: var(--radius-md); + padding: 1rem 1.1rem; + margin-bottom: 0.75rem; + transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; +} + +.result:hover { + border-color: var(--border-focus); + box-shadow: var(--shadow-sm); + transform: translateY(-1px); +} + +.result_header { + margin-bottom: 0.25rem; +} + +.result-favicon { + display: inline-block; + width: 16px; + height: 16px; + border-radius: 3px; + vertical-align: middle; + margin-right: 0.4rem; + background: var(--bg-tertiary); + flex-shrink: 0; +} + +.result_url { + display: flex; + align-items: center; + gap: 0.4rem; + font-size: 0.8rem; + color: var(--text-muted); + margin-bottom: 0.35rem; + overflow: hidden; +} + +.result_url a { + color: var(--text-muted); + text-decoration: none; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.result_url a:hover { + color: var(--accent); +} + +.result_url .engine-badge { + flex-shrink: 0; + display: inline-flex; + align-items: center; + gap: 0.25rem; + padding: 0.1rem 0.4rem; + background: var(--bg-tertiary); + border-radius: var(--radius-sm); + font-size: 0.7rem; + color: var(--text-muted); + margin-left: auto; +} + +.result_header a { + font-size: 1rem; + font-weight: 500; + color: var(--text-primary); + text-decoration: none; + line-height: 1.4; + display: block; +} + +.result_header a:hover { + color: var(--accent); +} + +.result_header a:visited { + color: var(--text-secondary); +} + +.result_content { + font-size: 0.9rem; + color: var(--text-secondary); + line-height: 1.55; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; +} + +/* ============================================================ + Sidebar + ============================================================ */ + +.sidebar { + position: sticky; + top: calc(var(--header-height) + 1.5rem); +} + +.sidebar-card { + background: var(--bg); + border: 1px solid var(--border); + border-radius: var(--radius-md); + padding: 1rem; + margin-bottom: 1rem; +} + +.sidebar-title { + font-size: 0.75rem; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.05em; + color: var(--text-muted); + margin-bottom: 0.75rem; +} + +/* Suggestions in sidebar */ +.suggestion-list { + display: flex; + flex-wrap: wrap; + gap: 0.4rem; +} + +.suggestion a { + display: inline-block; + padding: 0.3rem 0.65rem; + font-size: 0.8rem; + border: 1px solid var(--border); + border-radius: var(--radius-full); + color: var(--accent); + text-decoration: none; + background: var(--accent-soft); + transition: background 0.15s, border-color 0.15s; +} + +.suggestion a:hover { + background: color-mix(in srgb, var(--accent-soft) 70%, var(--bg-tertiary)); + border-color: var(--accent); +} + +/* Unresponsive engines warning */ +.unresponsive-engines { + font-size: 0.8rem; + color: var(--text-muted); +} + +.unresponsive-engines li { + margin: 0.3rem 0; +} + +/* Corrections */ +.correction { + font-size: 0.85rem; + color: var(--text-muted); + margin-bottom: 0.5rem; +} + +/* ============================================================ + No Results + ============================================================ */ + +.no-results { + text-align: center; + padding: 4rem 2rem; +} + +.no-results-icon { + font-size: 3rem; + margin-bottom: 1rem; + opacity: 0.3; +} + +.no-results h2 { + font-size: 1.25rem; + font-weight: 500; + margin-bottom: 0.5rem; +} + +.no-results p { + color: var(--text-muted); + font-size: 0.95rem; +} + +/* ============================================================ + Pagination + ============================================================ */ + +.pagination { + display: flex; + align-items: center; + justify-content: center; + gap: 0.4rem; + padding: 2rem 0; + flex-wrap: wrap; +} + +.pagination button, +.pagination .page-link { + min-width: 40px; + height: 40px; + padding: 0 0.75rem; + border: 1px solid var(--border); + border-radius: var(--radius-sm); + background: var(--bg); + color: var(--text-primary); + font-size: 0.9rem; + font-family: inherit; + cursor: pointer; + text-decoration: none; + display: inline-flex; + align-items: center; + justify-content: center; + transition: background 0.15s, border-color 0.15s, color 0.15s; +} + +.pagination button:hover, +.pagination .page-link:hover { + background: var(--bg-tertiary); + border-color: var(--border-focus); +} + +.pagination .page-current { + background: var(--accent); + border-color: var(--accent); + color: #fff; +} + +.pagination .page-current:hover { + background: var(--accent-hover); + border-color: var(--accent-hover); +} + +.pagination .prev-next { + font-weight: 500; +} + +/* ============================================================ + Footer + ============================================================ */ + footer { text-align: center; - padding: 1.5rem; - color: var(--color-footer); + padding: 3rem 1.5rem 2rem; + color: var(--text-muted); font-size: 0.85rem; + margin-top: auto; } footer a { - color: var(--color-link); + color: var(--accent); text-decoration: none; } @@ -112,331 +546,21 @@ footer a:hover { text-decoration: underline; } -/* Index / Homepage */ -.index { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - min-height: 60vh; - text-align: center; -} - -.index .title h1 { - font-size: 2rem; - font-weight: 300; - margin-bottom: 2rem; - letter-spacing: 0.05em; -} - -/* Search form */ -#search { - width: 100%; - max-width: 600px; - margin-bottom: 2rem; -} - -#search form { - display: flex; - gap: 0.5rem; -} - -#search input[type="text"], -#q { - flex: 1; - padding: 0.7rem 1rem; - font-size: 1rem; - border: 1px solid var(--color-search-border); - border-radius: var(--radius); - background: var(--color-base-background); - color: var(--color-base-font); - outline: none; - transition: border-color 0.2s; -} - -#search input[type="text"]:focus, -#q:focus { - border-color: var(--color-search-focus); - box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15); -} - -#search button[type="submit"] { - padding: 0.7rem 1.2rem; - font-size: 1rem; - border: 1px solid var(--color-search-border); - border-radius: var(--radius); - background: var(--color-btn-background); - color: var(--color-base-font); - cursor: pointer; - transition: background 0.2s; -} - -#search button[type="submit"]:hover { - background: var(--color-btn-hover); -} - -/* Results page search bar (compact) */ -.search_on_results #search { - max-width: 100%; - margin-bottom: 1rem; -} - -/* Results area */ -#results { - display: flex; - gap: 1.5rem; -} - -#sidebar { - flex: 0 0 200px; - font-size: 0.85rem; -} - -#sidebar p { - margin-bottom: 0.5rem; -} - -#urls { - flex: 1; - min-width: 0; -} - -/* Result count */ -#result_count { - margin-bottom: 1rem; -} - -/* Individual result */ -.result { - padding: 0.8rem 0; - border-bottom: 1px solid var(--color-result-border); - word-wrap: break-word; -} - -.result:last-child { - border-bottom: none; -} - -.result_header { - margin-bottom: 0.2rem; -} - -.result_header a { - font-size: 1.1rem; - font-weight: 400; - color: var(--color-result-title); - text-decoration: none; -} - -.result_header a:visited { - color: var(--color-result-title-visited); -} - -.result_header a:hover { - text-decoration: underline; -} - -.result_url { - font-size: 0.85rem; - color: var(--color-result-url); - margin-bottom: 0.2rem; -} - -.result_url a { - color: var(--color-result-url); - text-decoration: none; -} - -.result_url a:visited { - color: var(--color-result-url-visited); -} - -.result_content { - font-size: 0.9rem; - color: var(--color-result-content); - max-width: 600px; -} - -.result_content p { - margin: 0; -} - -.result_engine { - font-size: 0.75rem; - color: var(--color-result-engine); - margin-top: 0.3rem; -} - -.engine { - display: inline-block; - padding: 0.1rem 0.4rem; - background: var(--color-sidebar-background); - border: 1px solid var(--color-sidebar-border); - border-radius: 2px; - font-size: 0.7rem; - color: var(--color-result-engine); -} - -/* No results */ -.no_results { - text-align: center; - padding: 3rem 1rem; - color: var(--color-suggestion); -} - -/* Suggestions */ -#suggestions { - margin-bottom: 1rem; -} - -.suggestion { - display: inline-block; - margin: 0.2rem; -} - -.suggestion a { - display: inline-block; - padding: 0.3rem 0.6rem; - font-size: 0.85rem; - border: 1px solid var(--color-pagination-border); - border-radius: var(--radius); - color: var(--color-link); - text-decoration: none; - background: var(--color-btn-background); - transition: background 0.2s; -} - -.suggestion a:hover { - background: var(--color-btn-hover); -} - -/* Infoboxes */ -#infoboxes { - margin-bottom: 1rem; -} - -.infobox { - background: var(--color-infobox-background); - border: 1px solid var(--color-infobox-border); - border-radius: var(--radius); - padding: 0.8rem; - margin-bottom: 0.5rem; -} - -.infobox .title { - font-weight: 600; - margin-bottom: 0.5rem; -} - -/* Errors */ -.dialog-error { - background: var(--color-error-background); - color: var(--color-error); - border: 1px solid var(--color-error); - border-radius: var(--radius); - padding: 0.8rem 1rem; - margin-bottom: 1rem; -} - -/* Unresponsive engines */ -.unresponsive_engines { - font-size: 0.8rem; - color: var(--color-suggestion); - margin-top: 0.5rem; -} - -.unresponsive_engines li { - margin: 0.1rem 0; -} - -/* Corrections */ -.correction { - font-size: 0.9rem; - margin-bottom: 0.5rem; -} - -/* Pagination */ -#pagination { - display: flex; - align-items: center; - justify-content: center; - gap: 0.3rem; - padding: 1.5rem 0; - flex-wrap: wrap; -} - -#pagination button, -#pagination .page_number, -#pagination .page_number_current { - padding: 0.4rem 0.8rem; - font-size: 0.9rem; - border: 1px solid var(--color-pagination-border); - border-radius: var(--radius); - background: var(--color-btn-background); - color: var(--color-base-font); - cursor: pointer; - text-decoration: none; - transition: background 0.2s; -} - -#pagination button:hover, -#pagination .page_number:hover { - background: var(--color-btn-hover); -} - -#pagination .page_number_current { - background: var(--color-pagination-current); - color: #fff; - border-color: var(--color-pagination-current); - cursor: default; -} - -.previous_page, .next_page { - font-weight: 500; -} - -/* Back to top */ -#backToTop { - text-align: center; - margin: 1rem 0; -} - -#backToTop a { - color: var(--color-link); - text-decoration: none; - font-size: 0.85rem; -} - -/* HTMX loading indicator */ -.htmx-indicator { - display: none; - text-align: center; - padding: 2rem; - color: var(--color-suggestion); -} - -.htmx-request .htmx-indicator, -.htmx-request.htmx-indicator { - display: block; -} - -/* Autocomplete dropdown */ -#search { - position: relative; -} +/* ============================================================ + Autocomplete Dropdown + ============================================================ */ #autocomplete-dropdown { position: absolute; - top: 100%; + top: calc(100% + 6px); left: 0; right: 0; - background: var(--color-base-background); - border: 1px solid var(--color-search-border); - border-top: none; - border-radius: 0 0 var(--radius) var(--radius); - box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); - z-index: 100; - max-height: 320px; + background: var(--bg); + border: 1px solid var(--border); + border-radius: var(--radius-md); + box-shadow: var(--shadow-lg); + z-index: 200; + max-height: 360px; overflow-y: auto; display: none; } @@ -446,12 +570,12 @@ footer a:hover { } .autocomplete-suggestion { - padding: 0.6rem 1rem; + padding: 0.7rem 1rem; cursor: pointer; font-size: 0.95rem; - color: var(--color-base-font); - border-bottom: 1px solid var(--color-result-border); - transition: background 0.15s; + color: var(--text-primary); + border-bottom: 1px solid var(--border); + transition: background 0.1s; } .autocomplete-suggestion:last-child { @@ -460,159 +584,101 @@ footer a:hover { .autocomplete-suggestion:hover, .autocomplete-suggestion.active { - background: var(--color-header-background); + background: var(--bg-tertiary); } .autocomplete-suggestion mark { background: none; - color: var(--color-link); + color: var(--accent); font-weight: 600; } .autocomplete-footer { - padding: 0.4rem 1rem; + padding: 0.5rem 1rem; font-size: 0.75rem; - color: var(--color-suggestion); - border-top: 1px solid var(--color-result-border); - background: var(--color-header-background); + color: var(--text-muted); + background: var(--bg-secondary); + border-radius: 0 0 var(--radius-md) var(--radius-md); + border-top: 1px solid var(--border); } -/* Responsive */ -@media (max-width: 768px) { - #results { - flex-direction: column-reverse; - } - - #sidebar { - flex: none; - border-top: 1px solid var(--color-sidebar-border); - padding-top: 0.5rem; - } - - .index .title h1 { - font-size: 1.5rem; - } - - main { - padding: 0.5rem; - } -} - -/* Print */ -@media print { - footer, #pagination, #search button, #backToTop, .htmx-indicator { - display: none; - } - - body { - background: #fff; - color: #000; - } - - .result a { - color: #000; - } -} - -/* ============================================ +/* ============================================================ Settings Panel - ============================================ */ + ============================================================ */ -/* Header */ -.site-header { - display: flex; - align-items: center; - justify-content: space-between; - padding: 0.6rem 1rem; - background: var(--color-header-background); - border-bottom: 1px solid var(--color-header-border); -} -.site-title { - font-size: 1rem; - font-weight: 600; - color: var(--color-base-font); -} - -/* Gear trigger button */ -.settings-trigger { - background: none; - border: none; - font-size: 1.1rem; - cursor: pointer; - padding: 0.3rem 0.5rem; - border-radius: var(--radius); - color: var(--color-base-font); - opacity: 0.7; - transition: opacity 0.2s, background 0.2s; - line-height: 1; -} -.settings-trigger:hover, -.settings-trigger[aria-expanded="true"] { - opacity: 1; - background: var(--color-sidebar-background); -} - -/* Popover panel */ .settings-popover { - position: absolute; - top: 100%; - right: 0; - width: 280px; - max-height: 420px; + position: fixed; + top: calc(var(--header-height) + 8px); + right: 1rem; + width: 300px; + max-height: calc(100vh - var(--header-height) - 2rem); overflow-y: auto; - background: var(--color-base-background); - border: 1px solid var(--color-sidebar-border); - border-radius: var(--radius); - box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); - z-index: 200; + background: var(--bg); + border: 1px solid var(--border); + border-radius: var(--radius-lg); + box-shadow: var(--shadow-lg); + z-index: 300; display: none; - flex-direction: column; } + .settings-popover[data-open="true"] { - display: flex; - animation: settings-slide-in 0.2s ease; + display: block; + animation: pop-in 0.2s ease; } -@keyframes settings-slide-in { - from { opacity: 0; transform: translateY(-8px); } - to { opacity: 1; transform: translateY(0); } + +@keyframes pop-in { + from { opacity: 0; transform: translateY(-8px) scale(0.97); } + to { opacity: 1; transform: translateY(0) scale(1); } } .settings-popover-header { display: flex; justify-content: space-between; align-items: center; - padding: 0.75rem 1rem; - border-bottom: 1px solid var(--color-sidebar-border); + padding: 1rem 1.25rem; + border-bottom: 1px solid var(--border); font-weight: 600; - font-size: 0.9rem; - flex-shrink: 0; + font-size: 0.95rem; + position: sticky; + top: 0; + background: var(--bg); + z-index: 1; } + .settings-popover-close { background: none; border: none; - font-size: 1.2rem; + width: 28px; + height: 28px; + border-radius: var(--radius-sm); cursor: pointer; - color: var(--color-base-font); - opacity: 0.6; - padding: 0 0.25rem; - line-height: 1; + color: var(--text-secondary); + display: flex; + align-items: center; + justify-content: center; + font-size: 1.2rem; + transition: background 0.15s, color 0.15s; +} + +.settings-popover-close:hover { + background: var(--bg-tertiary); + color: var(--text-primary); } -.settings-popover-close:hover { opacity: 1; } .settings-popover-body { - padding: 0.8rem; + padding: 1rem 1.25rem; display: flex; flex-direction: column; - gap: 1rem; + gap: 1.25rem; } .settings-section-title { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; - letter-spacing: 0.05em; - color: var(--color-suggestion); - margin-bottom: 0.5rem; + letter-spacing: 0.06em; + color: var(--text-muted); + margin-bottom: 0.6rem; } /* Theme buttons */ @@ -620,162 +686,109 @@ footer a:hover { display: flex; gap: 0.4rem; } + .theme-btn { flex: 1; - padding: 0.35rem 0.5rem; - border: 1px solid var(--color-sidebar-border); - border-radius: var(--radius); - background: var(--color-btn-background); - color: var(--color-base-font); + padding: 0.45rem; + border: 1px solid var(--border); + border-radius: var(--radius-sm); + background: var(--bg); + color: var(--text-secondary); cursor: pointer; - font-size: 0.75rem; - text-align: center; - transition: background 0.15s, border-color 0.15s; -} -.theme-btn:hover { background: var(--color-btn-hover); } -.theme-btn.active { - background: var(--color-link); - color: #fff; - border-color: var(--color-link); + font-size: 0.8rem; + font-family: inherit; + transition: background 0.15s, border-color 0.15s, color 0.15s; } -/* Engine toggles — 2-column grid */ +.theme-btn:hover { + background: var(--bg-tertiary); +} + +.theme-btn.active { + background: var(--accent-soft); + border-color: var(--accent); + color: var(--accent); + font-weight: 500; +} + +/* Engine toggles */ .engine-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; } + .engine-toggle { display: flex; align-items: center; gap: 0.4rem; - padding: 0.3rem 0.5rem; - border-radius: var(--radius); - background: var(--color-sidebar-background); - font-size: 0.78rem; + padding: 0.4rem 0.5rem; + border-radius: var(--radius-sm); + background: var(--bg-tertiary); + font-size: 0.8rem; cursor: pointer; + transition: background 0.1s; } + +.engine-toggle:hover { + background: var(--border); +} + .engine-toggle input[type="checkbox"] { width: 15px; height: 15px; margin: 0; cursor: pointer; - accent-color: var(--color-link); -} -.engine-toggle span { - flex: 1; - min-width: 0; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; + accent-color: var(--accent); + flex-shrink: 0; } -/* Search defaults */ +.engine-toggle span { + color: var(--text-secondary); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +/* Select dropdowns */ .setting-row { display: flex; align-items: center; justify-content: space-between; - gap: 0.5rem; - margin-top: 0.4rem; + gap: 0.75rem; } + .setting-row label { font-size: 0.85rem; - flex: 1; + color: var(--text-secondary); } + .setting-row select { - width: 110px; - padding: 0.3rem 0.4rem; + padding: 0.35rem 0.6rem; font-size: 0.8rem; - border: 1px solid var(--color-sidebar-border); - border-radius: var(--radius); - background: var(--color-base-background); - color: var(--color-base-font); + font-family: inherit; + border: 1px solid var(--border); + border-radius: var(--radius-sm); + background: var(--bg); + color: var(--text-primary); cursor: pointer; + min-width: 100px; +} + +.setting-row select:focus { + outline: none; + border-color: var(--accent); } -/* Mid-search notice */ .settings-notice { - font-size: 0.72rem; - color: var(--color-suggestion); - margin-top: 0.3rem; + font-size: 0.75rem; + color: var(--text-muted); font-style: italic; + margin-top: 0.25rem; } -/* Dark theme via data-theme attribute */ -html[data-theme="dark"] { - --color-base: #222; - --color-base-font: #dcdcdc; - --color-base-background: #2b2b2b; - --color-header-background: #333; - --color-header-border: #444; - --color-search-border: #555; - --color-search-focus: #5dade2; - --color-result-url: #8ab4f8; - --color-result-url-visited: #b39ddb; - --color-result-content: #b0b0b0; - --color-result-title: #8ab4f8; - --color-result-title-visited: #b39ddb; - --color-result-engine: #999; - --color-result-border: #3a3a3a; - --color-link: #5dade2; - --color-link-visited: #b39ddb; - --color-sidebar-background: #333; - --color-sidebar-border: #444; - --color-infobox-background: #333; - --color-infobox-border: #444; - --color-pagination-current: #5dade2; - --color-pagination-border: #444; - --color-error: #e74c3c; - --color-error-background: #3b1a1a; - --color-suggestion: #999; - --color-footer: #666; - --color-btn-background: #333; - --color-btn-border: #555; - --color-btn-hover: #444; -} - -/* Light theme via data-theme attribute - explicit reset */ -html[data-theme="light"] { - --color-base: #f5f5f5; - --color-base-font: #444; - --color-base-background: #fff; - --color-header-background: #f7f7f7; - --color-header-border: #ddd; - --color-search-border: #bbb; - --color-search-focus: #3498db; - --color-result-url: #1a0dab; - --color-result-url-visited: #609; - --color-result-content: #545454; - --color-result-title: #1a0dab; - --color-result-title-visited: #609; - --color-result-engine: #666; - --color-result-border: #eee; - --color-link: #3498db; - --color-link-visited: #609; - --color-sidebar-background: #f7f7f7; - --color-sidebar-border: #ddd; - --color-infobox-background: #f9f9f9; - --color-infobox-border: #ddd; - --color-pagination-current: #3498db; - --color-pagination-border: #ddd; - --color-error: #c0392b; - --color-error-background: #fdecea; - --color-suggestion: #666; - --color-footer: #888; - --color-btn-background: #fff; - --color-btn-border: #ddd; - --color-btn-hover: #eee; -} - -/* Mobile: Bottom sheet + FAB trigger */ -@media (max-width: 768px) { - /* Hide desktop trigger, show FAB */ - .settings-trigger-desktop { - display: none; - } - .settings-trigger-mobile { - display: block; - } +/* Mobile settings: bottom sheet */ +@media (max-width: 480px) { .settings-popover { position: fixed; top: auto; @@ -784,29 +797,64 @@ html[data-theme="light"] { right: 0; width: 100%; max-height: 70vh; - border-radius: var(--radius) var(--radius) 0 0; + border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: none; } - /* FAB: fixed bottom-right button visible only on mobile */ + .settings-trigger-mobile { - display: block; - position: fixed; - bottom: 1.5rem; - right: 1.5rem; - width: 48px; - height: 48px; - border-radius: 50%; - background: var(--color-link); - color: #fff; - border: none; - box-shadow: 0 4px 12px rgba(0,0,0,0.2); - font-size: 1.2rem; - z-index: 199; - opacity: 1; + display: flex; } } -/* Video result cards */ +@media (min-width: 481px) { + .settings-trigger-mobile { + display: none; + } +} + +/* ============================================================ + HTMX Loading State + ============================================================ */ + +.htmx-indicator { + display: none; + text-align: center; + padding: 2rem; + color: var(--text-muted); +} + +.htmx-request .htmx-indicator { + display: block; +} + +.htmx-request .results-column { + opacity: 0.5; + transition: opacity 0.2s; +} + +/* ============================================================ + Back to Top + ============================================================ */ + +.back-to-top { + text-align: center; + padding: 1rem; +} + +.back-to-top a { + color: var(--accent); + text-decoration: none; + font-size: 0.85rem; +} + +.back-to-top a:hover { + text-decoration: underline; +} + +/* ============================================================ + Video Results + ============================================================ */ + .video-result { display: flex; gap: 1rem; @@ -816,15 +864,134 @@ html[data-theme="light"] { .video-result .result_thumbnail { flex-shrink: 0; width: 180px; + border-radius: var(--radius-sm); + overflow: hidden; + background: var(--bg-tertiary); } .video-result .result_thumbnail img { width: 100%; height: auto; - border-radius: var(--radius); + display: block; + object-fit: cover; } .video-result .result_content_wrapper { flex: 1; min-width: 0; } + +@media (max-width: 480px) { + .video-result { + flex-direction: column; + } + + .video-result .result_thumbnail { + width: 100%; + } +} + +/* ============================================================ + Infoboxes + ============================================================ */ + +.infobox { + background: var(--bg-secondary); + border: 1px solid var(--border); + border-radius: var(--radius-md); + padding: 1rem; + margin-bottom: 0.75rem; +} + +.infobox .title { + font-weight: 600; + margin-bottom: 0.5rem; + font-size: 0.95rem; +} + +.infobox img { + max-width: 100%; + border-radius: var(--radius-sm); + margin-top: 0.5rem; +} + +/* ============================================================ + Errors + ============================================================ */ + +.dialog-error { + background: color-mix(in srgb, var(--accent) 8%, var(--bg)); + border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); + color: var(--accent); + border-radius: var(--radius-md); + padding: 0.8rem 1rem; + margin-bottom: 1rem; + font-size: 0.9rem; +} + +/* ============================================================ + Focus visible — keyboard navigation + ============================================================ */ + +:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; +} + +button:focus-visible, +a:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; +} + +/* ============================================================ + Selection color + ============================================================ */ + +::selection { + background: var(--accent-soft); + color: var(--accent); +} + +/* ============================================================ + Scrollbar + ============================================================ */ + +::-webkit-scrollbar { + width: 8px; + height: 8px; +} + +::-webkit-scrollbar-track { + background: var(--bg-secondary); +} + +::-webkit-scrollbar-thumb { + background: var(--border); + border-radius: 4px; +} + +::-webkit-scrollbar-thumb:hover { + background: var(--border-focus); +} + +/* ============================================================ + Print + ============================================================ */ + +@media print { + .site-header, footer, .settings-popover, #backToTop, .htmx-indicator, .settings-trigger { + display: none !important; + } + + body { + background: #fff; + color: #000; + } + + .result { + break-inside: avoid; + border: 1px solid #ddd; + margin-bottom: 1rem; + } +} diff --git a/internal/views/templates/base.html b/internal/views/templates/base.html index 239e886..691dba2 100644 --- a/internal/views/templates/base.html +++ b/internal/views/templates/base.html @@ -1,6 +1,6 @@ {{define "base"}} - + @@ -13,31 +13,43 @@ - + - - -
+ +
{{template "content" .}}
+

Powered by kafka — a privacy-respecting, open metasearch engine

+ + + +
+ From 805e7ffdc2397b04ccdda172a6bca113872b8592 Mon Sep 17 00:00:00 2001 From: Franz Kafka Date: Sun, 22 Mar 2026 08:34:20 +0000 Subject: [PATCH 4/5] feat: add source_url config option for footer source link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thread source_url through: config.ServerConfig → Handler.sourceURL → PageData.SourceURL → template footer. Footer only shows Source link when source_url is set. --- cmd/kafka/main.go | 2 +- config.example.toml | 5 +++++ internal/config/config.go | 3 ++- internal/httpapi/handlers.go | 10 ++++++---- internal/views/templates/base.html | 2 +- internal/views/views.go | 5 +++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cmd/kafka/main.go b/cmd/kafka/main.go index f16aa96..cdc81b5 100644 --- a/cmd/kafka/main.go +++ b/cmd/kafka/main.go @@ -77,7 +77,7 @@ func main() { acSvc := autocomplete.NewService(cfg.Upstream.URL, cfg.HTTPTimeout()) - h := httpapi.NewHandler(svc, acSvc.Suggestions) + h := httpapi.NewHandler(svc, acSvc.Suggestions, cfg.Server.SourceURL) mux := http.NewServeMux() mux.HandleFunc("/", h.Index) diff --git a/config.example.toml b/config.example.toml index 34f60a6..042bb63 100644 --- a/config.example.toml +++ b/config.example.toml @@ -14,6 +14,11 @@ http_timeout = "10s" # Example: "https://search.example.com" base_url = "" +# Link to the source code (shown in footer as "Source" link) +# Defaults to the upstream kafka repo if not set. +# Example: "https://git.example.com/my-kafka-fork" +source_url = "" + [upstream] # URL of an upstream metasearch instance for unported engines (env: UPSTREAM_SEARXNG_URL) # Leave empty to run without an upstream proxy. diff --git a/internal/config/config.go b/internal/config/config.go index 2644c70..e5d1fbb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -40,7 +40,8 @@ type Config struct { type ServerConfig struct { Port int `toml:"port"` HTTPTimeout string `toml:"http_timeout"` - BaseURL string `toml:"base_url"` // Public URL for OpenSearch XML (e.g. "https://search.example.com") + BaseURL string `toml:"base_url"` // Public URL for OpenSearch XML (e.g. "https://search.example.com") + SourceURL string `toml:"source_url"` // Link to the source code (e.g. "https://git.example.com/fork/kafka") } type UpstreamConfig struct { diff --git a/internal/httpapi/handlers.go b/internal/httpapi/handlers.go index 9e62c1b..cc19b4b 100644 --- a/internal/httpapi/handlers.go +++ b/internal/httpapi/handlers.go @@ -30,12 +30,14 @@ import ( type Handler struct { searchSvc *search.Service autocompleteSvc func(ctx context.Context, query string) ([]string, error) + sourceURL string } -func NewHandler(searchSvc *search.Service, autocompleteSuggestions func(ctx context.Context, query string) ([]string, error)) *Handler { +func NewHandler(searchSvc *search.Service, autocompleteSuggestions func(ctx context.Context, query string) ([]string, error), sourceURL string) *Handler { return &Handler{ searchSvc: searchSvc, autocompleteSvc: autocompleteSuggestions, + sourceURL: sourceURL, } } @@ -51,7 +53,7 @@ func (h *Handler) Index(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - if err := views.RenderIndex(w); err != nil { + if err := views.RenderIndex(w, h.sourceURL); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } @@ -80,7 +82,7 @@ func (h *Handler) Search(w http.ResponseWriter, r *http.Request) { if err != nil { // For HTML, render error on the results page. if req.Format == contracts.FormatHTML || r.FormValue("format") == "html" { - pd := views.PageData{Query: r.FormValue("q")} + pd := views.PageData{SourceURL: h.sourceURL, Query: r.FormValue("q")} if views.IsHTMXRequest(r) { views.RenderSearchFragment(w, pd) } else { @@ -95,7 +97,7 @@ func (h *Handler) Search(w http.ResponseWriter, r *http.Request) { resp, err := h.searchSvc.Search(r.Context(), req) if err != nil { if req.Format == contracts.FormatHTML { - pd := views.PageData{Query: req.Query} + pd := views.PageData{SourceURL: h.sourceURL, Query: req.Query} if views.IsHTMXRequest(r) { views.RenderSearchFragment(w, pd) } else { diff --git a/internal/views/templates/base.html b/internal/views/templates/base.html index 5b58487..d2fec79 100644 --- a/internal/views/templates/base.html +++ b/internal/views/templates/base.html @@ -35,7 +35,7 @@
diff --git a/internal/views/views.go b/internal/views/views.go index 50cec56..4d7289c 100644 --- a/internal/views/views.go +++ b/internal/views/views.go @@ -35,6 +35,7 @@ var staticFS embed.FS // PageData holds all data passed to templates. type PageData struct { + SourceURL string Query string Pageno int PrevPage int @@ -187,9 +188,9 @@ func FromResponse(resp contracts.SearchResponse, query string, pageno int) PageD } // RenderIndex renders the homepage (search box only). -func RenderIndex(w http.ResponseWriter) error { +func RenderIndex(w http.ResponseWriter, sourceURL string) error { w.Header().Set("Content-Type", "text/html; charset=utf-8") - return tmplIndex.ExecuteTemplate(w, "base", PageData{ShowHeader: true}) + return tmplIndex.ExecuteTemplate(w, "base", PageData{ShowHeader: true, SourceURL: sourceURL}) } // RenderSearch renders the full search results page (with base layout). From 5b942a5fd6a0869130b63968719bcb6c8be6abd7 Mon Sep 17 00:00:00 2001 From: Franz Kafka Date: Sun, 22 Mar 2026 11:10:50 +0000 Subject: [PATCH 5/5] refactor: clean up verbose and redundant comments Trim or remove comments that: - State the obvious (function names already convey purpose) - Repeat what the code clearly shows - Are excessively long without adding value Keep comments that explain *why*, not *what*. --- internal/autocomplete/service.go | 5 +---- internal/contracts/main_result.go | 13 +------------ internal/contracts/types.go | 15 +++++---------- internal/engines/braveapi.go | 14 +++----------- internal/engines/factory.go | 5 ++--- internal/engines/google.go | 26 -------------------------- internal/engines/planner.go | 4 ---- internal/engines/qwant.go | 18 +----------------- internal/middleware/ratelimit.go | 11 ++--------- internal/search/merge.go | 5 ----- internal/search/types.go | 2 +- 11 files changed, 16 insertions(+), 102 deletions(-) diff --git a/internal/autocomplete/service.go b/internal/autocomplete/service.go index d6460f1..23473d5 100644 --- a/internal/autocomplete/service.go +++ b/internal/autocomplete/service.go @@ -27,8 +27,7 @@ import ( "time" ) -// Service fetches search suggestions from an upstream metasearch instance -// or falls back to Wikipedia's OpenSearch API. +// Service fetches search suggestions from upstream or Wikipedia OpenSearch. type Service struct { upstreamURL string http *http.Client @@ -44,7 +43,6 @@ func NewService(upstreamURL string, timeout time.Duration) *Service { } } -// Suggestions returns search suggestions for the given query. func (s *Service) Suggestions(ctx context.Context, query string) ([]string, error) { if strings.TrimSpace(query) == "" { return nil, nil @@ -56,7 +54,6 @@ func (s *Service) Suggestions(ctx context.Context, query string) ([]string, erro return s.wikipediaSuggestions(ctx, query) } -// upstreamSuggestions proxies to an upstream /autocompleter endpoint. func (s *Service) upstreamSuggestions(ctx context.Context, query string) ([]string, error) { u := s.upstreamURL + "/autocompleter?" + url.Values{"q": {query}}.Encode() req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil) diff --git a/internal/contracts/main_result.go b/internal/contracts/main_result.go index c804f6b..02fb29c 100644 --- a/internal/contracts/main_result.go +++ b/internal/contracts/main_result.go @@ -22,14 +22,10 @@ import ( ) // MainResult represents one element of the `results` array. -// -// The API returns many additional keys beyond what templates use. To keep the -// contract stable for proxying/merging, we preserve all unknown keys in -// `raw` and re-emit them via MarshalJSON. +// Unknown keys are preserved in `raw` and re-emitted via MarshalJSON. type MainResult struct { raw map[string]any - // Common fields used by templates (RSS uses: title, url, content, pubdate). Template string `json:"template"` Title string `json:"title"` Content string `json:"content"` @@ -45,17 +41,13 @@ type MainResult struct { Positions []int `json:"positions"` Engines []string `json:"engines"` - // These fields exist in the MainResult base; keep them so downstream - // callers can generate richer output later. OpenGroup bool `json:"open_group"` CloseGroup bool `json:"close_group"` - // parsed_url is emitted as a tuple; we preserve it as-is. ParsedURL any `json:"parsed_url"` } func (mr *MainResult) UnmarshalJSON(data []byte) error { - // Preserve the full object. dec := json.NewDecoder(bytes.NewReader(data)) dec.UseNumber() @@ -66,7 +58,6 @@ func (mr *MainResult) UnmarshalJSON(data []byte) error { mr.raw = m - // Fill the typed/common fields (best-effort; don't fail if types differ). mr.Template = stringOrEmpty(m["template"]) mr.Title = stringOrEmpty(m["title"]) mr.Content = stringOrEmpty(m["content"]) @@ -104,12 +95,10 @@ func (mr *MainResult) UnmarshalJSON(data []byte) error { } func (mr MainResult) MarshalJSON() ([]byte, error) { - // If we came from upstream JSON, preserve all keys exactly. if mr.raw != nil { return json.Marshal(mr.raw) } - // Otherwise, marshal the known fields. m := map[string]any{ "template": mr.Template, "title": mr.Title, diff --git a/internal/contracts/types.go b/internal/contracts/types.go index 279ce57..40ed6bc 100644 --- a/internal/contracts/types.go +++ b/internal/contracts/types.go @@ -20,18 +20,15 @@ package contracts type OutputFormat string const ( - FormatHTML OutputFormat = "html" // accepted for compatibility (not yet implemented) + FormatHTML OutputFormat = "html" // accepted for compatibility FormatJSON OutputFormat = "json" FormatCSV OutputFormat = "csv" FormatRSS OutputFormat = "rss" ) type SearchRequest struct { - // Format is what the client requested via `format=...`. - Format OutputFormat - - Query string - + Format OutputFormat + Query string Pageno int Safesearch int TimeRange *string @@ -39,16 +36,14 @@ type SearchRequest struct { TimeoutLimit *float64 Language string - // Engines and categories are used for deciding which engines run locally vs are proxied. - // For now, engines can be supplied directly via the `engines` form parameter. + // Engines and categories decide which engines run locally vs proxy to upstream. Engines []string Categories []string // EngineData matches the `engine_data--=` parameters. EngineData map[string]map[string]string - // AccessToken is an optional request token used to gate paid/limited engines. - // It is not part of the upstream JSON schema; it only influences local engines. + // AccessToken gates paid/limited engines. Not part of upstream JSON schema. AccessToken string } diff --git a/internal/engines/braveapi.go b/internal/engines/braveapi.go index 641a1d4..81d1f3b 100644 --- a/internal/engines/braveapi.go +++ b/internal/engines/braveapi.go @@ -30,13 +30,9 @@ import ( "github.com/metamorphosis-dev/kafka/internal/contracts" ) -// BraveEngine implements the `braveapi` engine (Brave Web Search API). -// -// Config / gating: -// - BRAVE_API_KEY: required to call Brave -// - BRAVE_ACCESS_TOKEN (optional): if set, the request must include a token -// that matches the env var (via Authorization Bearer, X-Search-Token, -// X-Brave-Access-Token, or form field `token`). +// BraveEngine implements the Brave Web Search API. +// Required: BRAVE_API_KEY env var or config. +// Optional: BRAVE_ACCESS_TOKEN to gate requests. type BraveEngine struct { client *http.Client apiKey string @@ -51,8 +47,6 @@ func (e *BraveEngine) Search(ctx context.Context, req contracts.SearchRequest) ( return contracts.SearchResponse{}, errors.New("brave engine not initialized") } - // Gate / config checks should not be treated as fatal errors; the reference - // implementation treats misconfigured engines as unresponsive. if strings.TrimSpace(e.apiKey) == "" { return contracts.SearchResponse{ Query: req.Query, @@ -109,8 +103,6 @@ func (e *BraveEngine) Search(ctx context.Context, req contracts.SearchRequest) ( } } - // The reference implementation checks `if params["safesearch"]:` which treats any - // non-zero (moderate/strict) as strict. if req.Safesearch > 0 { args.Set("safesearch", "strict") } diff --git a/internal/engines/factory.go b/internal/engines/factory.go index ddaeb06..528dcb7 100644 --- a/internal/engines/factory.go +++ b/internal/engines/factory.go @@ -24,9 +24,8 @@ import ( "github.com/metamorphosis-dev/kafka/internal/config" ) -// NewDefaultPortedEngines returns the starter set of Go-native engines. -// The service can swap/extend this registry later as more engines are ported. -// If cfg is nil, falls back to reading API keys from environment variables. +// NewDefaultPortedEngines returns the Go-native engine registry. +// If cfg is nil, API keys fall back to environment variables. func NewDefaultPortedEngines(client *http.Client, cfg *config.Config) map[string]Engine { if client == nil { client = &http.Client{Timeout: 10 * time.Second} diff --git a/internal/engines/google.go b/internal/engines/google.go index 0119a98..8563829 100644 --- a/internal/engines/google.go +++ b/internal/engines/google.go @@ -57,7 +57,6 @@ func (e *GoogleEngine) Search(ctx context.Context, req contracts.SearchRequest) start := (req.Pageno - 1) * 10 query := url.QueryEscape(req.Query) - // Build URL like SearXNG does. u := fmt.Sprintf( "https://www.google.com/search?q=%s&filter=0&start=%d&hl=%s&lr=%s&safe=%s", query, @@ -118,7 +117,6 @@ func (e *GoogleEngine) Search(ctx context.Context, req contracts.SearchRequest) }, nil } -// detectGoogleSorry returns true if the response is a Google block/CAPTCHA page. func detectGoogleSorry(resp *http.Response) bool { if resp.Request != nil { if resp.Request.URL.Host == "sorry.google.com" || strings.HasPrefix(resp.Request.URL.Path, "/sorry") { @@ -128,16 +126,9 @@ func detectGoogleSorry(resp *http.Response) bool { return false } -// parseGoogleResults extracts search results from Google's HTML. -// Uses the same selectors as SearXNG: div.MjjYud for result containers. func parseGoogleResults(body, query string) []contracts.MainResult { var results []contracts.MainResult - // SearXNG selector: .//div[contains(@class, "MjjYud")] - // Each result block contains a title link and snippet. - // We simulate the XPath matching with regex-based extraction. - - // Find all MjjYud div blocks. mjjPattern := regexp.MustCompile(`]*class="[^"]*MjjYud[^"]*"[^>]*>(.*?)\s*(?=]*class="[^"]*MjjYud|$)`) matches := mjjPattern.FindAllStringSubmatch(body, -1) @@ -147,15 +138,12 @@ func parseGoogleResults(body, query string) []contracts.MainResult { } block := match[1] - // Extract title and URL from the result link. - // Pattern: TITLE urlPattern := regexp.MustCompile(`]+href="(/url\?q=[^"&]+)`) urlMatch := urlPattern.FindStringSubmatch(block) if len(urlMatch) < 2 { continue } rawURL := urlMatch[1] - // Remove /url?q= prefix and decode. actualURL := strings.TrimPrefix(rawURL, "/url?q=") if amp := strings.Index(actualURL, "&"); amp != -1 { actualURL = actualURL[:amp] @@ -168,14 +156,12 @@ func parseGoogleResults(body, query string) []contracts.MainResult { continue } - // Extract title from the title tag. titlePattern := regexp.MustCompile(`]*class="[^"]*qrStP[^"]*"[^>]*>([^<]+)`) titleMatch := titlePattern.FindStringSubmatch(block) title := query if len(titleMatch) >= 2 { title = stripTags(titleMatch[1]) } else { - // Fallback: extract visible text from an with data-title or role="link" linkTitlePattern := regexp.MustCompile(`]+role="link"[^>]*>([^<]+)<`) ltMatch := linkTitlePattern.FindStringSubmatch(block) if len(ltMatch) >= 2 { @@ -183,7 +169,6 @@ func parseGoogleResults(body, query string) []contracts.MainResult { } } - // Extract snippet from data-sncf divs (SearXNG's approach). snippet := extractGoogleSnippet(block) urlPtr := actualURL @@ -202,10 +187,7 @@ func parseGoogleResults(body, query string) []contracts.MainResult { return results } -// extractGoogleSnippet extracts the snippet text from a Google result block. func extractGoogleSnippet(block string) string { - // Google's snippets live in divs with data-sncf attribute. - // SearXNG looks for: .//div[contains(@data-sncf, "1")] snippetPattern := regexp.MustCompile(`]+data-sncf="1"[^>]*>(.*?)`) matches := snippetPattern.FindAllStringSubmatch(block, -1) var parts []string @@ -221,10 +203,8 @@ func extractGoogleSnippet(block string) string { return strings.Join(parts, " ") } -// extractGoogleSuggestions extracts search suggestions from Google result cards. func extractGoogleSuggestions(body string) []string { var suggestions []string - // SearXNG xpath: //div[contains(@class, "ouy7Mc")]//a suggestionPattern := regexp.MustCompile(`(?s)]*class="[^"]*ouy7Mc[^"]*"[^>]*>.*?]*>([^<]+)`) matches := suggestionPattern.FindAllStringSubmatch(body, -1) seen := map[string]bool{} @@ -241,8 +221,6 @@ func extractGoogleSuggestions(body string) []string { return suggestions } -// googleHL maps SearXNG locale to Google hl (host language) parameter. -// e.g. "en-US" -> "en-US" func googleHL(lang string) string { lang = strings.ToLower(strings.TrimSpace(lang)) if lang == "" || lang == "auto" { @@ -251,8 +229,6 @@ func googleHL(lang string) string { return lang } -// googleUILanguage maps SearXNG language to Google lr (language restrict) parameter. -// e.g. "en" -> "lang_en", "de" -> "lang_de" func googleUILanguage(lang string) string { lang = strings.ToLower(strings.Split(lang, "-")[0]) if lang == "" || lang == "auto" { @@ -261,7 +237,6 @@ func googleUILanguage(lang string) string { return "lang_" + lang } -// googleSafeSearchLevel maps safesearch (0-2) to Google's safe parameter. func googleSafeSearchLevel(safesearch int) string { switch safesearch { case 0: @@ -275,7 +250,6 @@ func googleSafeSearchLevel(safesearch int) string { } } -// stripTags removes HTML tags from a string. func stripTags(s string) string { stripper := regexp.MustCompile(`<[^>]*>`) s = stripper.ReplaceAllString(s, "") diff --git a/internal/engines/planner.go b/internal/engines/planner.go index 295f458..9616a4b 100644 --- a/internal/engines/planner.go +++ b/internal/engines/planner.go @@ -95,9 +95,6 @@ func (p *Planner) Plan(req contracts.SearchRequest) (localEngines, upstreamEngin } func inferFromCategories(categories []string) []string { - // Minimal mapping for the initial porting subset. - // This mirrors the idea of selecting from engine categories without - // embedding the whole engine registry. set := map[string]bool{} for _, c := range categories { switch strings.TrimSpace(strings.ToLower(c)) { @@ -131,7 +128,6 @@ func inferFromCategories(categories []string) []string { } func sortByOrder(list []string, order map[string]int) { - // simple insertion sort (list is tiny) for i := 1; i < len(list); i++ { j := i for j > 0 && order[list[j-1]] > order[list[j]] { diff --git a/internal/engines/qwant.go b/internal/engines/qwant.go index 77f7b70..e15d4f2 100644 --- a/internal/engines/qwant.go +++ b/internal/engines/qwant.go @@ -30,11 +30,7 @@ import ( "github.com/PuerkitoBio/goquery" ) -// QwantEngine implements a `qwant` (web) adapter using -// Qwant v3 endpoint: https://api.qwant.com/v3/search/web. -// -// Qwant's API is not fully documented; this implements parsing logic -// for the `web` category. +// QwantEngine implements the Qwant v3 API (web and web-lite modes). type QwantEngine struct { client *http.Client category string // "web" (JSON API) or "web-lite" (HTML fallback) @@ -53,8 +49,6 @@ func (e *QwantEngine) Search(ctx context.Context, req contracts.SearchRequest) ( return contracts.SearchResponse{Query: req.Query}, nil } - // For API parity we use web defaults: count=10, offset=(pageno-1)*count. - // The engine's config field exists so we can expand to news/images/videos later. count := e.resultsPerPage if count <= 0 { count = 10 @@ -271,9 +265,7 @@ func (e *QwantEngine) searchWebLite(ctx context.Context, req contracts.SearchReq results := make([]contracts.MainResult, 0) seen := map[string]bool{} - // Pattern 1: legacy/known qwant-lite structure. doc.Find("section article").Each(func(_ int, item *goquery.Selection) { - // ignore randomly interspersed advertising adds if item.Find("span.tooltip").Length() > 0 { return } @@ -307,19 +299,14 @@ func (e *QwantEngine) searchWebLite(ctx context.Context, req contracts.SearchReq }) }) - // Pattern 2: broader fallback for updated lite markup: - // any article/list item/div block containing an external anchor. - // We keep this conservative by requiring non-empty title + URL. doc.Find("article, li, div").Each(func(_ int, item *goquery.Selection) { if len(results) >= 20 { return } - // Skip ad-like blocks in fallback pass too. if item.Find("span.tooltip").Length() > 0 { return } - // Skip obvious nav/footer blocks. classAttr, _ := item.Attr("class") classLower := strings.ToLower(classAttr) if strings.Contains(classLower, "nav") || strings.Contains(classLower, "footer") { @@ -368,13 +355,10 @@ func (e *QwantEngine) searchWebLite(ctx context.Context, req contracts.SearchReq } seen[href] = true - // Best-effort snippet extraction from nearby paragraph/span text. content := strings.TrimSpace(item.Find("p").First().Text()) if content == "" { content = strings.TrimSpace(item.Find("span").First().Text()) } - // If there is no snippet, still keep clearly external result links. - // Qwant-lite frequently omits rich snippets for some entries. u := href results = append(results, contracts.MainResult{ diff --git a/internal/middleware/ratelimit.go b/internal/middleware/ratelimit.go index 899029f..78774f2 100644 --- a/internal/middleware/ratelimit.go +++ b/internal/middleware/ratelimit.go @@ -27,19 +27,12 @@ import ( "log/slog" ) -// RateLimitConfig controls per-IP rate limiting using a sliding window counter. type RateLimitConfig struct { - // Requests is the max number of requests allowed per window. - Requests int - // Window is the time window duration (e.g. "1m"). - Window time.Duration - // CleanupInterval is how often stale entries are purged (default: 5m). + Requests int + Window time.Duration CleanupInterval time.Duration } -// RateLimit returns a middleware that limits requests per IP address. -// Uses an in-memory sliding window counter. When the limit is exceeded, -// responds with HTTP 429 and a Retry-After header. func RateLimit(cfg RateLimitConfig, logger *slog.Logger) func(http.Handler) http.Handler { requests := cfg.Requests if requests <= 0 { diff --git a/internal/search/merge.go b/internal/search/merge.go index 7be7353..0e8a15a 100644 --- a/internal/search/merge.go +++ b/internal/search/merge.go @@ -25,11 +25,6 @@ import ( ) // MergeResponses merges multiple compatible JSON responses. -// -// MVP merge semantics: -// - results are concatenated with a simple de-dup key (engine|title|url) -// - suggestions/corrections are de-duplicated as sets -// - answers/infoboxes/unresponsive_engines are concatenated (best-effort) func MergeResponses(responses []contracts.SearchResponse) contracts.SearchResponse { var merged contracts.SearchResponse diff --git a/internal/search/types.go b/internal/search/types.go index 9665dde..89b323d 100644 --- a/internal/search/types.go +++ b/internal/search/types.go @@ -23,7 +23,7 @@ import "github.com/metamorphosis-dev/kafka/internal/contracts" type OutputFormat = contracts.OutputFormat const ( - FormatHTML = contracts.FormatHTML // accepted for compatibility (not yet implemented) + FormatHTML = contracts.FormatHTML // accepted for compatibility FormatJSON = contracts.FormatJSON FormatCSV = contracts.FormatCSV FormatRSS = contracts.FormatRSS