llgame — quiz and games portal built with Vue 3 + Vite, using data/quiz.js and data/games.js as data sources. Brand constants live in src/config/site.js.
| Route | Description |
|---|---|
/quiz |
Quiz card grid (23 quizzes) |
/quiz/:id |
Quiz play — questions, 2×2 options, progress bar |
/games |
Games home — carousel, HOT/Popular, category grids |
/games/category/:type |
Filter by game type |
/games/play/:path |
Game detail + play (iframe) |
/articles |
Articles list (Editor's Choice) |
/articles/:slug |
Article detail |
* |
404 page |
Features: Per-route SEO meta, quiz search/topic filters, iframe error UI, route lazy-loading, page skeletons, AppImage lazy load, game preview (blurred gameplay video loop + preview card → Play), list preview modal, Popular Games from click stats (popular.json + optional Worker).
npm install
npm run devOpen http://localhost:5173 (defaults to /games)
- 全局样式:
src/styles/mobile.css(≤768px / ≤430px、安全区、触控 44px、防 iOS 输入缩放) - 断点常量(JS):
src/config/breakpoints.js(768/430/1335) index.html:viewport-fit=cover、theme-color、状态栏样式- 窄屏与横滑列表防溢出见各组件内
@media,首页布局在GamesHome.vue(≤768 显示 Mobile Hero + Trending) - 文章配图:
data/articles/media.js(Unsplash 等远程图库 URL,与站内游戏资源无关)
游戏通过 iframe 从 games.hhxzhd.xyz 加载,可在 .env 中设置:
VITE_GAME_EMBED_BASE=https://games.hhxzhd.xyz
加载体验:默认 30 秒超时;超过 12 秒仍 loading 会提示「较大游戏可能较慢」。开发模式下加载失败会在控制台打印 embed URL。可选:
VITE_GAME_LOAD_TIMEOUT_MS=30000
VITE_GAME_LOAD_SLOW_HINT_MS=12000
- 用户 打开预览(权重 1)或 点 Play(权重 3)时,前端向
{VITE_STATS_API_BASE}/api/stats/event上报(sendBeacon)。 - 首页
fetchPopularConfig()读取{VITE_STATS_API_BASE}/popular.json(未配置则用同源/popular.json);失败回退games.js策展。 - 本地:
npm run dev自带统计 API(vite-stats-plugin),数据在data/game-stats.json。
- KV:Dashboard → Workers & Pages → KV → Create,把 namespace id 写入
wrangler.toml的REPLACE_WITH_KV_NAMESPACE_ID。 - 部署 Worker:
记下输出 URL,例如
npm install npx wrangler login npm run deploy:stats
https://llgame-popular-stats.xxx.workers.dev。 - 联调 API(另开终端可先
npm run dev测本地):通过即:npm run test:stats STATS_API=https://llgame-popular-stats.xxx.workers.dev npm run test:stats STATS_ORIGIN=https://llgame.xyz npm run test:stats
/api/stats/health→ POST preview/play → GET/popular.json结构正确。 - 前端生产环境变量(复制
.env.production.example→.env.production):然后VITE_SITE_URL=https://llgame.xyz VITE_STATS_API_BASE=https://llgame-popular-stats.xxx.workers.dev
npm run build并部署dist/。 - 验收:打开线上首页 → DevTools Network 应有对 Worker 的
POST .../api/stats/event(预览/Play 后)和GET .../popular.json;Popular 区块source为stats/config且非常驻策展。
可选:
wrangler secret put ADMIN_TOKEN+PUT /api/stats/pins(Bearer)固定 HOT / 轮播置顶。POPULAR_SEED(wrangler.toml[vars])KV 无数据时的初始列表。- 静态兜底:
STATS_API=... npm run sync:popular把 Worker 榜单写入public/popular.json再部署(无 Worker 时前端仍可读静态文件)。
npm run build:popular # 从 hotPage 生成初始 popular.json
npm run sync:popular # 等同 aggregate:popular
STATS_API=https://your-worker.workers.dev npm run sync:popularOptional — replace generated icons with originals from the live site:
npm run fetch:icons本地 npm run dev 只在你的电脑上跑;线上需要:域名 + 静态托管 + 生产构建产物 dist/。
配置 .env.production → npm run build → 上传 dist/ → 绑定域名 →(可选)部署统计 Worker
- 购买/准备一个域名(例如
llgame.xyz),DNS 交给托管商(Cloudflare、阿里云等)。 - 复制生产配置并改成你的真实地址:
cp .env.production.example .env.production编辑 .env.production(构建时 Vite 会读入并打进前端):
VITE_SITE_URL=https://你的域名.com # 不要末尾斜杠
VITE_GAME_EMBED_BASE=https://games.hhxzhd.xyz # 游戏 CDN,有自有 CDN 再改
# AdSense 发布商 ID(Account → Account information,格式 ca-pub-…)
VITE_ADSENSE_CLIENT=ca-pub-XXXXXXXXXXXXXXXX
# 若已部署 Popular 统计 Worker(见上文 Popular Games 章节):
VITE_STATS_API_BASE=https://llgame-popular-stats.xxx.workers.devnpm run build 会根据 VITE_ADSENSE_CLIENT 自动生成 public/ads.txt(部署后访问 https://你的域名/ads.txt)。未配置时可临时 ADS_TXT_SKIP=1 npm run build,但提审 AdSense 前必须填真实 ID。
没有 Worker 也可以先上线:首页 Popular 会用 public/popular.json 静态文件。
npm install
npm run build
npm run preview构建会自动 预渲染(SSR)以下路由为静态 HTML,便于搜索引擎与 AdSense 抓取正文与 meta:
/games(首页,含轮播 / Latest / Popular / 分类预览;dist/index.html同步为同一份 HTML,便于/回退)/about、/privacy、/terms/articles、/articles/:slug(全部文章)/games/play/:path(全部游戏详情,共 118+ 页)
测验等其余路由仍为 SPA,依赖 dist/_redirects 回退。
生产构建请设置站点根 URL(用于 canonical / Open Graph):
VITE_SITE_URL=https://llgame.xyz npm run build浏览器打开终端里提示的地址(多为 http://localhost:4173),点几条路由确认:
/games、/quiz、/games/play/xxx刷新不 404- 查看页面源代码:
/about或/games/play/ttt应能看到完整正文,而非仅 boot 骨架 http://localhost:4173/ads.txt含你的pub-…行(需已配置VITE_ADSENSE_CLIENT)- 游戏预览 / Play 能打开 iframe
构建结果在 dist/ 目录(整包上传,不是源码)。
| 方式 | 适合 | 要点 |
|---|---|---|
| Cloudflare Pages | 已用 CF Worker 统计 | 连 GitHub 自动构建,或 npx wrangler pages deploy dist |
| Netlify | 简单静态站 | 拖放 dist 或连 Git,publish directory = dist |
| Vercel | 连 Git 一键 | Framework: Vite,Output: dist |
| Nginx / 对象存储 | 自有服务器 | 根目录指向 dist,见下方 Nginx |
项目已包含 public/_redirects(构建后进 dist/),用于 SPA 路由:直接访问 /games/category/action 时仍返回 index.html,由 Vue Router 接管。
A. 仪表盘(连 Git)
- Cloudflare → Workers & Pages → Create → Pages → Connect Git。
- Build command:
npm run build - Build output directory:
dist - Environment variables:填入与
.env.production相同的VITE_* - 保存后每次 push 自动发布;Custom domains 里绑定你的域名。
B. 命令行只传 dist
npm run build
npx wrangler pages deploy dist --project-name=llgame再到 Pages 项目里绑定自定义域名。
- Build:
npm run build,Publish:dist - 或本地:
npm run build后把dist拖到 Netlify Drop
server {
listen 80;
server_name 你的域名.com;
root /var/www/llgame/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}HTTPS 用 Certbot 或 Cloudflare 代理均可。
- Cloudflare 代理(橙云):A/CNAME 指到 Pages 给的地址。
- 生效后访问
https://你的域名.com/games应能打开首页。
- 首页、分类、测验、游戏详情可打开,刷新子路径不 404
-
https://你的域名.com/sitemap.xml、/robots.txt可访问 - 随便玩一个游戏,iframe 能加载(依赖
VITE_GAME_EMBED_BASE) - 若配置了 Worker:Network 里有
POST .../api/stats/event
| 现象 | 原因 |
|---|---|
| 子路径刷新 404 | 未配置 SPA 回退(_redirects / try_files) |
| sitemap 仍是 localhost / 旧域名 | 构建前未设 VITE_SITE_URL,改后重新 npm run build |
| Popular 不随点击变 | 未设 VITE_STATS_API_BASE 或未部署 Worker |
| 游戏黑屏 | CDN 地址错或游戏源站不可用 |
Set your production origin (sitemap + robots.txt):
# .env.production 或 shell
VITE_SITE_URL=https://your-domain.comnpm run build
npm run previewnpm run build runs generate:sitemap first and writes:
public/sitemap.xml— home, categories, all game play URLs, all quiz URLs, legal pagespublic/robots.txt—Sitemap: https://your-domain.com/sitemap.xml
Regenerate only:
VITE_SITE_URL=https://your-domain.com npm run generate:sitemap# 测验真实图片(从 hhxzhd.xyz 素材库下载 .jpg,并更新 quiz.js 路径)
npm run fetch:quiz-images
# 游戏真实图标(从 games.hhxzhd.xyz 下载)
npm run fetch:icons
# 首次初始化:测验图 + 游戏图标
npm run setup:assets注意:不要用 npm run generate:quiz-images 除非需要临时占位图(AI 生成)。正式素材请用 fetch:quiz-images。不要对游戏跑 generate:images --games,会覆盖已下载图标。
data/quiz.js— 23 quiz topics, 540 questionsdata/games.js— 118 HTML5 games