惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
月光博客
月光博客
D
DataBreaches.Net
L
LangChain Blog
美团技术团队
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
阮一峰的网络日志
阮一峰的网络日志
Y
Y Combinator Blog
I
InfoQ
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
博客园 - 三生石上(FineUI控件)
腾讯CDC
Martin Fowler
Martin Fowler

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building a 100-question Rice Purity Test with Next.js: pe...
hb lai · 2026-06-24 · via DEV Community

hb lai

I shipped a small side project last week, a Rice Purity Test, and a couple of the build details turned out more interesting than the quiz itself. Two in particular: making the result screen recolor itself based on your score, and exporting a share card to PNG entirely in the browser. Notes below in case they save someone an hour.

The setup

It's a Next.js 16 app on the App Router, deployed to Cloudflare Workers via OpenNext. The quiz is one client component (an "island") sitting inside otherwise static, server-rendered pages, so the SEO content stays fast and only the interactive part hydrates. 100 checkbox questions; your score is 100 minus whatever you tick.

Persona-adaptive theming

This was the fun part. Instead of one result screen, the page picks a colour identity from your score band and drives everything off a single CSS custom property.

:root { --persona: var(--sage); }      /* high score, reserved */
[data-band="wild"] { --persona: var(--crimson); }  /* low score */

The result component sets a data-band attribute plus the accent colour, and the card background, the borders, even the shadow tint all follow from --persona. No conditional class soup. Ten bands, one variable.

const band = bandForScore(score);   // 0..9
return <section data-band={band.key} style={{ "--persona": band.color }}>...</section>;

Setting a CSS var inline in React like that is underused. You compute a theme value in JS and hand it straight to plain CSS, no styled-components, no re-render storm.

Exporting the share card as a PNG

People want to post their score, so the card has to become an image. I used html-to-image and dynamic-imported it so it never touches the initial bundle:

async function savePng(node) {
  await document.fonts.ready;                 // gotcha #1
  const { toPng } = await import("html-to-image");
  const url = await toPng(node, { pixelRatio: 2, cacheBust: true });  // gotcha #2
  const a = document.createElement("a");
  a.href = url; a.download = "rice-purity-score.png"; a.click();
}

Two things ate that hour. Web fonts must be fully loaded before you rasterize or the card renders in a fallback font, hence await document.fonts.ready. And the default export looks soft on retina, so pixelRatio: 2.

i18n without moving indexed URLs

I added five languages after launch. English stays at the root (unprefixed) so nothing already indexed moves; other locales get a prefix (/es, /pt, and so on). One dictionary file per locale, all matching the same TypeScript Dict shape, and the client quiz reads the dict as plain serializable data. hreflang and canonical both generate from a single LOCALES array, so adding a language is basically: write the dict, append the code, deploy.

If you want to poke at the finished thing, it's live at ricepuritytest.art, and the score-meaning breakdown is where those band colours come from. Happy to get into any of the build details in the comments.