feat: Update project guidelines for code style and architecture clarity

This commit is contained in:
zhangyuheng
2026-03-10 11:21:22 +08:00
parent 2c8a9fdd19
commit bb2f680e63

View File

@@ -1,20 +1,27 @@
# Project Guidelines # Project Guidelines
## Code Style ## Code Style
- This repo is framework-free: plain HTML + CSS + vanilla JavaScript (`index.html`, `sponsor.html`, `stats.html`, `script.js`, `sponsor_script.js`, `stats_script.js`, `components.js`). - This repo is framework-free: plain HTML + CSS + vanilla JavaScript — no frameworks, modules, or build tooling.
- Keep existing naming style: `camelCase` for JS functions/variables and descriptive DOM ids/classes (for example `fetchCrowdfunding`, `setupMobileMenu`, `#players-grid`). - Keep existing naming style: `camelCase` for JS functions/variables and descriptive DOM ids/classes (for example `fetchCrowdfunding`, `setupMobileMenu`, `#players-grid`).
- Preserve current formatting patterns: 4-space indentation in HTML/CSS, simple function-based JS (no classes/modules/build tooling). - Preserve current formatting patterns: 4-space indentation in HTML/CSS, simple function-based JS.
- Reuse shared tokens in `style.css` (`:root` variables such as `--bg-color`, `--accent-color`) instead of introducing new ad-hoc styles. - Shared JS utilities use the global-object pattern (e.g. `DataUtils` in `js/data_utils.js`) — do not convert to ES modules.
- Reuse shared tokens in `css/style.css` (`:root` variables such as `--bg-color`, `--accent-color`) instead of introducing new ad-hoc styles.
- Keep page-local style overrides scoped to their page blocks; avoid broad visual refactors unless explicitly requested. - Keep page-local style overrides scoped to their page blocks; avoid broad visual refactors unless explicitly requested.
- Keep user-facing copy in Chinese unless the surrounding section is already English. - Keep user-facing copy in Chinese unless the surrounding section is already English.
## Architecture ## Architecture
- Public pages are static entry points: - Public pages are static entry points:
- `index.html` + `script.js`: landing page, sponsors, fundraising progress, live server status. - `index.html` + `js/script.js`: landing page, sponsors, fundraising progress, live server status.
- `sponsor.html` + `sponsor_script.js`: donation total, sponsor list, search/filter, donation modal. - `sponsor.html` + `js/sponsor_script.js`: donation total, sponsor list, search/filter, donation modal.
- `stats.html` + `stats_script.js`: player leaderboard + searchable player cards + modal details. - `stats.html` + `js/stats_script.js`: player leaderboard + searchable player cards + modal details.
- Shared structure is injected by `components.js` into `#navbar-component` / `#footer-component` and handles mobile menu/current-link highlighting. - `join.html` + `js/join_script.js`: 4-step wizard (convention → agree → device → tutorial). Uses `js/marked.min.js` to render `data/convention.md` as HTML.
- Shared visual system lives in `css/style.css`; page-specific styles live in `css/pages/` (for example `css/pages/sponsor.css`, `css/pages/stats.css`). - `facilities.html` + `js/facilities_script.js`: searchable/filterable catalog of server facilities from `data/facilities.json`. Supports Bilibili video embeds (BV IDs) in notes.
- `doc.html`, `map.html`, `photo.html`: iframe wrappers (navbar + fullscreen iframe to external hosts). No page-specific JS beyond `js/components.js`.
- Shared utilities:
- `js/components.js`: injected into `#navbar-component` / `#footer-component`, handles mobile menu & current-link highlighting.
- `js/data_utils.js`: `DataUtils.parseSponsorsText()` and `DataUtils.buildSponsorTotals()` — used by both `index.html` and `sponsor.html`.
- Shared visual system lives in `css/style.css`; page-specific styles live in `css/pages/` (`join.css`, `facilities.css`, `sponsor.css`, `stats.css`).
- Every page includes `<script type="application/ld+json">` Schema.org metadata and full OG/Twitter Card meta tags.
- Data flow for stats: - Data flow for stats:
1. `statsprocess.py` fetches raw player JSON files and writes normalized outputs to `stats/`. 1. `statsprocess.py` fetches raw player JSON files and writes normalized outputs to `stats/`.
2. It generates `stats/summary.json` consumed by `stats_script.js` via `fetch('stats/summary.json')`. 2. It generates `stats/summary.json` consumed by `stats_script.js` via `fetch('stats/summary.json')`.
@@ -26,24 +33,33 @@
- `python3 -m http.server 8000` - `python3 -m http.server 8000`
- open `http://localhost:8000/` - open `http://localhost:8000/`
- Regenerate player summary data: - Regenerate player summary data:
- `python3 statsprocess.py` - `python3 statsprocess.py` (requires `STATS_BASE_URL`, `STATS_USER`, `STATS_PASS` env vars for remote authentication).
- Python script dependencies are runtime imports in `statsprocess.py` (not pinned): `requests`, `tqdm`. - Python script dependencies are runtime imports in `statsprocess.py` (not pinned): `requests`, `tqdm`.
- CI/CD: `.github/workflows/deploy.yml` runs `statsprocess.py` then deploys to GitHub Pages on push to `main`, daily cron, or manual dispatch. Secrets live in GitHub Actions — never commit credentials.
## Data Contracts
- `data/sponsors.txt`: comma-separated fields (`name, project, amount, [date]`), parsed by `DataUtils.parseSponsorsText()`.
- `data/fund_progress.txt`: line-parsed by frontend scripts.
- `data/facilities.json`: array of `{title, intro, type, dimension, status, coordinates:{x,y,z}, contributors:[], instructions:[{type,content}], notes:[{type,content}]}`. Notes with `type:"video"` use Bilibili BV IDs.
- `data/convention.md`: Markdown server rules, rendered via marked.js in join wizard.
- `stats/summary.json` and `stats/{uuid}.json`: generated by `statsprocess.py` — do not hand-edit.
## Project Conventions ## Project Conventions
- Prefer progressive enhancement with `DOMContentLoaded` initializers (all page scripts and `components.js`). - Prefer progressive enhancement with `DOMContentLoaded` initializers (all page scripts and `components.js`).
- Keep network fetch paths relative for local assets (`data/fund_progress.txt`, `data/sponsors.txt`, `stats/summary.json`, `stats/{uuid}.json`). - Keep network fetch paths relative for local assets.
- For unavailable remote APIs, follow existing behavior: log errors and render fallback text instead of throwing. - For unavailable remote APIs, follow existing behavior: log errors and render fallback text instead of throwing.
- Preserve current text-data contracts: `data/sponsors.txt` is parsed as comma-separated fields (`name, project, amount, [date]`), and `data/fund_progress.txt` is line-parsed by frontend scripts. - Iframe wrapper pages (`doc.html`, `map.html`, `photo.html`) share an identical pattern: navbar + inline-styled fullscreen iframe. Follow this pattern for new external-embed pages.
- Do not introduce bundlers/framework migrations unless explicitly requested. - Do not introduce bundlers/framework migrations unless explicitly requested.
## Integration Points ## Integration Points
- External APIs/services currently used: - External APIs/services:
- Server status: `https://api.mcstatus.io/v2/status/java/mcpure.lunadeer.cn` - Server status: `https://api.mcstatus.io/v2/status/java/mcpure.lunadeer.cn`
- Avatars: `https://minotar.net/...` and `https://crafatar.com/...` - Avatars: `https://minotar.net/...` and `https://crafatar.com/...`
- Player name resolution in pipeline: Ashcon + Mojang Session APIs (`statsprocess.py`). - Player name resolution in pipeline: Ashcon + Mojang Session APIs (`statsprocess.py`).
- Source stats endpoint: `http://x2.sjcmc.cn:15960/stats/`. - Stats source endpoint: authenticated, URL in `STATS_BASE_URL` secret.
- Navbar external links are centralized in `components.js` (outline docs, map, photo, QQ group). - External iframe hosts: `schema.lunadeer.cn` (docs), `mcmap.lunadeer.cn` (map), `mcphoto.lunadeer.cn` (photo).
- External assets are loaded directly from CDNs (Google Fonts, Font Awesome) and image hosts. - Navbar external links are centralized in `js/components.js`.
- External assets: Google Fonts, Font Awesome (CDN), Bilibili embeds (facilities notes).
## Security ## Security
- Treat player UUID/name datasets in `stats/` as production content; avoid destructive bulk edits. - Treat player UUID/name datasets in `stats/` as production content; avoid destructive bulk edits.