Author SHA1 Message Date
ahp 57be6ca2ce feat(web): dark mode with an OS-preference default and a header toggle
- ThemeToggle (sun/moon) in the site header; an explicit choice is
  saved in localStorage, otherwise prefers-color-scheme decides and OS
  changes are followed live
- an inline <head> script sets html.dark before first paint, so there
  is no flash of the wrong theme; suppressHydrationWarning on <html>
  covers the class it adds
- globals.css remaps the Tailwind palette under html.dark (stone
  inverted, accent tints darkened, text-only accent shades lifted)
  instead of adding dark: to ~230 utilities across 8 files; solid
  teal/red keep their value for white-on-accent buttons, with targeted
  overrides where they double as a text colour
- per-scheme themeColor; fa/en labels for the toggle
2026-11-26 16:25:44 +03:30
13 changed files with 173 additions and 35 deletions

No files matched your search

-1
View File
@@ -1,6 +1,5 @@
# Sokhan configuration
# Copy this file to .env and adjust the values.
# For docker compose, copy it to deploy/.env instead.
# Every variable below has a working default for local development.
# --- Core ---
+5 -13
View File
@@ -5,19 +5,6 @@ The format follows [Keep a Changelog](https://keepachangelog.com/) and the proje
## [Unreleased]
### Fixed
- Compose: the Whisper model cache now lives on the `sokhan-data` volume
(`HF_HOME=/data/huggingface`). Previously it sat in the container's own
filesystem, so every recreate (`down`/`up`, `--build`, a new image)
re-downloaded the weights — and transcription failed outright where the
Hugging Face Hub is unreachable.
- Compose: the postgres healthcheck probes the configured `POSTGRES_USER` and
`POSTGRES_DB` instead of a hardcoded `sokhan`.
- Quickstart (both READMEs) and `.env.example` now say to copy the env file to
`deploy/.env`; the missing-password error names that path too. Copying it to
the repo root left `POSTGRES_PASSWORD` unset for compose.
### Added
- **Persian accuracy stack (v2)** — measured on the 12-clip Common Voice
@@ -50,6 +37,11 @@ The format follows [Keep a Changelog](https://keepachangelog.com/) and the proje
fine-tuned 0.75 / medium 0.5625); the weekly benchmark workflow now
guards `small` **and** `medium`; regression-gate test updated to the
committed baseline.
- Dashboard dark mode: a sun/moon toggle in the header, defaulting to the OS
preference until the user picks one (saved in localStorage, applied before
first paint so there is no flash). Implemented by remapping the Tailwind
palette under `html.dark` in `globals.css`, so existing pages needed no
per-class changes.
- Brand refresh: a hero banner in both READMEs (`docs/assets/banner.png`),
a redesigned 1280x640 social preview (`docs/assets/social-preview.png` —
upload it once in Settings → General → Social preview) and a 512px app
+1 -5
View File
@@ -145,8 +145,6 @@ faster-whisper، یک ورکر Celery، یک داشبورد Next.js که فار
```bash
git clone https://github.com/Abolfazlrwm/sokhan.git
cd sokhan
cp .env.example deploy/.env # compose فایل .env کنار فایل compose را می‌خواند
# در deploy/.env مقدار POSTGRES_PASSWORD را یک رمز طولانی و تصادفی بگذارید
docker compose -f deploy/docker-compose.yml up -d --build
```
@@ -154,9 +152,7 @@ docker compose -f deploy/docker-compose.yml up -d --build
- API و مستندات: http://localhost:8000/docs
ورکر مدل Whisper تنظیم‌شده را در اولین رونویسی دانلود می‌کند
(`WHISPER_MODEL_SIZE`، پیش‌فرض `small`) و آن را روی ولوم `sokhan-data`
(`HF_HOME=/data/huggingface`) نگه می‌دارد، پس ساخت دوبارهٔ کانتینرها مدل را
دوباره دانلود نمی‌کند. برای فعال‌کردن خلاصه‌سازی،
(`WHISPER_MODEL_SIZE`، پیش‌فرض `small`). برای فعال‌کردن خلاصه‌سازی،
`SUMMARY_ENABLED=true` و متغیرهای LLM خود را در فایل `.env` کنار
`docker-compose.yml` بگذارید. برای اعمال مهاجرت‌های اسکیما به‌صورت دستی:
+1 -5
View File
@@ -143,8 +143,6 @@ default — a GPU is not required.
```bash
git clone https://github.com/Abolfazlrwm/sokhan.git
cd sokhan
cp .env.example deploy/.env # compose reads the .env next to the compose file
# edit deploy/.env and set POSTGRES_PASSWORD to a long random value
docker compose -f deploy/docker-compose.yml up -d --build
```
@@ -152,9 +150,7 @@ docker compose -f deploy/docker-compose.yml up -d --build
- API and docs: http://localhost:8000/docs
The worker downloads the configured Whisper model on first transcription
(`WHISPER_MODEL_SIZE`, default `small`) and caches it on the `sokhan-data`
volume (`HF_HOME=/data/huggingface`), so recreating the containers does not
download it again. To enable summaries, set
(`WHISPER_MODEL_SIZE`, default `small`). To enable summaries, set
`SUMMARY_ENABLED=true` and your LLM variables in a `.env` file next to
`docker-compose.yml`. To apply schema migrations manually:
+3 -3
View File
@@ -12,9 +12,9 @@ COPY alembic ./alembic
RUN pip install --no-cache-dir .
RUN useradd --system --uid 1000 --create-home appuser \
&& mkdir -p /data/audio \
&& chown -R appuser:appuser /data
# Non-root runtime user; uvicorn binds 8000 (unprivileged) and the app keeps
# no local writable state (postgres via DATABASE_URL).
RUN useradd --system --uid 1000 --create-home appuser
USER appuser
EXPOSE 8000
+3 -4
View File
@@ -5,12 +5,12 @@ services:
POSTGRES_USER: ${POSTGRES_USER:-sokhan}
# Required on purpose: shipping a default credential means every
# deployment that forgets the .env runs an open database.
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set (cp .env.example deploy/.env and edit it)}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set (see .env.example)}
POSTGRES_DB: ${POSTGRES_DB:-sokhan}
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
test: ["CMD-SHELL", "pg_isready -U sokhan"]
interval: 5s
timeout: 3s
retries: 10
@@ -33,11 +33,10 @@ services:
build:
context: ../backend
environment: &backend-env
DATABASE_URL: postgresql+psycopg://${POSTGRES_USER:-sokhan}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set (cp .env.example deploy/.env and edit it)}@postgres:5432/${POSTGRES_DB:-sokhan}
DATABASE_URL: postgresql+psycopg://${POSTGRES_USER:-sokhan}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set (see .env.example)}@postgres:5432/${POSTGRES_DB:-sokhan}
REDIS_URL: redis://redis:6379/0
CELERY_ENABLED: "true"
DATA_DIR: /data
HF_HOME: /data/huggingface
SOKHAN_CORS_ORIGINS: ${SOKHAN_CORS_ORIGINS:-}
WHISPER_MODEL_SIZE: ${WHISPER_MODEL_SIZE:-medium}
WHISPER_DEVICE: ${WHISPER_DEVICE:-cpu}
+3 -1
View File
@@ -15,7 +15,9 @@
"new": "New transcription",
"archive": "Archive",
"switchToEn": "English",
"switchToFa": "فارسی"
"switchToFa": "فارسی",
"themeToDark": "Switch to dark theme",
"themeToLight": "Switch to light theme"
},
"landing": {
"headline": "From speech to text, in moments",
+3 -1
View File
@@ -15,7 +15,9 @@
"new": "رونویسی تازه",
"archive": "آرشیو",
"switchToEn": "English",
"switchToFa": "فارسی"
"switchToFa": "فارسی",
"themeToDark": "تم تیره",
"themeToLight": "تم روشن"
},
"landing": {
"headline": "از گفتار به متن، در چند لحظه",
+9 -2
View File
@@ -5,6 +5,7 @@ import { getTranslations, setRequestLocale } from "next-intl/server";
import localFont from "next/font/local";
import { routing } from "@/i18n/routing";
import { SiteHeader } from "@/components/site-header";
import { themeInitScript } from "@/lib/theme";
import "../globals.css";
// Fonts are self-hosted (see src/fonts/README.txt): builds must never depend
@@ -47,7 +48,10 @@ export async function generateMetadata({
}
export const viewport: Viewport = {
themeColor: "#0f766e",
themeColor: [
{ media: "(prefers-color-scheme: light)", color: "#0f766e" },
{ media: "(prefers-color-scheme: dark)", color: "#134e4a" },
],
};
export default async function LocaleLayout({
@@ -64,7 +68,10 @@ export default async function LocaleLayout({
const t = await getTranslations("common");
return (
<html lang={locale} dir={locale === "fa" ? "rtl" : "ltr"}>
<html lang={locale} dir={locale === "fa" ? "rtl" : "ltr"} suppressHydrationWarning>
<head>
<script dangerouslySetInnerHTML={{ __html: themeInitScript }} />
</head>
<body
className={`${vazirmatn.variable} ${inter.variable} flex min-h-screen flex-col bg-stone-50 text-stone-900 antialiased`}
>
+74
View File
@@ -1,5 +1,7 @@
@import "tailwindcss";
@custom-variant dark (&:where(.dark, .dark *));
@theme {
--font-vazir: var(--font-vazirmatn, Vazirmatn), var(--font-inter, Inter), ui-sans-serif,
system-ui, sans-serif;
@@ -21,3 +23,75 @@ html[lang="en"] body {
background-color: #99f6e4;
color: #134e4a;
}
html.dark {
color-scheme: dark;
--color-stone-50: oklch(14.7% 0.004 49.25);
--color-stone-100: oklch(26.8% 0.007 34.298);
--color-stone-200: oklch(30% 0.007 34.298);
--color-stone-300: oklch(40% 0.01 67.558);
--color-stone-400: oklch(55.3% 0.013 58.071);
--color-stone-500: oklch(70.9% 0.01 56.259);
--color-stone-600: oklch(80% 0.005 56.366);
--color-stone-700: oklch(86.9% 0.005 56.366);
--color-stone-800: oklch(92.3% 0.003 48.717);
--color-stone-900: oklch(97% 0.001 106.424);
--color-stone-950: oklch(98.5% 0.001 106.423);
--color-teal-50: oklch(27.7% 0.046 192.524);
--color-teal-100: oklch(32% 0.055 190);
--color-teal-200: oklch(38.6% 0.063 188.416);
--color-teal-800: oklch(85.5% 0.138 181.071);
--color-teal-900: oklch(91% 0.096 180.426);
--color-teal-950: oklch(95.3% 0.051 180.801);
--color-red-50: oklch(25.8% 0.092 26.042);
--color-red-100: oklch(30% 0.11 26);
--color-red-200: oklch(39.6% 0.141 25.723);
--color-red-700: oklch(80.8% 0.114 19.571);
--color-red-800: oklch(88.5% 0.062 18.334);
--color-red-900: oklch(93.6% 0.032 17.717);
--color-amber-100: oklch(27.9% 0.077 45.635);
--color-amber-800: oklch(92.4% 0.12 95.746);
--color-emerald-100: oklch(26.2% 0.051 172.552);
--color-emerald-800: oklch(90.5% 0.093 164.15);
--sokhan-surface: oklch(19% 0.005 56);
}
html.dark body {
background-color: var(--color-stone-50);
color: var(--color-stone-900);
}
html.dark ::selection {
background-color: #115e59;
color: #f0fdfa;
}
html.dark .bg-white {
background-color: var(--sokhan-surface);
}
html.dark .bg-white\/90 {
background-color: color-mix(in oklab, var(--sokhan-surface) 90%, transparent);
}
html.dark .supports-\[backdrop-filter\]\:bg-white\/75 {
@supports (backdrop-filter: var(--tw)) {
background-color: color-mix(in oklab, var(--sokhan-surface) 75%, transparent);
}
}
html.dark .text-teal-600,
html.dark .text-teal-700 {
color: oklch(77.7% 0.152 181.912);
}
html.dark .text-teal-700\/60 {
color: color-mix(in oklab, oklch(77.7% 0.152 181.912) 60%, transparent);
}
html.dark * {
--tw-ring-offset-color: var(--sokhan-surface);
}
+2
View File
@@ -3,6 +3,7 @@
import { useLocale, useTranslations } from "next-intl";
import { AudioLines } from "lucide-react";
import { Link, usePathname, useRouter } from "@/i18n/navigation";
import { ThemeToggle } from "@/components/theme-toggle";
export function SiteHeader() {
const t = useTranslations("nav");
@@ -60,6 +61,7 @@ export function SiteHeader() {
>
{otherLocale === "en" ? "EN" : "فا"}
</button>
<ThemeToggle />
</nav>
</div>
</header>
+64
View File
@@ -0,0 +1,64 @@
"use client";
import { useEffect, useState } from "react";
import { useTranslations } from "next-intl";
import { Moon, Sun } from "lucide-react";
import { THEME_STORAGE_KEY, type Theme } from "@/lib/theme";
function applyTheme(theme: Theme) {
document.documentElement.classList.toggle("dark", theme === "dark");
}
export function ThemeToggle() {
const t = useTranslations("nav");
const [theme, setTheme] = useState<Theme | null>(null);
useEffect(() => {
setTheme(document.documentElement.classList.contains("dark") ? "dark" : "light");
const media = window.matchMedia("(prefers-color-scheme: dark)");
const onChange = (event: MediaQueryListEvent) => {
let saved: string | null = null;
try {
saved = window.localStorage.getItem(THEME_STORAGE_KEY);
} catch {
}
if (saved === "light" || saved === "dark") return;
const next: Theme = event.matches ? "dark" : "light";
applyTheme(next);
setTheme(next);
};
media.addEventListener("change", onChange);
return () => media.removeEventListener("change", onChange);
}, []);
const isDark = theme === "dark";
function toggle() {
const next: Theme = isDark ? "light" : "dark";
applyTheme(next);
setTheme(next);
try {
window.localStorage.setItem(THEME_STORAGE_KEY, next);
} catch {
}
}
const label = isDark ? t("themeToLight") : t("themeToDark");
return (
<button
type="button"
onClick={toggle}
aria-label={label}
title={label}
className="flex h-9 w-9 items-center justify-center rounded-lg border border-stone-300 text-stone-700 transition-colors hover:border-teal-700 hover:text-teal-800 focus-visible:ring-2 focus-visible:ring-teal-700"
>
{isDark ? (
<Sun className="h-4 w-4" aria-hidden="true" />
) : (
<Moon className="h-4 w-4" aria-hidden="true" />
)}
</button>
);
}
+5
View File
@@ -0,0 +1,5 @@
export const THEME_STORAGE_KEY = "sokhan-theme";
export type Theme = "light" | "dark";
export const themeInitScript = `(function(){try{var t=localStorage.getItem("${THEME_STORAGE_KEY}");if(t!=="light"&&t!=="dark"){t=matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}document.documentElement.classList.toggle("dark",t==="dark")}catch(e){}})();`;