--- /** * Sneaker van de Dag — Shows the best deal of the day with a countdown timer. * Picks from the top 7 biggest discounts, rotating daily. */ import { query } from '../lib/db'; const { rows } = await query(` SELECT p.id, p.slug, p.name, p.brand, p.colorway, p.cutout_image_url, p.image_url, MIN(po.price)::float as current_price, po.original_price::float as original_price, ROUND(((po.original_price - MIN(po.price)) / po.original_price * 100))::int as discount_pct, COUNT(DISTINCT po.feed_id)::int as shop_count FROM products p JOIN product_offers po ON po.product_id = p.id AND po.in_stock = true WHERE p.is_sneaker = true AND po.original_price IS NOT NULL AND po.original_price > po.price AND p.image_url IS NOT NULL AND p.image_url != '' GROUP BY p.id, p.slug, p.name, p.brand, p.colorway, p.cutout_image_url, p.image_url, po.original_price HAVING MIN(po.price) < po.original_price * 0.75 ORDER BY (po.original_price - MIN(po.price)) DESC LIMIT 7 `); // Rotate daily: pick a different deal from the top 7 each day const dayOfYear = Math.floor((Date.now() - new Date(new Date().getFullYear(), 0, 0).getTime()) / 86400000); const deal = rows[dayOfYear % Math.max(rows.length, 1)]; if (!deal) return; // Always use the API image proxy — it handles caching, fallback, and broken URLs const imageUrl = `/api/img/${deal.id}`; const saving = (deal.original_price - deal.current_price).toFixed(2).replace('.', ','); ---
Deal vd dag
{`${deal.brand}
-{deal.discount_pct}%

{deal.brand}

{deal.name}

{deal.colorway}

€{deal.current_price.toFixed(2).replace('.', ',')} €{deal.original_price.toFixed(2).replace('.', ',')} Bespaar €{saving}

Beschikbaar bij {deal.shop_count} shop{deal.shop_count > 1 ? 's' : ''}

Bekijk deal