commit 584a04500f530cdef400675be41dc9f4105bce29 Author: MeghdadFadaee Date: Sun Oct 18 14:28:53 2026 +0330 init diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..43c0fcf --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,45 @@ +name: Build and deploy OneUP +on: + push: + branches: [main, master] + pull_request: + workflow_dispatch: +permissions: + contents: read +concurrency: + group: pages-${{ github.ref }} + cancel-in-progress: true +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-node@v4 + with: + node-version: '24' + - name: Verify content and behavior + run: npm test + - name: Download battle preview images + if: github.event_name != 'pull_request' + run: npm run sync:battles + - name: Build static pages + run: npm run build + - uses: actions/upload-pages-artifact@v4 + if: github.event_name != 'pull_request' + with: + path: dist + deploy: + if: github.event_name != 'pull_request' + needs: build + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - uses: actions/configure-pages@v5 + - name: Deploy + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b8a3a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# Generated output and dependencies +/dist/ +/node_modules/ +/coverage/ +*.log + +# Local maintainer notes, environment files, and credentials +/.local/ +.env +.env.* +!.env.example +/.aws/ + +# Editor and local agent state +/.idea/ +/.vscode/ +/.agents/ +/.codex/ +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..42bffad --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# OneUP + +**One United Power.** A bilingual static website for the OneUP Albion Online guild, with fight highlights, AlbionBB reports, recruitment, and seasonal rewards. + +## Development + +Requires Node.js 22 or newer. The project has no external build dependencies; no install step is needed. + +```bash +npm run dev +``` + +Preview at `http://localhost:4173`. Restart after source or content changes to rebuild. Set `PORT` to use a different port. + +| Command | Purpose | +| --- | --- | +| `npm run dev` | Build and serve a local preview | +| `npm run build` | Generate the static website in `dist/` | +| `npm test` | Validate content, URL handling, preview metadata, and generated pages | +| `npm run sync:battles` | Download social preview images for configured AlbionBB reports | + +The build works offline. Battle image synchronization requires network access and preserves report links when previews are unavailable. + +## Project structure + +```text +content/ Guild data, reward configuration, and translations +docs/ Content format reference +public/assets/ Logo, jersey artwork, and optional media +scripts/ Static generator, preview server, and battle image sync +src/ Styles and browser interactions +test/ Node.js tests +.github/workflows/ Build and deployment workflow +``` + +## Content + +| File | Purpose | +| --- | --- | +| `content/site.json` | Site URL, guild profile, recruitment, socials, clips, and battle reports | +| `content/rewards.json` | Milestone targets, Silver payouts, and reward artwork | +| `content/translations.json` | English and Persian interface copy | + +Localized fields accept `{ "en": "English", "fa": "فارسی" }` or a plain string. Missing Persian values fall back to English. See [the content reference](docs/content.md) for media formats, battle report fields, recruitment, and rewards. + +## Architecture + +The Node.js generator renders complete HTML pages at `/` (English) and `/fa/` (Persian, RTL). Vanilla JavaScript handles navigation, reward tabs, media dialogs, and language preferences. A one-year `oneup_language` cookie remembers the selected language; `?lang=en` or `?lang=fa` overrides it. + +The build emits canonical and language alternate links, social metadata, organization structured data, `robots.txt`, `sitemap.xml`, a circular SVG favicon, and a custom-domain `CNAME`. Hosting assumes the domain root rather than a repository subpath. + +YouTube uses thumbnails and a privacy-enhanced player loaded on request. Direct video URLs use the native video element. AlbionBB previews are cached at build time; explicit image URLs and Europe single/combined battle preview URLs also work without a local cache. Fonts are served by Google Fonts, with system fallbacks. + +The GitHub Actions workflow validates pull requests. Pushes to `main` or `master` also synchronize battle previews, build, and deploy the static artifact to GitHub Pages. Generated output is not tracked. diff --git a/content/rewards.json b/content/rewards.json new file mode 100644 index 0000000..d3466ac --- /dev/null +++ b/content/rewards.json @@ -0,0 +1,13 @@ +{ + "jerseyImage": "assets/reward-picture.jpg", + "firstToTargetSilver": 20000000, + "categories": [ + { "id": "hellgate", "name": { "en": "Hellgate", "fa": "هل‌گیت" }, "target": 200000, "podium": [50000000, 20000000] }, + { "id": "depths", "name": { "en": "Depths", "fa": "اعماق" }, "target": 200000, "podium": [50000000, 20000000] }, + { "id": "power-core", "name": { "en": "Hideout Power Core", "fa": "پاورکور هاید‌اوت" }, "target": 150000, "podium": [30000000, 20000000, 10000000] }, + { "id": "ancient-lands", "name": { "en": "Ancient Lands", "fa": "سرزمین‌های باستانی" }, "target": 300000, "podium": [20000000, 10000000] }, + { "id": "gathering", "name": { "en": "Gathering", "fa": "جمع‌آوری منابع" }, "target": 300000, "podium": [20000000] }, + { "id": "corrupted", "name": { "en": "Corrupted", "fa": "کوراپتد" }, "target": 200000, "podium": [20000000] }, + { "id": "crystal-creatures", "name": { "en": "Crystal Creatures", "fa": "موجودات کریستالی" }, "target": 300000, "podium": [20000000] } + ] +} diff --git a/content/site.json b/content/site.json new file mode 100644 index 0000000..58458e4 --- /dev/null +++ b/content/site.json @@ -0,0 +1,68 @@ +{ + "siteUrl": "https://oneup.megh.dad", + "guildName": "OneUP", + "motto": "One United Power.", + "members": "100+", + "recruiting": true, + "recruitment": { + "intro": { + "en": "Welcome to OneUP recruitment! We are a PvP-focused guild looking for experienced and active players to join our community.", + "fa": "به بخش جذب اعضای وان‌آپ خوش آمدید! ما یک گیلد متمرکز بر PvP هستیم و از بازیکنان باتجربه و فعال برای پیوستن به جمعمان دعوت می‌کنیم." + }, + "activities": [ + { "en": "Ganking", "fa": "گنکینگ" }, + { "en": "Dive Content", "fa": "دایو کانتنت" }, + { "en": "Small Scale PvP", "fa": "نبردهای PvP اسمال‌اسکیل" }, + { "en": "Group Roaming & Open World Fights", "fa": "رومینگ گروهی و نبردهای جهان باز" }, + { "en": "Static Diving and PvP Activities", "fa": "دایو استاتیک و فعالیت‌های PvP" } + ], + "fameRequirements": [ + { "value": "200M+", "label": { "en": "Total Fame", "fa": "فیم کل" } }, + { "value": "10M+", "label": { "en": "PvP Fame", "fa": "فیم PvP" } } + ], + "requirements": [ + { "en": "Active and willing to participate in guild content", "fa": "فعال باشید و برای شرکت در فعالیت‌های گیلد آمادگی داشته باشید" }, + { "en": "Team player with a positive attitude", "fa": "روحیه کار تیمی و نگرش مثبت داشته باشید" }, + { "en": "Able to communicate and coordinate with the guild", "fa": "توانایی ارتباط و هماهنگی با اعضای گیلد را داشته باشید" } + ], + "applicationIntro": { + "en": "If you meet the requirements and want to be part of an active and competitive community, we’d be happy to have you!", + "fa": "اگر این شرایط را دارید و می‌خواهید عضوی از یک جمع فعال و رقابتی باشید، خوشحال می‌شویم به ما بپیوندید!" + }, + "applicationInstructions": { + "en": "Open a ticket in the #apply section and tell us a little about yourself.", + "fa": "در بخش #apply یک تیکت باز کنید و کمی درباره خودتان بگویید." + }, + "welcome": { + "en": "Welcome to OneUP — One United Power.", + "fa": "به وان‌آپ خوش آمدید — یک قدرت متحد." + } + }, + "seasonLabel": { "en": "Season rewards", "fa": "جوایز فصل" }, + "description": { + "en": "OneUP is an Albion Online guild of 100+ members. One United Power. Explore our battles, fight highlights, community, and seasonal member rewards.", + "fa": "وان‌آپ، گیلد آلبیون آنلاین با بیش از ۱۰۰ عضو. یک قدرت متحد. نبردها، ویدیوها، جامعه و جوایز فصلی اعضای ما را ببینید." + }, + "socials": [ + { "name": "Discord", "kind": "discord", "url": "", "description": { "en": "Where the guild comes together.", "fa": "محل گردهمایی اعضای گیلد." } }, + { "name": "Telegram", "kind": "telegram", "url": "", "description": { "en": "News from the front line.", "fa": "تازه‌ترین خبرها از خط مقدم." } }, + { "name": "YouTube", "kind": "youtube", "url": "", "description": { "en": "Our fights. Our point of view.", "fa": "نبردهای ما، از نگاه ما." } } + ], + "clips": [ + { + "title": { "en": "OneUP — Battle highlights", "fa": "وان‌آپ — لحظه‌های نبرد" }, + "type": "youtube", + "url": "https://www.youtube.com/watch?v=aVU4upHCGbc" + } + ], + "battles": [ + { + "title": { "en": "Battle #448776222", "fa": "نبرد شماره ۴۴۸۷۷۶۲۲۲" }, + "url": "https://europe.albionbb.com/battles/448776222" + }, + { + "title": { "en": "Combined battle report — 3 engagements", "fa": "گزارش ترکیبی — ۳ نبرد" }, + "url": "https://europe.albionbb.com/battles/multi?ids=441002770,441001581,440997498" + } + ] +} diff --git a/content/translations.json b/content/translations.json new file mode 100644 index 0000000..c7a7479 --- /dev/null +++ b/content/translations.json @@ -0,0 +1,40 @@ +{ + "en": { + "battleArchive": "From the war archive", "singleReport": "Battle report", "combinedReport": "Campaign report", "europe": "Europe", "engagement": "engagement", "engagements": "engagements", "reportIds": "Battle report IDs", "archivedReports": "Archived reports", "loggedEngagements": "Recorded engagements", "archiveMotto": "One banner. Every battlefield.", "detailedLog": "Detailed battle log", + "mainContent": "Our main content", "recruitmentRequirements": "Entry requirements", "applicationTitle": "Ready to join the ranks?", "applyDiscord": "Apply on Discord", + "title": "OneUP — One United Power. | Albion Online Guild", + "skip": "Skip to content", "guild": "ALBION ONLINE GUILD", "nav": ["The guild", "War chronicles", "Battle board", "Rewards"], + "join": "Join the ranks", "recruiting": "THE RANKS ARE OPEN", "closed": "THE GUILD STANDS UNITED", + "eyebrow": "MANY WARRIORS. ONE BANNER.", "hero1": "ONE UNITED", "hero2": "POWER.", + "intro": "Different warriors. The same resolve. We are OneUP — a guild built on unity, driven by battle, and defined by the people beside us.", + "watch": "Watch us fight", "scroll": "ENTER THE WORLD OF ONEUP", "memberLabel": "MEMBERS. ONE PURPOSE.", + "manifestoLabel": "01 / THE GUILD", "manifestoTitle": "A guild is a name.", "manifestoAccent": "A brotherhood is a choice.", + "manifestoText": "From the first call to the final clash, we stand together. More than a hundred members, each bringing something to the banner. Every fight is ours. Every contribution matters.", + "pillars": [ { "title": "United in battle", "text": "One call. One direction. We fight as a guild, with trust in the people at our side." }, { "title": "Stronger together", "text": "From gathering to the front line, every role helps build the strength of OneUP." }, { "title": "Earn your legacy", "text": "Push your limits. Reach the milestones. Let your contribution become part of our story." } ], + "clipsLabel": "02 / WAR CHRONICLES", "clipsTitle": "Let the fights", "clipsAccent": "do the talking.", "clipsIntro": "The clashes, the calls, the moments worth reliving. From our side of the battlefield.", + "all": "All footage", "youtube": "YouTube", "direct": "Guild uploads", "play": "Play video", "close": "Close video", "clipsEmpty": "The next chapter is being written.", "clipsEmptyText": "Our fight highlights will appear here. Until then, the banner keeps moving.", "noFilter": "No footage in this category yet.", + "battlesLabel": "03 / THE BATTLE BOARD", "battlesTitle": "Every battle.", "battlesAccent": "Part of our story.", "battlesIntro": "Reports from the front line. Explore our recorded fights on AlbionBB.", "albionbb": "Explore AlbionBB", "report": "View battle report", "battleEmpty": "The field is quiet. For now.", "battleEmptyText": "Battle reports will be posted here after our fights.", "date": "Date", "battle": "Battle", "outcome": "Outcome", "kills": "Kills", "deaths": "Deaths", "victory": "Victory", "defeat": "Defeat", "draw": "Draw", "recorded": "Recorded", + "rewardsLabel": "04 / THE SPOILS OF DEDICATION", "rewardsTitle": "Your effort.", "rewardsAccent": "Your reward.", "rewardsIntro": "Two ways to make your mark. Race to a milestone or rise through the season rankings. Your contribution counts.", + "first": "First to the finish", "podium": "Season podium", "firstRule": "One winner per category: the first member to reach the target earns 20M Silver and a custom OneUP jersey.", "podiumRule": "Awarded at the end of the season to the highest-ranked members in each category.", "category": "Category", "target": "Point target", "prize": "Reward", "rank1": "1st place", "rank2": "2nd place", "rank3": "3rd place", "silver": "Silver", "jersey": "Custom jersey", "jerseyLabel": "WEAR THE BANNER", "jerseyTitle": "Earned. Never given.", "jerseyText": "The OneUP custom jersey. A real-world reward for the first member to hit each category’s milestone.", "jerseyAlt": "Black and white OneUP custom guild jerseys, front and back", "jerseyZoom": "View jersey artwork", "closeImage": "Close jersey artwork", + "communityLabel": "05 / ANSWER THE CALL", "communityTitle": "Your next chapter", "communityAccent": "starts with us.", "communityText": "Find your people. Bring your ambition. Stand beneath the OneUP banner.", "socialSoon": "Link coming soon", "socialOpen": "Visit", "footer": "Many warriors. One United Power.", "fan": "An independent Albion Online guild community. Albion Online belongs to Sandbox Interactive.", "top": "Back to top", "menu": "Toggle navigation", "videoFallback": "Open original video", "videoError": "This video could not be loaded. You can open the original link below." + }, + "fa": { + "battleArchive": "از آرشیو نبردها", "singleReport": "گزارش نبرد", "combinedReport": "گزارش مجموعه نبردها", "europe": "اروپا", "engagement": "نبرد", "engagements": "نبرد", "reportIds": "شناسه گزارش نبردها", "archivedReports": "گزارش ثبت‌شده", "loggedEngagements": "نبرد ثبت‌شده", "archiveMotto": "یک پرچم، در هر میدان نبرد.", "detailedLog": "جزئیات گزارش نبردها", + "mainContent": "فعالیت‌های اصلی ما", "recruitmentRequirements": "شرایط پیوستن", "applicationTitle": "آماده پیوستن به ما هستید؟", "applyDiscord": "درخواست عضویت در دیسکورد", + "title": "وان‌آپ — یک قدرت متحد | گیلد آلبیون آنلاین", + "skip": "رفتن به محتوای اصلی", "guild": "گیلد آلبیون آنلاین", "nav": ["درباره گیلد", "روایت نبردها", "گزارش نبرد", "جوایز"], + "join": "به ما بپیوندید", "recruiting": "پذیرش جنگجویان تازه", "closed": "متحد زیر یک پرچم", + "eyebrow": "جنگجویان بسیار. یک پرچم.", "hero1": "یک قدرت", "hero2": "متحد.", + "intro": "جنگجویانی متفاوت، با اراده‌ای مشترک. ما وان‌آپ هستیم؛ گیلدی ساخته‌شده بر پایه اتحاد، با انگیزه نبرد و قدرت همراهانمان.", + "watch": "نبردهای ما را ببینید", "scroll": "به دنیای وان‌آپ قدم بگذارید", "memberLabel": "عضو. یک هدف مشترک.", + "manifestoLabel": "۰۱ / گیلد ما", "manifestoTitle": "گیلد یک نام است.", "manifestoAccent": "برادری یک انتخاب.", + "manifestoText": "از اولین فراخوان تا آخرین درگیری، کنار هم می‌ایستیم. بیش از صد عضو که هر کدام سهمی در قدرت این پرچم دارند. هر نبرد برای همه ماست و هر مشارکتی ارزش دارد.", + "pillars": [ { "title": "متحد در نبرد", "text": "یک فرمان، یک مسیر. با اعتماد به همراهانمان، در کنار هم می‌جنگیم." }, { "title": "با هم قوی‌تریم", "text": "از جمع‌آوری منابع تا خط مقدم، هر نقش به قدرت وان‌آپ اضافه می‌کند." }, { "title": "نامت را ماندگار کن", "text": "از محدودیت‌هایت عبور کن، به هدف‌ها برس و سهمت را در داستان ما بساز." } ], + "clipsLabel": "۰۲ / روایت نبردها", "clipsTitle": "بگذار نبردها", "clipsAccent": "حرف بزنند.", "clipsIntro": "درگیری‌ها، فرمان‌ها و لحظه‌هایی که ارزش دوباره دیدن دارند؛ از نگاه ما در میدان نبرد.", + "all": "همه ویدیوها", "youtube": "یوتیوب", "direct": "ویدیوهای گیلد", "play": "پخش ویدیو", "close": "بستن ویدیو", "clipsEmpty": "فصل بعدی در حال نوشته شدن است.", "clipsEmptyText": "ویدیوهای نبرد ما اینجا قرار می‌گیرند. تا آن زمان، پرچم همچنان برافراشته است.", "noFilter": "هنوز ویدیویی در این دسته قرار نگرفته است.", + "battlesLabel": "۰۳ / گزارش میدان نبرد", "battlesTitle": "هر نبرد،", "battlesAccent": "بخشی از داستان ما.", "battlesIntro": "گزارش‌هایی از خط مقدم. جزئیات نبردهای ما را در آلبیون‌بی‌بی ببینید.", "albionbb": "مشاهده آلبیون‌بی‌بی", "report": "مشاهده گزارش نبرد", "battleEmpty": "میدان فعلاً آرام است.", "battleEmptyText": "گزارش نبردها پس از هر مبارزه در این بخش منتشر می‌شود.", "date": "تاریخ", "battle": "نبرد", "outcome": "نتیجه", "kills": "کشتن", "deaths": "مرگ", "victory": "پیروزی", "defeat": "شکست", "draw": "مساوی", "recorded": "ثبت‌شده", + "rewardsLabel": "۰۴ / پاداش پشتکار", "rewardsTitle": "تلاش تو.", "rewardsAccent": "پاداش تو.", "rewardsIntro": "دو راه برای درخشیدن. زودتر به هدف برس یا در پایان فصل در صدر جدول باش. مشارکت تو ارزشمند است.", + "first": "اولین نفر در خط پایان", "podium": "سکوی پایان فصل", "firstRule": "در هر دسته فقط یک برنده: اولین عضوی که به امتیاز هدف برسد، ۲۰ میلیون سیلور و یک لباس اختصاصی وان‌آپ می‌گیرد.", "podiumRule": "این جوایز در پایان فصل، بر اساس رتبه جدول هر دسته، به اعضای برتر تعلق می‌گیرد.", "category": "دسته", "target": "امتیاز هدف", "prize": "جایزه", "rank1": "نفر اول", "rank2": "نفر دوم", "rank3": "نفر سوم", "silver": "سیلور", "jersey": "لباس اختصاصی", "jerseyLabel": "پرچم را به تن کن", "jerseyTitle": "با تلاش به دستش بیاور.", "jerseyText": "لباس اختصاصی وان‌آپ؛ پاداشی در دنیای واقعی برای اولین عضوی که به هدف امتیازی هر دسته برسد.", "jerseyAlt": "نمای جلو و پشت لباس‌های اختصاصی مشکی و سفید گیلد وان‌آپ", "jerseyZoom": "مشاهده طرح لباس", "closeImage": "بستن تصویر لباس", + "communityLabel": "۰۵ / به فراخوان پاسخ بده", "communityTitle": "فصل بعدی تو", "communityAccent": "با ما آغاز می‌شود.", "communityText": "همراهانت را پیدا کن. با انگیزه بیا و زیر پرچم وان‌آپ بایست.", "socialSoon": "لینک به‌زودی", "socialOpen": "مشاهده", "footer": "جنگجویان بسیار. یک قدرت متحد.", "fan": "جامعه مستقل گیلد آلبیون آنلاین. آلبیون آنلاین متعلق به Sandbox Interactive است.", "top": "بازگشت به بالا", "menu": "باز و بسته کردن منو", "videoFallback": "باز کردن لینک اصلی ویدیو", "videoError": "ویدیو بارگذاری نشد. می‌توانید لینک اصلی را در پایین باز کنید." + } +} diff --git a/docs/content.md b/docs/content.md new file mode 100644 index 0000000..65ddb66 --- /dev/null +++ b/docs/content.md @@ -0,0 +1,82 @@ +# Content reference + +All guild content lives in three JSON files: + +| File | What to edit | +| --- | --- | +| `content/site.json` | Domain, member count, recruitment status and details, social links, clips, battle reports, SEO descriptions | +| `content/rewards.json` | Point targets, Silver payouts, and jersey artwork | +| `content/translations.json` | English and Persian page text | + +Translated fields accept `{ "en": "English text", "fa": "متن فارسی" }`. A plain string also works. Missing Persian entries fall back to English. + +## Recruitment + +Recruitment copy, PvP activities, fame thresholds, and application instructions are editable in `recruitment` within `content/site.json`. The community section presents these in English and Persian; an “Apply on Discord” button appears automatically when the Discord social URL is configured. + +## Social links + +Set each social's `url` to its real HTTPS invite/channel address. Empty URLs display a translated “Link coming soon” label. Add or remove entries freely; `kind` supports `discord`, `telegram`, `youtube`, or a generic globe for other services. + +## Fight clips + +Add to the `clips` array in `content/site.json`: + +```json +{ + "title": { "en": "Your fight title", "fa": "عنوان نبرد شما" }, + "description": { "en": "A short description", "fa": "توضیح کوتاه" }, + "type": "youtube", + "url": "https://www.youtube.com/watch?v=YOUR_VIDEO_ID", + "duration": "04:32" +} +``` + +Replace the video ID with a real 11-character YouTube ID. Watch, short-link, Shorts, Live, and embed URLs are supported. YouTube previews use the video's thumbnail; the privacy-enhanced player loads only after a click. + +For a direct MP4/WebM file, use `"type": "direct"`, a publicly accessible HTTPS media URL, and optionally `"poster": "assets/my-fight.jpg"`. The media host must permit browser playback. Use a URL for the actual video file, rather than a sharing page. A link to the original is always available in the player. + +Put additional local images under `public/assets/` and reference them as `assets/filename.jpg`. Do not add `public/` to content paths. Large videos are better hosted on YouTube or an external media host. + +## Battle reports and AlbionBB preview images + +Add each battle manually to `battles` after the fight: + +```json +{ + "title": { "en": "Your battle title", "fa": "عنوان نبرد شما" }, + "date": "2026-10-18", + "url": "https://europe.albionbb.com/battles/448776222" +} +``` + +The sample title and date are illustrative. Omit the date or results when unknown. + +Optional fields: `"date": "2026-10-18"`, `"outcome": "victory"` (also `defeat`, `draw`, or `recorded`), `"kills": 0`, and `"deaths": 0`. Enter verified guild-specific numbers. Omit unknown dates and figures; they display as dashes. Reports sort by date, newest first, with undated reports following in JSON order. Combined `/battles/multi?ids=...` links are supported and receive distinct preview cache filenames. + +Only the report URL is needed to discover its preview; no `preview` field is required. The GitHub deployment automatically runs `npm run sync:battles`, which reads each report's `twitter:image` or `og:image`, including combined reports. If the report page cannot be read or has no image metadata, Europe reports fall back to endpoints derived from the report URL: `https://api.albionbb.com/eu/preview/BATTLE_ID` for a single battle, or `https://api.albionbb.com/eu/preview/multi?ids=ID1,ID2,...` for combined battles. An optional explicit `preview` field overrides discovery. + +PNG/JPEG/WebP images are downloaded to `public/assets/battles/` and included in the generated site. If a download fails, the discovered remote URL remains usable by the browser; an existing local image cache is preserved. Europe single and combined preview URLs are also derived directly during local builds without synchronization. Image display does not require a cross-origin API request. Downloaded files on the Actions runner are included in deployment but are not committed back to Git. + +Every report renders a visual card with local decorative terrain artwork, guild branding, report IDs, and single/combined report labels. Report images display in full without cropping; missing or failed images retain the local artwork. Combined reports use the combined scoreboard image; a single engagement's image is not substituted for the combined results. The map is decorative, not a reconstruction of the battle. Archive counts use report entries and unique battle IDs from their URLs. Only supplied dates and results are shown. The full table is available in the expandable detailed log. + +To download previews locally, run: + +```bash +npm run sync:battles +``` + +Commit `public/assets/battles/` if you want persistent local fallback images. An optional `preview` field can provide an explicit HTTPS image URL or a local `assets/` path. This is useful if AlbionBB changes its metadata. Override an old cached image by syncing the report again or removing its entry from `public/assets/battles/previews.json`. + +You can inspect/download a report's preview without publishing it to the battle archive: + +```bash +npm run sync:battles -- https://europe.albionbb.com/battles/448776222 +``` + +## Rewards + +The reward model supports one first-to-target winner per category and a separate end-of-season podium. Targets, payouts, and jersey artwork are configured in `content/rewards.json`. Values use whole Silver: `20000000` means 20M. Update the explanatory text in `content/translations.json` when changing the jersey rule or adding different prizes. + +Artwork lives in `public/assets/`. The build copies it into the site and creates a circular favicon with transparent corners from the original logo. The reward rules are maintained in `content/rewards.json`. + diff --git a/package.json b/package.json new file mode 100644 index 0000000..5cf9e41 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "oneup-guild", + "description": "Bilingual static website for the OneUP Albion Online guild.", + "version": "1.0.0", + "private": true, + "type": "module", + "engines": { "node": ">=22" }, + "scripts": { + "build": "node scripts/build.mjs", + "dev": "node scripts/serve.mjs", + "test": "node --test", + "sync:battles": "node scripts/sync-battles.mjs" + } +} diff --git a/public/assets/battle-terrain.svg b/public/assets/battle-terrain.svg new file mode 100644 index 0000000..f0c3bae --- /dev/null +++ b/public/assets/battle-terrain.svg @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/assets/logo.jpg b/public/assets/logo.jpg new file mode 100644 index 0000000..1a85f81 Binary files /dev/null and b/public/assets/logo.jpg differ diff --git a/public/assets/reward-picture.jpg b/public/assets/reward-picture.jpg new file mode 100644 index 0000000..db1c693 Binary files /dev/null and b/public/assets/reward-picture.jpg differ diff --git a/scripts/battle-previews.mjs b/scripts/battle-previews.mjs new file mode 100644 index 0000000..20ef47e --- /dev/null +++ b/scripts/battle-previews.mjs @@ -0,0 +1,46 @@ +import { safeUrl } from './lib.mjs'; +import { createHash } from 'node:crypto'; +const decode = value => value.replace(/&/g,'&').replace(/"/g,'"').replace(/'/g,"'").replace(/&#(\d+);/g,(_,n)=>String.fromCodePoint(Number(n))); +// Europe preview routes supplied from AlbionBB's Twitter metadata. +export function directPreview(url) { + try { + const u=new URL(url); + if(u.protocol!=='https:'||u.hostname!=='europe.albionbb.com') return null; + if(/^\/battles\/multi\/?$/.test(u.pathname)){ + const ids=u.searchParams.get('ids'); + return /^\d+(?:,\d+)*$/.test(ids||'')?`https://api.albionbb.com/eu/preview/multi?ids=${ids}`:null; + } + const id=u.pathname.match(/^\/battles\/(\d+)\/?$/)?.[1]; + return id?`https://api.albionbb.com/eu/preview/${id}`:null; + } catch { return null; } +} +export function socialImage(html, pageUrl) { + const images = new Map(); + for (const tag of html.matchAll(/]*>/gi)) { + const attrs = {}; + for (const a of tag[0].matchAll(/([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/g)) attrs[a[1].toLowerCase()] = decode(a[2]??a[3]??a[4]); + const key=(attrs.property||attrs.name||'').toLowerCase(); + if (attrs.content) images.set(key,attrs.content); + } + const value=images.get('twitter:image')||images.get('twitter:image:src')||images.get('og:image:secure_url')||images.get('og:image'); + if (!value) return null; + try { const url=new URL(value,pageUrl).href; return safeUrl(url)?url:null; } catch { return null; } +} +export async function discoverPreview(battle, fetchImpl=fetch) { + if (battle.preview) return battle.preview; + let metadataError; + try { + const page=await fetchImpl(battle.url,{signal:AbortSignal.timeout(15000),headers:{'User-Agent':'OneUP-Guild-Preview/1.0'}}); + if (!page.ok) throw Error(`Report returned HTTP ${page.status}`); + const discovered=socialImage(await page.text(),battle.url); + if (discovered) return discovered; + } catch(error) { metadataError=error; } + const fallback=directPreview(battle.url); + if (fallback) return fallback; + throw metadataError||Error('No Twitter/Open Graph preview found for this report.'); +} +export function battleKey(url) { + const u=new URL(url); + const queryKey=u.search?`-${createHash('sha256').update(u.search).digest('hex').slice(0,16)}`:''; + return `${u.hostname.replace(/[^a-z0-9.-]/gi,'-')}-${u.pathname.split('/').filter(Boolean).pop().replace(/[^a-z0-9-]/gi,'-')}${queryKey}`; +} diff --git a/scripts/build.mjs b/scripts/build.mjs new file mode 100644 index 0000000..96f7922 --- /dev/null +++ b/scripts/build.mjs @@ -0,0 +1,91 @@ +import { readFile, writeFile, mkdir, rm, cp, access } from 'node:fs/promises'; +import { escapeHtml as e, localized, youtubeId, validate } from './lib.mjs'; +import { renderBattleCards } from './render-battles.mjs'; + +const read = async name => JSON.parse(await readFile(new URL(`../content/${name}.json`, import.meta.url), 'utf8')); +const [site, rewards, translations] = await Promise.all(['site','rewards','translations'].map(read)); +validate(site, rewards); +let previews={}; +try { previews=JSON.parse(await readFile(new URL('../public/assets/battles/previews.json',import.meta.url),'utf8')); } catch(err) { if(err.code!=='ENOENT') throw err; } +const root = new URL('../', import.meta.url); +const dist = new URL('../dist/', import.meta.url); +await rm(dist, { recursive: true, force: true }); +await mkdir(new URL('assets/', dist), { recursive: true }); +for (const [from,to] of [['src/styles.css','styles.css'],['src/app.js','app.js']]) await cp(new URL(from,root),new URL(`assets/${to}`,dist)); +try { await cp(new URL('public/assets/',root),new URL('assets/',dist),{ recursive:true }); } catch(err) { if(err.code !== 'ENOENT') throw err; } +await rm(new URL('assets/battles/previews.json',dist),{force:true}); +const faviconLogo=(await readFile(new URL('public/assets/logo.jpg',root))).toString('base64'); +await writeFile(new URL('assets/favicon.svg',dist),``); +for (const path of [rewards.jerseyImage,...site.clips.map(c=>c.poster).filter(p=>p?.startsWith('assets/'))]) await access(new URL(path,dist)); +const origin = site.siteUrl.replace(/\/$/, ''); +const icon = (name, cls='') => ``; +const glyphs = ``; + +function render(lang) { + const t=translations[lang], fa=lang==='fa', base=fa?'../':'./', path=fa?'/fa/':'/'; + const l=v=>e(localized(v,lang)), asset=p=>base+p; + const number=n=>new Intl.NumberFormat(fa?'fa-IR':'en-US').format(n); + const silver=n=>`${number(n/1e6)}${fa?' میلیون':'M'}`; + const external=(url,text,cls='')=>`${text}`; + const heading=(label,title,accent)=>`

${e(label)}

${e(title)}
${e(accent)}

`; + const firstRule=t.firstRule.replace(fa?'۲۰ میلیون':'20M',fa?`${number(rewards.firstToTargetSilver/1e6)} میلیون`:`${rewards.firstToTargetSilver/1e6}M`); + const clips=site.clips.map((c,i)=>{ + const poster=c.poster?assetOrUrl(c.poster):c.type==='youtube'?`https://i.ytimg.com/vi/${youtubeId(c.url)}/hqdefault.jpg`:asset('assets/logo.jpg'); + return `
${String(i+1).padStart(2,'0')}

${l(c.title)}

${c.description?`

${l(c.description)}

`:''}
${icon('diagonal')}
`; + }).join(''); + function assetOrUrl(p){return p.startsWith('assets/')?asset(p):p;} + const battleCards=renderBattleCards({battles:site.battles,previews,lang,base,icon,t}); + const schema={ '@context':'https://schema.org', '@type':'Organization', name:site.guildName, slogan:site.motto, url:origin, logo:origin+'/assets/logo.jpg', description:localized(site.description,lang), sameAs:site.socials.filter(s=>s.url).map(s=>s.url) }; + const recruitment=site.recruitment; + const discord=site.socials.find(s=>s.kind==='discord'&&s.url); + const recruitmentMarkup=recruitment?`
${icon('swords')}

${e(t.mainContent)}

    ${recruitment.activities.map(a=>`
  • ${l(a)}
  • `).join('')}
${icon('shield')}

${e(t.recruitmentRequirements)}

${recruitment.fameRequirements.map(r=>`
${l(r.label)}
${e(r.value)}
`).join('')}
    ${recruitment.requirements.map(r=>`
  • ${l(r)}
  • `).join('')}

${e(t.applicationTitle)}

${l(recruitment.applicationIntro)}

${l(recruitment.applicationInstructions).replaceAll('#apply','#apply')}

${l(recruitment.welcome)}

${discord?external(discord.url,`${icon('discord')}${e(t.applyDiscord)}${icon('diagonal')}`,'button'):''}
`:''; + return ` + + +${e(t.title)} + + + + + + +${glyphs} + +
${e(site.recruiting?t.recruiting:t.closed)}

${e(t.eyebrow)}

${e(t.hero1)}
${e(t.hero2)}

${e(t.intro)}

${e(site.members)}${e(t.memberLabel)}
${icon('shield')}
↓${e(t.scroll)}
+ +
${heading(t.manifestoLabel,t.manifestoTitle,t.manifestoAccent)}

${e(t.manifestoText)}

${e(site.motto)}

${t.pillars.map((p,i)=>`
${icon(['swords','shield','crown'][i])}0${i+1}

${e(p.title)}

${e(p.text)}

`).join('')}
+
${heading(t.clipsLabel,t.clipsTitle,t.clipsAccent)}

${e(t.clipsIntro)}

${site.clips.length?`
${['all','youtube','direct'].map((v,i)=>``).join('')}
${clips}
`:`
${icon('play')}

${e(t.clipsEmpty)}

${e(t.clipsEmptyText)}

`}
+
${heading(t.battlesLabel,t.battlesTitle,t.battlesAccent)}

${e(t.battlesIntro)}

${external('https://albionbb.com/',`${e(t.albionbb)} ${icon('diagonal')}`,'text-link')}
${battleCards}${site.battles.length?`
${icon('swords')}${e(t.detailedLog)}`:''}
${icon('swords')} ONEUP / ${fa?'گزارش نبردها':'BATTLE LOG'}POWERED BY ALBIONBB ↗
${site.battles.length?`
${[t.date,t.battle,t.outcome,t.kills,t.deaths,''].map(v=>``).join('')}${[...site.battles].sort((a,b)=>(b.date||'').localeCompare(a.date||'')).map(b=>``).join('')}
${e(v)}
${b.date?``:'—'}${l(b.title)}${e(t[b.outcome||'recorded'])}${b.kills==null?'—':number(b.kills)}${b.deaths==null?'—':number(b.deaths)}${external(b.url,`${e(t.report)} ${icon('diagonal')}`,'text-link')}
`:`
${icon('shield')}

${e(t.battleEmpty)}

${e(t.battleEmptyText)}

`}
${site.battles.length?'
':''}
+
${heading(t.rewardsLabel,t.rewardsTitle,t.rewardsAccent)}

${e(t.rewardsIntro)}

${e(firstRule)}

${rewards.categories.map((r,i)=>``).join('')}
${e(t.category)}${e(t.target)}${e(t.prize)}
0${i+1}${l(r.name)}${number(r.target/1000)}K${silver(rewards.firstToTargetSilver)} ${e(t.silver)}+ ${e(t.jersey)}
+
${heading(t.communityLabel,t.communityTitle,t.communityAccent)}

${recruitment?l(recruitment.intro):e(t.communityText)}

${recruitmentMarkup}
+ +

${e(t.videoFallback)} ↗
+${e(t.jerseyAlt)} +`; +} +for (const lang of ['en','fa']) { + const folder=lang==='en'?dist:new URL('fa/',dist); + await mkdir(folder,{recursive:true}); await writeFile(new URL('index.html',folder),render(lang)); +} +await Promise.all([ + writeFile(new URL('CNAME',dist),new URL(origin).hostname+'\n'), + writeFile(new URL('.nojekyll',dist),''), + writeFile(new URL('robots.txt',dist),`User-agent: *\nAllow: /\nSitemap: ${origin}/sitemap.xml\n`), + writeFile(new URL('sitemap.xml',dist),`${['/','/fa/'].map(p=>`${origin}${p}`).join('')}`), + writeFile(new URL('404.html',dist),`Lost in the Outlands | OneUP

404 / BEYOND THE FRONT LINE

Lost in the
Outlands.

The banner is this way.

Return to OneUP →بازگشت به وان‌آپ
`) +]); +console.log(`Built English and Persian pages in dist/ for ${origin}`); diff --git a/scripts/lib.mjs b/scripts/lib.mjs new file mode 100644 index 0000000..d97c52e --- /dev/null +++ b/scripts/lib.mjs @@ -0,0 +1,46 @@ +export const escapeHtml = (value) => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&', '<':'<', '>':'>', '"':'"', "'":'''}[c])); +export const localized = (value, lang) => typeof value === 'string' ? value : value?.[lang] ?? value?.en ?? ''; +export function youtubeId(value) { + try { + const u = new URL(value); + if (['youtu.be', 'www.youtu.be'].includes(u.hostname)) return /^[\w-]{11}$/.test(u.pathname.slice(1)) ? u.pathname.slice(1) : null; + if (!['youtube.com','www.youtube.com','m.youtube.com','youtube-nocookie.com','www.youtube-nocookie.com'].includes(u.hostname)) return null; + const id = u.searchParams.get('v') || u.pathname.match(/^\/(?:shorts|embed|live)\/([\w-]{11})/)?.[1]; + return /^[\w-]{11}$/.test(id ?? '') ? id : null; + } catch { return null; } +} +export function safeUrl(value) { + try { const u = new URL(value); return u.protocol === 'https:'; } catch { return false; } +} +export function assetPath(value) { + return typeof value === 'string' && /^assets\/[a-zA-Z0-9_./-]+$/.test(value) && !value.split('/').includes('..'); +} +export function validate(site, rewards) { + const fail = msg => { throw new Error(`Content error: ${msg}`); }; + if (!safeUrl(site.siteUrl)) fail('siteUrl must use HTTPS.'); + const origin = new URL(site.siteUrl); + if (origin.search || origin.hash || origin.pathname !== '/') fail('siteUrl must be a domain without a path, query, or fragment.'); + for (const key of ['socials','clips','battles']) if (!Array.isArray(site[key])) fail(`${key} must be an array.`); + for (const s of site.socials) if (s.url && !safeUrl(s.url)) fail(`Invalid social URL: ${s.name}`); + for (const c of site.clips) { + if (!safeUrl(c.url)) fail(`Invalid clip URL: ${localized(c.title,'en')}`); + if (!['youtube','direct'].includes(c.type)) fail('Clip type must be youtube or direct.'); + if (c.type === 'youtube' && !youtubeId(c.url)) fail(`Unrecognized YouTube URL: ${c.url}`); + if (c.poster && !safeUrl(c.poster) && !assetPath(c.poster)) fail('Poster must be an HTTPS URL or an assets/ path.'); + if (!localized(c.title,'en')) fail('Clips need an English title.'); + } + for (const b of site.battles) { + if (!safeUrl(b.url) || !/(^|\.)albionbb\.com$/.test(new URL(b.url).hostname)) fail('Battle URLs must be HTTPS albionbb.com links.'); + if (b.date != null && (!/^\d{4}-\d{2}-\d{2}$/.test(b.date) || Number.isNaN(Date.parse(b.date)))) fail('Battle date must be YYYY-MM-DD when provided.'); + if (!localized(b.title,'en')) fail('Battles need an English title.'); + if (b.preview && !safeUrl(b.preview) && !assetPath(b.preview)) fail('Battle preview must be an HTTPS URL or assets/ path.'); + if (b.outcome && !['victory','defeat','draw','recorded'].includes(b.outcome)) fail('Unknown battle outcome.'); + for (const key of ['kills','deaths']) if (b[key] != null && (!Number.isInteger(b[key]) || b[key] < 0)) fail(`${key} must be a nonnegative integer.`); + } + if (!assetPath(rewards.jerseyImage)) fail('Jersey image must be an assets/ path.'); + if (!Number.isFinite(rewards.firstToTargetSilver) || rewards.firstToTargetSilver <= 0) fail('Invalid milestone reward.'); + if (!rewards.categories?.length) fail('Add at least one reward category.'); + for (const r of rewards.categories) { + if (!Number.isFinite(r.target) || r.target <= 0 || !r.podium?.length || r.podium.length > 3 || r.podium.some(n => !Number.isFinite(n) || n <= 0)) fail(`Invalid rewards for ${r.id}`); + } +} diff --git a/scripts/render-battles.mjs b/scripts/render-battles.mjs new file mode 100644 index 0000000..1d6ad3c --- /dev/null +++ b/scripts/render-battles.mjs @@ -0,0 +1,26 @@ +import { escapeHtml as e, localized } from './lib.mjs'; +import { directPreview } from './battle-previews.mjs'; + +export function battleDetails(url) { + const u=new URL(url); + const combined=/\/battles\/multi\/?$/.test(u.pathname); + const ids=combined?[...new Set((u.searchParams.get('ids')||'').split(',').filter(id=>/^\d+$/.test(id)))]:[u.pathname.split('/').filter(Boolean).pop()].filter(id=>/^\d+$/.test(id)); + return {combined,ids,region:u.hostname==='europe.albionbb.com'?'europe':u.hostname}; +} + +export function renderBattleCards({battles,previews,lang,base,icon,t}) { + if (!battles.length) return ''; + const number=n=>new Intl.NumberFormat(lang==='fa'?'fa-IR':'en-US').format(n); + const sorted=[...battles].sort((a,b)=>(b.date||'').localeCompare(a.date||'')); + // Combined reports may overlap with single reports; count unique, explicit battle IDs. + const engagements=new Set(battles.flatMap(b=>battleDetails(b.url).ids)).size; + const cards=sorted.map((battle,index)=>{ + const info=battleDetails(battle.url); + const preview=previews[battle.url]||battle.preview||directPreview(battle.url); + const image=preview?`${e(localized(battle.title,lang))} — AlbionBB`:''; + const outcome=battle.outcome||'recorded'; + const date=battle.date?``:e(t.battleArchive); + return `
${image}
${icon(info.combined?'shield':'swords')}${e(info.combined?t.combinedReport:t.singleReport)}${e(info.region==='europe'?t.europe:info.region)}
${number(info.ids.length||1)}${e(info.ids.length===1?t.engagement:t.engagements)}
${date}${e(t[outcome])}

${e(localized(battle.title,lang))}

${info.ids.map(id=>`#${e(id)}`).join('')}
${battle.kills!=null||battle.deaths!=null?`
${e(t.kills)}
${battle.kills==null?'—':number(battle.kills)}
${e(t.deaths)}
${battle.deaths==null?'—':number(battle.deaths)}
`:''}
`; + }).join(''); + return `
${number(battles.length)}${e(t.archivedReports)}
${number(engagements)}${e(t.loggedEngagements)}

${icon('shield')}${e(t.archiveMotto)}

${cards}
`; +} diff --git a/scripts/serve.mjs b/scripts/serve.mjs new file mode 100644 index 0000000..02a16be --- /dev/null +++ b/scripts/serve.mjs @@ -0,0 +1,17 @@ +import http from 'node:http'; +import { readFile, stat } from 'node:fs/promises'; +import { resolve, extname, sep } from 'node:path'; +import { spawnSync } from 'node:child_process'; +const built = spawnSync(process.execPath, ['scripts/build.mjs'], { stdio:'inherit' }); +if (built.status) process.exit(built.status); +const root=resolve('dist'); +const types={'.html':'text/html; charset=utf-8','.css':'text/css','.js':'text/javascript','.jpg':'image/jpeg','.png':'image/png','.webp':'image/webp','.svg':'image/svg+xml','.xml':'application/xml','.txt':'text/plain'}; +http.createServer(async(req,res)=>{ + try { + let path=resolve(root, '.'+decodeURIComponent(new URL(req.url,'http://localhost').pathname)); + if(path!==root && !path.startsWith(root+sep)){res.writeHead(403).end();return;} + if((await stat(path)).isDirectory()) path=resolve(path,'index.html'); + const bytes=await readFile(path); + res.writeHead(200,{'Content-Type':types[extname(path)]||'application/octet-stream','Cache-Control':'no-store'}).end(bytes); + }catch{res.writeHead(404,{'Content-Type':'text/html; charset=utf-8'}).end(await readFile(resolve(root,'404.html')));} +}).listen(Number(process.env.PORT)||4173,'127.0.0.1',()=>console.log(`OneUP preview: http://localhost:${Number(process.env.PORT)||4173}`)); diff --git a/scripts/sync-battles.mjs b/scripts/sync-battles.mjs new file mode 100644 index 0000000..7f9b87f --- /dev/null +++ b/scripts/sync-battles.mjs @@ -0,0 +1,36 @@ +import { mkdir, readFile, writeFile } from 'node:fs/promises'; +import { battleKey, discoverPreview } from './battle-previews.mjs'; +import { safeUrl, validate } from './lib.mjs'; +const site=JSON.parse(await readFile(new URL('../content/site.json',import.meta.url),'utf8')); +const rewards=JSON.parse(await readFile(new URL('../content/rewards.json',import.meta.url),'utf8')); +validate(site,rewards); +const folder=new URL('../public/assets/battles/',import.meta.url); +await mkdir(folder,{recursive:true}); +const mapPath=new URL('previews.json',folder); +let previews={}; +try{previews=JSON.parse(await readFile(mapPath,'utf8'));}catch(e){if(e.code!=='ENOENT')throw e;} +// An optional URL inspects/downloads a report without adding it to the public battle archive. +const inputs=process.argv[2]?[{url:process.argv[2]}]:site.battles; +for (const battle of inputs) { + try { + if (!safeUrl(battle.url) || !/(^|\.)albionbb\.com$/.test(new URL(battle.url).hostname)) throw Error('Expected an HTTPS AlbionBB report URL.'); + if (battle.preview?.startsWith('assets/')) continue; + const imageUrl=await discoverPreview(battle); + // Keep the discovered URL usable by browsers even if downloading it fails here. + // Preserve an existing local cache when the remote image is temporarily unavailable. + if(!previews[battle.url]?.startsWith('assets/')) previews[battle.url]=imageUrl; + const response=await fetch(imageUrl,{signal:AbortSignal.timeout(15000)}); + if(!response.ok)throw Error(`Image returned HTTP ${response.status}`); + const type=response.headers.get('content-type')?.split(';')[0]; + const ext={'image/png':'png','image/jpeg':'jpg','image/webp':'webp'}[type]; + if(!ext)throw Error(`Unsupported image type ${type}`); + if(Number(response.headers.get('content-length'))>10_000_000)throw Error('Preview exceeds 10 MB.'); + const reader=response.body.getReader(); const chunks=[]; let size=0; + while(true){const {value,done}=await reader.read();if(done)break;size+=value.length;if(size>10_000_000){await reader.cancel();throw Error('Preview exceeds 10 MB.');}chunks.push(value);} + const file=`${battleKey(battle.url)}.${ext}`; + await writeFile(new URL(file,folder),Buffer.concat(chunks)); + previews[battle.url]=`assets/battles/${file}`; + console.log(`Downloaded ${imageUrl} → public/assets/battles/${file}`); + }catch(error){console.warn(`Preview unavailable for ${battle.url}: ${error.message}. Existing preview or report link will be used.`);} +} +await writeFile(mapPath,JSON.stringify(previews,null,2)+'\n'); diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..9f471ce --- /dev/null +++ b/src/app.js @@ -0,0 +1,105 @@ +(() => { + document.querySelectorAll('[data-battle-preview]').forEach(img => { + const ready = () => img.closest('.battle-art').classList.add('has-report-preview'); + const fallback = () => { img.hidden = true; img.closest('.battle-art').classList.remove('has-report-preview'); }; + img.addEventListener('load', ready); + img.addEventListener('error', fallback); + if (img.complete) img.naturalWidth ? ready() : fallback(); + }); + const lang = document.documentElement.lang; + const fa = lang === 'fa'; + const base = new URL(fa ? '../' : './', location.href); + const query = new URLSearchParams(location.search); + const explicit = query.get('lang'); + const remembered = document.cookie.split('; ').find(c => c.startsWith('oneup_language='))?.split('=')[1]; + const persist = value => { + document.cookie = `oneup_language=${value}; Max-Age=31536000; Path=/; SameSite=Lax${location.protocol === 'https:' ? '; Secure' : ''}`; + }; + if (['en', 'fa'].includes(explicit)) { + persist(explicit); + if (explicit !== lang) { + const target = new URL(explicit === 'fa' ? 'fa/' : './', base); + target.search = `?lang=${explicit}`; target.hash = location.hash; + location.replace(target); return; + } + query.delete('lang'); + history.replaceState(null, '', location.pathname + (query.size ? `?${query}` : '') + location.hash); + } else if (!fa && remembered === 'fa') { + const target = new URL('fa/', base); target.search = location.search; target.hash = location.hash; + location.replace(target); return; + } + document.querySelectorAll('[data-language]').forEach(a => a.addEventListener('click', () => persist(a.dataset.language))); + + const menu = document.querySelector('.menu-toggle'); + const nav = document.querySelector('#navigation'); + const closeMenu = () => { menu.setAttribute('aria-expanded', 'false'); nav.classList.remove('open'); }; + menu.addEventListener('click', () => { + const open = menu.getAttribute('aria-expanded') !== 'true'; + menu.setAttribute('aria-expanded', String(open)); nav.classList.toggle('open', open); + }); + nav.querySelectorAll('a').forEach(a => a.addEventListener('click', closeMenu)); + document.addEventListener('keydown', event => { if (event.key === 'Escape') closeMenu(); }); + + const tabs = [...document.querySelectorAll('[role="tab"]')]; + function activate(tab) { + tabs.forEach(t => { + const selected = t === tab; + t.setAttribute('aria-selected', String(selected)); t.tabIndex = selected ? 0 : -1; + document.getElementById(t.getAttribute('aria-controls')).hidden = !selected; + }); + } + tabs.forEach((tab,index) => { + tab.addEventListener('click', () => activate(tab)); + tab.addEventListener('keydown', event => { + let next; + if (event.key === 'Home') next = 0; + if (event.key === 'End') next = tabs.length - 1; + if (event.key === 'ArrowRight') next = (index + (fa ? -1 : 1) + tabs.length) % tabs.length; + if (event.key === 'ArrowLeft') next = (index + (fa ? 1 : -1) + tabs.length) % tabs.length; + if (next != null) { event.preventDefault(); activate(tabs[next]); tabs[next].focus(); } + }); + }); + document.querySelectorAll('[data-filter]').forEach(button => button.addEventListener('click', () => { + document.querySelectorAll('[data-filter]').forEach(b => b.setAttribute('aria-pressed', String(b === button))); + let visible = 0; + document.querySelectorAll('.clip-card').forEach(card => { + card.hidden = button.dataset.filter !== 'all' && card.dataset.type !== button.dataset.filter; + if (!card.hidden) visible++; + }); + document.querySelector('.filter-empty').hidden = visible > 0; + })); + + const videoDialog = document.getElementById('video-dialog'); + const container = document.getElementById('video-container'); + document.querySelectorAll('[data-video]').forEach(button => button.addEventListener('click', () => { + document.getElementById('video-title').textContent = button.dataset.title; + const error = document.getElementById('video-error'); error.hidden = true; + document.getElementById('video-original').href = button.dataset.video; + let player; + if (button.dataset.videoType === 'youtube') { + const url = new URL(button.dataset.video); + const id = url.hostname.endsWith('youtu.be') ? url.pathname.slice(1) : url.searchParams.get('v') || url.pathname.split('/')[2]; + player = document.createElement('iframe'); + player.src = `https://www.youtube-nocookie.com/embed/${id}?autoplay=1&rel=0`; + player.title = button.dataset.title; + player.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share'; + player.allowFullscreen = true; player.referrerPolicy = 'strict-origin-when-cross-origin'; + } else { + player = document.createElement('video'); + player.controls = true; player.autoplay = true; player.playsInline = true; + player.src = button.dataset.video; + player.addEventListener('error', () => { error.textContent = document.body.dataset.videoError; error.hidden = false; }); + } + container.replaceChildren(player); videoDialog.showModal(); + })); + videoDialog.addEventListener('close', () => { const video=container.querySelector('video'); if(video) video.pause(); container.replaceChildren(); }); + const jerseyDialog = document.getElementById('jersey-dialog'); + document.querySelector('[data-jersey]').addEventListener('click', event => { event.preventDefault(); jerseyDialog.showModal(); }); + document.querySelectorAll('dialog').forEach(dialog => { + dialog.querySelector('.dialog-close').addEventListener('click', () => dialog.close()); + dialog.addEventListener('click', event => { + const rect = dialog.getBoundingClientRect(); + if (event.target === dialog && (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom)) dialog.close(); + }); + }); +})(); diff --git a/src/styles.css b/src/styles.css new file mode 100644 index 0000000..db87ed1 --- /dev/null +++ b/src/styles.css @@ -0,0 +1,107 @@ +:root{--bg:#101111;--panel:#171818;--text:#f0ede5;--muted:#a5a59d;--accent:#e34850;--accent-heading:#c92c39;--accent-strong:#b51f2f;--accent-hover:#cb2c3c;--on-accent:#fff5f5;--line:#ffffff16;--body:'Barlow',Arial,sans-serif;--display:'Barlow Condensed','Arial Narrow',Impact,sans-serif}*{box-sizing:border-box}html{scroll-behavior:smooth;scroll-padding-top:100px}body{margin:0;background:var(--bg);color:var(--text);font-family:var(--body);font-size:16px;line-height:1.65}body:has(dialog[open]){overflow:hidden}::selection{background:var(--accent-strong);color:var(--on-accent)}a{color:inherit;text-decoration:none}button{font:inherit;color:inherit;cursor:pointer}button,a{-webkit-tap-highlight-color:transparent}button{border:0}img{max-width:100%;display:block}svg{display:block}.icon{width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}.svg-defs{position:absolute;width:0;height:0;overflow:hidden}button:focus-visible,a:focus-visible{outline:2px solid var(--accent);outline-offset:6px}[hidden]{display:none!important}.skip-link{position:fixed;inset-block-start:10px;inset-inline-start:10px;background:var(--accent-strong);color:var(--on-accent);padding:10px 20px;z-index:100;transform:translateY(-150%)}.skip-link:focus{transform:translateY(0)}.site-header{height:92px;position:relative;z-index:10;border-bottom:1px solid var(--line);background:#101111ee}.header-inner{max-width:1440px;margin:auto;height:100%;padding:0 5%;display:flex;align-items:center;justify-content:space-between;gap:32px}.brand{display:flex;gap:12px;align-items:center}.brand img{border-radius:50%;border:1px solid #7776}.brand>span{font-family:var(--display);font-size:29px;font-weight:800;letter-spacing:1.3px;line-height:1}.brand-up{color:var(--accent)}.brand small{font-family:var(--body);font-size:8px;letter-spacing:2px;display:block;margin-top:8px;color:var(--muted)}nav{display:flex;gap:30px}nav a{font-size:13px;color:#bdbcb4;transition:color .2s}nav a:hover{color:var(--accent)}.header-actions{display:flex;align-items:center;gap:26px}.languages{display:flex;align-items:center;gap:8px;font-size:12px;white-space:nowrap}.languages a{color:var(--muted)}.languages a[aria-current]{color:var(--accent)}.languages>span{color:#565650}.button{display:inline-flex;align-items:center;justify-content:center;gap:28px;padding:17px 25px;background:var(--accent-strong);color:var(--on-accent);font-size:13px;font-weight:700;line-height:1.4;min-height:54px;transition:background .2s,transform .2s}.button:hover{background:var(--accent-hover);transform:translateY(-2px)}.button .icon{width:18px;height:18px}.button-small{padding:12px 18px;gap:20px;min-height:43px}.menu-toggle{display:none}.hero{position:relative;min-height:750px;max-width:1600px;margin:auto;overflow:hidden;background:radial-gradient(ellipse at 80% 45%,#4b101c26,transparent 65%)}.hero:after{content:'';position:absolute;inset:0;background:repeating-linear-gradient(115deg,transparent 0 140px,#ffffff02 141px 142px);pointer-events:none}.hero-inner{position:relative;z-index:2;max-width:1296px;margin:auto;padding:68px 5% 110px;pointer-events:none}.hero-inner a{pointer-events:auto}.status{display:flex;align-items:center;gap:9px;font-size:10px;font-weight:600;letter-spacing:1.8px;color:#c0beb2}.status>span{width:6px;height:6px;background:var(--accent);border-radius:50%;box-shadow:0 0 13px #c92c3960}.eyebrow{font-size:10px;font-weight:600;letter-spacing:2.4px;color:var(--accent);margin:0 0 23px;text-transform:uppercase}.hero-eyebrow{margin-top:48px;margin-bottom:14px;color:#aeaa9a}.hero h1{font-family:var(--display);font-size:clamp(78px,8.5vw,136px);font-weight:800;line-height:.93;letter-spacing:-2px;margin:0;text-transform:uppercase}.hero h1 span{color:var(--accent-heading)}.hero-copy{font-size:15px;color:#b6b6af;max-width:400px;line-height:1.8;margin:28px 0 29px}.hero-buttons{display:flex;gap:26px;align-items:center}.text-button{display:flex;align-items:center;gap:11px;font-size:13px}.small-play{width:34px;height:34px;border:1px solid #7776;display:grid;place-items:center;border-radius:50%}.small-play .icon{width:16px;height:16px}.hero-proof{display:flex;align-items:center;gap:17px;max-width:395px;margin-top:48px}.hero-proof strong{font-family:var(--display);font-size:40px;font-weight:600;line-height:1}.hero-proof>span{font-size:9px;letter-spacing:1.6px;max-width:90px;line-height:1.5;color:var(--muted)}.proof-line{height:1px;background:var(--line);flex:1}.hero-proof>.icon{color:var(--accent);width:29px;height:29px}.hero-art{position:absolute;top:16px;bottom:40px;inset-inline-end:-5%;width:65%;display:flex;align-items:center;justify-content:center;isolation:isolate}.hero-art:after{content:'';position:absolute;inset:0;background:radial-gradient(ellipse,transparent 24%,#101111 71%);z-index:1}.hero-art img{width:min(760px,100%);height:auto;filter:brightness(.72) saturate(1.1);mix-blend-mode:lighten;mask-image:radial-gradient(ellipse,#000 40%,transparent 73%)}.orbit{position:absolute;border:1px solid #c92c391b;aspect-ratio:1;width:86%;border-radius:50%;z-index:2;pointer-events:none}.orbit:before,.orbit:after{content:'+';position:absolute;color:var(--accent);font-size:18px;line-height:1;opacity:.6}.orbit:before{top:13%;left:13%}.orbit:after{bottom:13%;right:13%}.orbit-two{width:95%;border-style:dashed;border-color:#ffffff09}.art-caption{position:absolute;bottom:7%;font-size:8px;letter-spacing:5px;color:#91656a;z-index:2}.scroll-cue{position:absolute;bottom:30px;inset-inline-start:7.5%;display:flex;align-items:center;gap:12px;z-index:3;font-size:8px;letter-spacing:2px;color:#8d8c83}.scroll-cue>span{font-size:22px;color:var(--accent)}.hero-coordinate{position:absolute;bottom:37px;inset-inline-end:6%;font-size:8px;letter-spacing:2px;color:#64645d}.motto-strip{display:flex;gap:48px;align-items:center;white-space:nowrap;overflow:hidden;justify-content:center;border-top:1px solid #c92c3926;border-bottom:1px solid #c92c3926;padding:16px 0;background:#c92c3906;font-family:var(--display);font-size:18px;letter-spacing:3px;color:#888579}.motto-strip b{color:var(--accent);font-size:14px}.section{max-width:1296px;padding:100px 5%;margin:auto;scroll-margin-top:28px}h2{font-family:var(--display);font-size:clamp(40px,4.4vw,64px);font-weight:600;letter-spacing:-.5px;line-height:1.06;margin:0}h2 span{color:#93938b}h3{line-height:1.2}.section-top{display:flex;align-items:flex-end;justify-content:space-between;gap:45px;margin-bottom:40px}.section-intro{font-size:14px;line-height:1.8;max-width:325px;color:var(--muted);margin:0 0 4px}.guild-overview{display:grid;grid-template-columns:1.1fr 1fr;gap:90px;align-items:center}.guild-copy p{color:var(--muted);font-size:15px}.tiny-rule{display:block;width:36px;height:2px;background:var(--accent);margin-bottom:22px}.guild-copy .signature{color:var(--accent);font-family:var(--display);font-size:21px;letter-spacing:2px;text-transform:uppercase}.pillars{display:grid;grid-template-columns:repeat(3,1fr);margin-top:48px;border:1px solid var(--line)}.pillar{padding:30px 28px;border-inline-end:1px solid var(--line);background:linear-gradient(145deg,#ffffff03,transparent)}.pillar:last-child{border:0}.pillar-top{display:flex;justify-content:space-between;align-items:center;color:var(--accent)}.pillar-top .icon{width:28px;height:28px}.pillar-top>span{font-family:var(--display);font-size:18px;color:#62625b}.pillar h3{font-family:var(--display);font-size:27px;font-weight:500;margin:26px 0 12px}.pillar p{color:var(--muted);font-size:13px;margin:0;line-height:1.9}.chronicles-section{border-top:1px solid var(--line)}.filters{display:flex;gap:26px;border-bottom:1px solid var(--line);margin-bottom:28px}.filters button{background:none;padding:12px 0;color:var(--muted);font-size:12px;position:relative}.filters button[aria-pressed=true]{color:var(--accent)}.filters button[aria-pressed=true]:after{content:'';position:absolute;inset-inline:0;bottom:-1px;height:2px;background:var(--accent)}.clip-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:28px}.clip-card:first-child:nth-last-child(odd){grid-column:1/-1}.clip-visual{position:relative;padding:0;width:100%;display:block;overflow:hidden;background:#21221e;aspect-ratio:16/9}.clip-card.featured .clip-visual{max-height:520px}.clip-visual:after{content:'';position:absolute;inset:0;background:linear-gradient(transparent 40%,#0009)}.clip-visual>img{width:100%;height:100%;object-fit:cover;filter:saturate(.65);transition:transform .5s,filter .5s}.clip-visual:hover>img{transform:scale(1.035);filter:saturate(1)}.play-button{position:absolute;inset:0;margin:auto;display:grid;place-items:center;width:60px;height:60px;border:1px solid #ed8c9580;border-radius:50%;z-index:1;background:#1b101366;backdrop-filter:blur(8px)}.play-button .icon{width:25px;height:25px;color:var(--accent)}.video-source,.duration{position:absolute;bottom:17px;font-size:10px;z-index:1}.video-source{inset-inline-start:20px;text-transform:uppercase;letter-spacing:1.7px}.duration{inset-inline-end:20px;background:#0009;padding:2px 7px}.clip-caption{display:flex;align-items:center;gap:18px;padding:20px 0}.clip-number{font-family:var(--display);font-size:24px;color:var(--accent)}.clip-caption h3{font-family:var(--display);font-weight:500;font-size:26px;margin:0}.clip-caption p{font-size:12px;color:var(--muted);margin:6px 0 0}.clip-caption>.icon{margin-inline-start:auto;color:var(--accent)}.empty-state{border:1px solid var(--line);background:linear-gradient(130deg,#ffffff03,transparent);color:var(--muted)}.empty-state h3{color:var(--text);font-family:var(--display);font-size:28px;font-weight:500;margin:0 0 10px}.empty-state p{font-size:13px;margin:0;line-height:1.8}.footage-empty{position:relative;min-height:250px;padding:50px;display:flex;align-items:center;gap:35px;overflow:hidden;background:radial-gradient(ellipse at right,#c92c3909,transparent 70%)}.empty-emblem{width:72px;height:72px;flex-shrink:0;border:1px solid #c92c3940;border-radius:50%;display:grid;place-items:center;color:var(--accent)}.empty-index{position:absolute;bottom:17px;inset-inline-end:24px;font-size:9px;letter-spacing:2px;color:#6f6e64}.battles-section{background:#151615;max-width:none;padding-inline:max(5%,calc((100vw - 1166px)/2))}.board-aside{max-width:310px;font-size:14px;color:var(--muted)}.board-aside>p{margin:0 0 14px}.text-link{display:inline-flex;align-items:center;gap:10px;font-size:12px;color:var(--accent)}.text-link .icon{width:16px;height:16px}.board{border:1px solid #ffffff1c;background:#101111}.board-top{display:flex;justify-content:space-between;align-items:center;gap:20px;padding:19px 25px;border-bottom:1px solid var(--line)}.board-top>span:first-child{display:flex;align-items:center;gap:12px;font-family:var(--display);font-size:19px;letter-spacing:1.2px}.board-top .icon{width:20px;color:var(--accent)}.muted{color:#74756c}.board-provider{font-size:8px;letter-spacing:1.7px;color:#9d9e92}.battle-empty{border:0;min-height:230px;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:35px;text-align:center}.battle-empty>.icon{color:#b66b73;width:32px;height:32px;margin-bottom:22px}.battle-empty h3{font-size:26px}.table-scroll{width:100%;overflow-x:auto;scrollbar-color:#86343f #1a1b18}table{width:100%;border-collapse:collapse;text-align:start}th{text-align:start;font-weight:500}thead th{color:#888a80;font-size:10px;padding:16px 20px;border-bottom:1px solid var(--line)}tbody td,tbody th{padding:20px;border-bottom:1px solid var(--line);font-size:13px}tbody tr:last-child>*{border-bottom:0}.battle-table{min-width:760px}.battle-table td:first-child{color:var(--muted);font-size:12px}.battle-table th[scope=row]{font-weight:600}.outcome{font-size:10px;padding:4px 9px;border:1px solid #ffffff23;color:var(--muted)}.outcome.victory{color:#adca9c;border-color:#adca9c30;background:#adca9c09}.outcome.defeat{color:#df8e80;border-color:#df8e8030}.reward-tabs{display:flex;border-bottom:1px solid var(--line);gap:22px}.reward-tabs button{background:none;padding:15px 0;color:var(--muted);font-size:13px;position:relative}.reward-tabs button[aria-selected=true]{color:var(--accent)}.reward-tabs button[aria-selected=true]:after{content:'';height:2px;background:var(--accent);position:absolute;bottom:-1px;inset-inline:0}.rewards-layout{display:grid;grid-template-columns:minmax(0,1.8fr) minmax(0,1fr);gap:44px}.reward-rule{color:var(--muted);font-size:12px;line-height:1.9;min-height:50px;margin:20px 0}.rewards-table{min-width:440px}.rewards-table thead th{padding:13px 8px}.rewards-table td,.rewards-table tbody th{padding:17px 8px;font-size:12px}.rewards-table tbody th{width:46%;white-space:nowrap}.row-number{font-size:10px;margin-inline-end:14px;color:#62665c}.target-number{color:#c1c3b5;font-family:var(--display);font-size:20px}.rewards-table strong{color:var(--accent);font-family:var(--display);font-size:23px;font-weight:500;white-space:nowrap}.rewards-table strong small{font-family:var(--body);font-size:9px;color:#999c8f;margin-inline-start:2px}.jersey-bonus{font-size:9px;display:block;color:#a5a79a}.podium-table tbody th{width:auto}.podium-table strong{font-size:21px}.silver-label{display:block;font-size:9px;color:var(--muted)}.jersey-card{border:1px solid #c92c3938;background:#1d1517;align-self:start}.jersey-card-top{display:flex;justify-content:space-between;align-items:center;padding:17px 20px;font-size:9px;letter-spacing:1.6px;color:var(--accent)}.jersey-card-top .icon{width:18px}.jersey-image{display:block;position:relative;overflow:hidden}.jersey-image img{width:100%;height:auto;filter:saturate(.65);transition:transform .5s}.jersey-image:hover img{transform:scale(1.025)}.jersey-image>span{position:absolute;inset-inline-end:12px;bottom:12px;background:#111b;padding:8px}.jersey-image .icon{width:16px;height:16px}.jersey-description{padding:24px}.jersey-description .eyebrow{font-size:8px;margin-bottom:10px}.jersey-description h3{font-family:var(--display);font-size:30px;font-weight:500;margin:0 0 12px}.jersey-description>p:last-child{font-size:12px;line-height:1.9;color:var(--muted);margin:0}.community-section{position:relative;max-width:none;isolation:isolate;background:#191315;border-top:1px solid #c92c3920;border-bottom:1px solid #c92c3920;overflow:hidden;padding-inline:max(5%,calc((100vw - 1166px)/2))}.community-content{position:relative;z-index:1}.community-content h2{font-size:clamp(48px,5.2vw,76px)}.community-content h2 span{color:var(--accent-heading)}.community-content>p{font-size:14px;color:var(--muted);max-width:400px;margin-top:24px}.community-crest{position:absolute;z-index:-1;width:460px;inset-inline-end:6%;top:-90px;opacity:.13;mask-image:radial-gradient(ellipse,#000,transparent 72%)}.social-grid{position:relative;z-index:1;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:18px;margin-top:50px}.social-card{border:1px solid #ffffff26;background:#10111190;display:flex;align-items:center;gap:17px;padding:24px 20px;transition:border-color .2s,background .2s}.social-card:hover{border-color:#c92c3970;background:#251719}.social-card>.icon{color:var(--accent);width:26px;height:26px}.social-card strong{font-family:var(--display);font-weight:500;font-size:25px;display:block}.social-card small{font-size:11px;color:var(--muted);display:block;margin-top:5px;line-height:1.5}.social-action{margin-inline-start:auto;font-size:8px;max-width:44px;line-height:1.5;color:#ac9699}.social-action .icon{width:17px;height:17px;color:var(--accent)}.social-card.pending{border-style:dashed}.site-footer{max-width:1440px;margin:auto;display:flex;align-items:center;justify-content:space-between;gap:40px;padding:38px 5%}.footer-wordmark{font-family:var(--display);font-weight:700;font-size:30px;line-height:1}.footer-wordmark>span{color:var(--accent)}.footer-wordmark small{display:block;font:10px var(--body);color:var(--muted);margin-top:10px;direction:initial}.site-footer>p{font-size:10px;color:#7d8175;text-align:end;margin-inline-start:auto;line-height:1.9}.back-top{width:38px;height:38px;display:grid;place-items:center;border:1px solid #ffffff26;color:var(--accent)}dialog{border:1px solid #c92c3955;background:#151614;color:var(--text);padding:22px;max-width:1000px;width:calc(100% - 40px);max-height:92dvh}dialog::backdrop{background:#000d;backdrop-filter:blur(7px)}.dialog-top{display:flex;align-items:center;justify-content:space-between;gap:25px;margin-bottom:18px}.dialog-top h2{font-size:28px}.dialog-close{background:#ffffff0a;color:var(--text);width:40px;height:40px;font-size:30px;line-height:1;flex-shrink:0}#video-container{aspect-ratio:16/9;background:#000}#video-container>iframe,#video-container>video{width:100%;height:100%;border:0}#video-original{font-size:12px;color:var(--accent);display:inline-block;margin-top:15px}#video-error{font-size:13px;color:var(--muted)}#jersey-dialog{width:min(800px,calc(100% - 30px));padding:0}#jersey-dialog>.dialog-close{position:absolute;top:12px;inset-inline-end:12px;background:#111d}#jersey-dialog>img{width:100%;height:auto}.filter-empty{color:var(--muted);font-size:14px}.not-found{min-height:100vh;display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;padding:25px}.not-found h1{font-family:var(--display);font-size:80px;line-height:1;margin:0}.not-found h1 span{color:var(--accent)}.not-found>a:last-child{margin-top:20px;color:var(--muted)} +[dir=rtl]{--body:'Vazirmatn',Tahoma,sans-serif;--display:'Vazirmatn',Tahoma,sans-serif}[dir=rtl] .hero h1{font-size:clamp(64px,7.4vw,108px);line-height:1.3;letter-spacing:-4px}[dir=rtl] h2{font-size:clamp(32px,3.5vw,49px);line-height:1.6;letter-spacing:-1.4px}[dir=rtl] .eyebrow,[dir=rtl] .status,[dir=rtl] .scroll-cue{letter-spacing:0}[dir=rtl] .brand>span,[dir=rtl] .footer-wordmark,[dir=rtl] .motto-strip,[dir=rtl] .hero-proof strong,[dir=rtl] .board-top>span:first-child{font-family:'Barlow Condensed',Arial,sans-serif}[dir=rtl] .hero-copy{line-height:2;font-size:13px}[dir=rtl] .hero-art{transform:scaleX(-1)}[dir=rtl] .hero-art img,[dir=rtl] .art-caption{transform:scaleX(-1)}[dir=rtl] .pillar h3,[dir=rtl] .clip-caption h3,[dir=rtl] .empty-state h3,[dir=rtl] .jersey-description h3{font-size:21px;line-height:1.7}[dir=rtl] .section-intro,[dir=rtl] .guild-copy p,[dir=rtl] .board-aside{font-size:13px}[dir=rtl] .hero .icon use[href='#i-diagonal'],[dir=rtl] .button .icon,[dir=rtl] .text-link .icon{transform-origin:center;transform:scaleX(-1)}[dir=rtl] .rewards-table strong{font-size:17px}[dir=rtl] .rewards-table tbody th,[dir=rtl] .rewards-table td{font-size:11px}[dir=rtl] .target-number{font-size:17px}[dir=rtl] .rewards-layout{grid-template-columns:minmax(0,1.9fr) minmax(0,1fr)}[dir=rtl] .social-card strong{font-family:'Barlow Condensed',Arial,sans-serif}[dir=rtl] .signature{font-family:'Barlow Condensed',Arial,sans-serif} +@media(min-width:1500px){.hero-inner{padding-inline:0}.hero-art{inset-inline-end:0;width:64%}.scroll-cue{inset-inline-start:9.5%}}@media(max-width:1100px){nav{gap:18px}.header-inner{gap:18px}.header-actions{gap:20px}.hero-art{width:70%;inset-inline-end:-16%;opacity:.8}.hero-inner{padding-inline:5%}.hero h1{font-size:104px}.hero-copy{max-width:360px}.guild-overview{gap:50px}.rewards-layout{gap:25px}.social-grid{gap:12px}.social-card{gap:12px;padding:20px 14px}.social-card small{font-size:10px}.social-card strong{font-size:24px}.social-action{font-size:7px}.row-number{margin-inline-end:8px}.site-header .button-small{display:none}.board-top{padding-inline:20px}} +@media(max-width:760px){html{scroll-padding-top:30px}.site-header{height:78px}.header-inner{padding-inline:6%;gap:18px}.brand>span{font-size:25px}.brand img{width:38px;height:38px}.brand small{font-size:7px}.header-actions{margin-inline-start:auto}.languages{font-size:12px}.menu-toggle{display:flex;order:3;background:none;width:28px;height:34px;padding:5px 0;justify-content:center;flex-direction:column;gap:6px}.menu-toggle span{display:block;width:24px;height:1px;background:var(--text);transition:transform .2s}.menu-toggle[aria-expanded=true] span:first-child{transform:translateY(3.5px) rotate(45deg)}.menu-toggle[aria-expanded=true] span:last-child{transform:translateY(-3.5px) rotate(-45deg)}nav{display:none;position:absolute;top:78px;inset-inline:0;padding:24px 6%;background:#171817;border-bottom:1px solid #c92c3930;flex-direction:column;gap:20px}nav.open{display:flex}nav a{font-size:15px}.hero{min-height:760px}.hero-inner{padding:40px 6% 100px}.hero-eyebrow{margin-top:45px;font-size:9px}.hero h1{font-size:clamp(78px,14vw,105px);letter-spacing:-1.5px}.hero-copy{max-width:320px;font-size:14px;margin-top:26px}.hero-art{width:98%;inset-inline-end:-36%;top:30px;bottom:75px;opacity:.42;align-items:flex-start;padding-top:30px}.hero-art img{width:660px;max-width:none;flex-shrink:0}.hero-art:after{background:linear-gradient(90deg,#10111177,transparent 80%)}.orbit{display:none}.art-caption{display:none}.hero-proof{margin-top:44px;max-width:330px}.hero-buttons{gap:22px}.hero-buttons .button{padding:16px 20px;gap:16px}.hero-buttons .text-button{font-size:12px;gap:8px}.scroll-cue{inset-inline-start:6%;font-size:7px;bottom:28px;letter-spacing:1px}.hero-coordinate{display:none}.motto-strip{gap:30px;font-size:15px;padding:12px 0;letter-spacing:2px}.section{padding:65px 6%}.guild-overview{grid-template-columns:1fr;gap:25px}.guild-copy{max-width:520px}.guild-copy .signature{font-size:20px}.tiny-rule{display:none}.guild-copy p{font-size:14px}.pillars{grid-template-columns:1fr;margin-top:30px}.pillar{padding:26px;border-inline-end:0;border-bottom:1px solid var(--line)}.pillar h3{margin-top:18px}.pillar p{max-width:420px}.section-top{align-items:flex-start;flex-direction:column;gap:23px;margin-bottom:30px}.section-intro{max-width:460px;font-size:13px}.section-heading .eyebrow{font-size:9px;margin-bottom:18px}h2{font-size:46px}.footage-empty{padding:34px 25px;min-height:260px;gap:24px;align-items:flex-start;flex-direction:column}.empty-emblem{width:48px;height:48px}.empty-state h3{font-size:25px}.empty-state p{font-size:12px;max-width:400px}.clip-grid{grid-template-columns:1fr;gap:18px}.clip-card:first-child:nth-last-child(odd){grid-column:auto}.clip-caption h3{font-size:24px}.board-aside{max-width:440px;font-size:13px}.board-top{padding:17px;gap:12px}.board-top>span:first-child{font-size:16px;gap:8px}.board-provider{font-size:6px;letter-spacing:1px}.board-top .icon{width:17px}.rewards-layout,[dir=rtl] .rewards-layout{grid-template-columns:1fr;gap:30px}.jersey-card{display:grid;grid-template-columns:1fr 1fr;align-items:center}.jersey-card-top{grid-column:1/-1}.jersey-description{padding:20px}.jersey-description h3{font-size:27px}.jersey-description>p:last-child{font-size:11px}.reward-tabs{gap:25px}.reward-tabs button{font-size:12px}.rewards-table tbody th{width:45%}.community-content h2{font-size:52px}.community-content>p{font-size:13px}.social-grid{grid-template-columns:1fr;margin-top:30px;gap:12px}.social-card{padding:22px;gap:20px}.social-card small{font-size:12px}.social-card strong{font-size:27px}.social-action{max-width:none;font-size:10px}.community-crest{width:400px;inset-inline-end:-100px;top:-10px}.site-footer{padding:32px 6%;flex-wrap:wrap;gap:25px}.site-footer>p{order:3;width:100%;text-align:start;font-size:9px}.back-top{margin-inline-start:auto}.footer-wordmark small{font-size:9px}.dialog-top h2{font-size:23px}dialog{padding:15px;width:calc(100% - 24px)}[dir=rtl] .hero h1{font-size:clamp(65px,11vw,90px);letter-spacing:-3px}[dir=rtl] .hero-copy{max-width:310px;font-size:12px}[dir=rtl] h2{font-size:34px}[dir=rtl] .hero{min-height:790px}[dir=rtl] .hero-buttons{gap:16px}[dir=rtl] .hero-buttons .button{font-size:12px}[dir=rtl] .hero-buttons .text-button{font-size:11px}[dir=rtl] .community-content h2{font-size:38px}[dir=rtl] .hero-art:after{background:linear-gradient(-90deg,#10111177,transparent 80%)}[dir=rtl] .jersey-description h3{font-size:20px}} +@media(max-width:390px){.hero-buttons{gap:14px}.hero-buttons .button{font-size:12px;padding-inline:15px}.hero-buttons .text-button{font-size:11px}.hero-proof strong{font-size:36px}.hero h1{font-size:78px}.rewards-table{min-width:420px}.jersey-card{display:block}.jersey-image{max-height:320px}.jersey-image img{object-fit:cover;object-position:center;max-height:320px}.board-provider{display:none}.hero-eyebrow{font-size:8px}[dir=rtl] .hero-buttons{gap:10px}} +@media(prefers-reduced-motion:reduce){html{scroll-behavior:auto}*,*:before,*:after{transition:none!important;animation:none!important}}@media print{.site-header,.hero-art,.hero-coordinate,.scroll-cue,dialog,.motto-strip,.filters{display:none}body{background:white;color:black}.section{padding:30px 0;break-inside:avoid}.hero{min-height:0}.hero-inner{padding:30px 0}.hero h1{font-size:60px}.hero-copy,.section-intro,.guild-copy p{color:#333}h2{font-size:35px}a{color:#333}.community-section,.battles-section{background:white}.social-grid{grid-template-columns:repeat(3,1fr)}} +.recruitment-grid{position:relative;z-index:1;display:grid;grid-template-columns:1fr 1fr;gap:24px;margin-top:36px}.community-content:has(+.recruitment-grid)>p{max-width:660px}.recruitment-card{background:#101111b3;border:1px solid var(--line);padding:28px 30px}.recruitment-card-heading{display:flex;gap:14px;align-items:center;margin-bottom:24px}.recruitment-card-heading>.icon{color:var(--accent);width:25px;height:25px}.recruitment-card h3{font-family:var(--display);font-size:29px;font-weight:500;margin:0}.recruitment-activities,.recruitment-requirements{padding:0;margin:0;list-style:none}.recruitment-activities li{display:flex;align-items:center;gap:14px;padding:13px 0;border-bottom:1px solid var(--line);font-size:14px;color:var(--text)}.recruitment-activities li:last-child{border-bottom:0;padding-bottom:0}.recruitment-activities li:before{content:'';width:5px;height:5px;background:var(--accent-heading);transform:rotate(45deg);flex-shrink:0}.fame-requirements{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin:0 0 24px}.fame-requirements>div{display:flex;flex-direction:column-reverse;align-items:flex-start;border-inline-start:2px solid var(--accent-strong);padding-inline-start:16px}.fame-requirements dt{font-size:11px;color:var(--muted);margin-top:5px}.fame-requirements dd{margin:0;font-family:'Barlow Condensed','Arial Narrow',sans-serif;font-size:42px;font-weight:600;line-height:1.1;color:var(--accent)}.recruitment-requirements li{position:relative;padding-inline-start:20px;font-size:13px;color:var(--muted);line-height:1.8;margin-top:13px}.recruitment-requirements li:before{content:'✓';position:absolute;inset-inline-start:0;color:var(--accent)}.application-callout{position:relative;z-index:1;display:flex;align-items:center;gap:32px;justify-content:space-between;padding:30px;margin-top:24px;border:1px solid #c92c3938;border-inline-start:3px solid var(--accent-strong);background:linear-gradient(115deg,#c92c390a,#10111166)}.application-callout h3{font-family:var(--display);font-size:30px;font-weight:500;margin:0 0 12px}.application-callout p{font-size:13px;color:var(--muted);max-width:700px;margin:10px 0 0;line-height:1.9}.application-callout .button{flex-shrink:0;gap:14px}.application-callout .application-instructions{color:var(--text)}.apply-channel{display:inline-block;padding:1px 7px;border:1px solid #c92c3938;background:#c92c3914;color:var(--accent);font-weight:600;border-radius:3px;margin-inline:2px}.application-callout .recruitment-welcome{font-size:12px;color:var(--accent);margin-top:16px}[dir=rtl] .recruitment-card h3,[dir=rtl] .application-callout h3{font-size:23px;line-height:1.7}[dir=rtl] .recruitment-activities li,[dir=rtl] .recruitment-requirements li,[dir=rtl] .application-callout p{font-size:12px;line-height:2}@media(max-width:900px){.application-callout{align-items:flex-start;flex-direction:column;gap:22px}}@media(max-width:760px){.recruitment-grid{grid-template-columns:1fr;gap:18px;margin-top:28px}.recruitment-card{padding:24px}.recruitment-card h3{font-size:27px}.recruitment-activities li{font-size:13px}.application-callout{padding:24px;margin-top:18px}.application-callout h3{font-size:28px}.application-callout p{font-size:12px}.fame-requirements dd{font-size:38px}[dir=rtl] .recruitment-card h3,[dir=rtl] .application-callout h3{font-size:21px}} + +/* Battle archive: offline artwork, report previews, and an optional detailed ledger. */ +.battle-archive-strip { + display: flex; + align-items: center; + gap: 34px; + padding: 18px 0; + margin-bottom: 30px; + border-block: 1px solid var(--line); +} +.battle-archive-strip > div { display: flex; align-items: center; gap: 11px; } +.battle-archive-strip strong { font: 500 35px/1 'Barlow Condensed', sans-serif; color: var(--text); } +.battle-archive-strip span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; } +.battle-archive-strip > p { display: flex; align-items: center; gap: 12px; margin: 0; margin-inline-start: auto; font-size: 11px; color: var(--muted); } +.battle-archive-strip .icon { color: var(--accent); width: 19px; height: 19px; } +.battle-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 26px; } +.battle-card { min-width: 0; border: 1px solid #ffffff20; background: #101111; transition: border-color .25s, transform .25s; } +.battle-card:hover, .battle-card:focus-within { border-color: #c92c3980; transform: translateY(-4px); } +.battle-card:only-child { grid-column: 1 / -1; max-width: 860px; width: 100%; margin-inline: auto; } +.battle-card-link { display: flex; flex-direction: column; height: 100%; } +.battle-art { position: relative; height: 290px; overflow: hidden; isolation: isolate; background: #141719; border-bottom: 1px solid #c92c3930; } +.battle-terrain { position: absolute; inset: 0; z-index: -2; background: url('./battle-terrain.svg') center / cover no-repeat; transition: transform .7s, opacity .3s; } +.battle-art::after { content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; background: linear-gradient(#07090bb8, transparent 40%, #07090bc9), linear-gradient(90deg, #10111140, transparent 70%); } +.battle-card--campaign .battle-terrain { transform: scale(1.17) rotate(-9deg); filter: saturate(.85); background-position: 30% 60%; } +.battle-card:hover .battle-terrain { transform: scale(1.05); } +.battle-card--campaign:hover .battle-terrain { transform: scale(1.24) rotate(-9deg); } +.battle-art-top { position: absolute; top: 20px; inset-inline: 22px; display: flex; align-items: center; justify-content: space-between; gap: 15px; z-index: 2; } +.battle-type { display: flex; align-items: center; gap: 9px; padding: 6px 10px; background: #171215d9; border: 1px solid #c92c3955; color: #f0d4d8; font-size: 9px; letter-spacing: 1.3px; text-transform: uppercase; } +.battle-type .icon { width: 15px; height: 15px; color: var(--accent); } +.battle-region { color: #c1b7ba; font-size: 9px; text-transform: uppercase; letter-spacing: 1.8px; } +.battle-region::before { content: ''; display: inline-block; width: 5px; height: 5px; border: 1px solid var(--accent); margin-inline-end: 7px; transform: rotate(45deg); } +.battle-crest { position: absolute; top: 81px; inset-inline-start: 34px; padding: 6px; border: 1px solid #c92c395c; border-radius: 50%; background: #0a0b0c99; box-shadow: 0 0 0 8px #0a0b0c60, 0 0 38px #c92c3926; transition: opacity .2s; } +.battle-crest img { width: 88px; height: 88px; border-radius: 50%; opacity: .85; } +.battle-art-bottom { position: absolute; bottom: 16px; inset-inline: 22px; display: flex; align-items: flex-end; gap: 20px; z-index: 2; } +.battle-record-number { font: 600 58px/.9 'Barlow Condensed', sans-serif; color: #e9dfe1; opacity: .9; } +.battle-engagements { display: flex; align-items: baseline; gap: 7px; padding-bottom: 2px; font-size: 9px; letter-spacing: 1px; text-transform: uppercase; color: #bfb4b6; } +.battle-engagements strong { font: 500 25px/1 'Barlow Condensed', sans-serif; color: var(--accent); } +.battle-art-seal { margin-inline-start: auto; padding-bottom: 3px; font: 9px/1.7 var(--body); letter-spacing: 2px; color: #a68b92; text-align: end; } +.battle-report-image { position: absolute; top: 54px; left: 18px; width: calc(100% - 36px); height: calc(100% - 120px); object-fit: contain; z-index: 1; } +.has-report-preview .battle-terrain { opacity: .22; } +.has-report-preview .battle-crest { opacity: 0; } +.battle-card-content { padding: 25px 26px 0; display: flex; flex-direction: column; flex: 1; } +.battle-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 15px; color: var(--muted); font-size: 10px; } +.battle-card-meta .outcome { font-size: 9px; } +.battle-card-content h3 { font: 500 33px/1.12 var(--display); margin: 18px 0 17px; letter-spacing: -.2px; overflow-wrap: anywhere; } +.battle-id-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 25px; } +.battle-id-list span { display: inline-block; font-size: 9px; letter-spacing: .5px; color: #b0a2a5; border: 1px solid #ffffff13; padding: 3px 7px; background: #ffffff03; } +.battle-card-stats { display: grid; grid-template-columns: 1fr 1fr; margin: 0 0 22px; border-block: 1px solid var(--line); } +.battle-card-stats > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; } +.battle-card-stats > div:first-child { padding-inline-end: 20px; border-inline-end: 1px solid var(--line); } +.battle-card-stats > div + div { padding-inline-start: 20px; } +.battle-card-stats dt { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; } +.battle-card-stats dd { margin: 0; font: 500 28px/1 'Barlow Condensed', sans-serif; color: var(--text); } +.battle-card-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding: 17px 0; margin-top: auto; } +.battle-source { font-size: 8px; letter-spacing: 2px; color: #a89b9e; } +.battle-source > span { color: var(--accent); margin-inline-start: 4px; } +.battle-open { display: flex; align-items: center; gap: 13px; font-size: 11px; color: var(--text); } +.battle-open-icon { width: 31px; height: 31px; display: grid; place-items: center; background: #c92c3917; border: 1px solid #c92c3938; transition: background .2s; } +.battle-open-icon .icon { width: 15px; height: 15px; color: var(--accent); } +.battle-card:hover .battle-open-icon { background: #c92c3930; } +.battle-ledger { margin-top: 26px; } +.battle-ledger > summary { display: flex; align-items: center; gap: 12px; padding: 17px 20px; border: 1px solid var(--line); cursor: pointer; font-size: 11px; color: var(--muted); list-style: none; } +.battle-ledger > summary::-webkit-details-marker { display: none; } +.battle-ledger > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; } +.battle-ledger > summary .icon { color: var(--accent); width: 18px; height: 18px; } +.ledger-toggle { margin-inline-start: auto; color: var(--accent); font-size: 23px; line-height: 1; transition: transform .2s; } +.battle-ledger[open] .ledger-toggle { transform: rotate(45deg); } +.battle-ledger[open] > summary { border-bottom: 0; } +[dir=rtl] .battle-archive-strip span, [dir=rtl] .battle-type, [dir=rtl] .battle-region, [dir=rtl] .battle-engagements { letter-spacing: 0; } +[dir=rtl] .battle-card-content h3 { font-size: 25px; line-height: 1.6; letter-spacing: -.6px; } +[dir=rtl] .battle-card-meta, [dir=rtl] .battle-open { font-size: 10px; } +[dir=rtl] .battle-open-icon .icon { transform: scaleX(-1); } +@media (max-width: 760px) { + .battle-archive-strip { gap: 24px; flex-wrap: wrap; margin-bottom: 24px; } + .battle-archive-strip > p { flex-basis: 100%; margin-inline-start: 0; font-size: 10px; } + .battle-archive-strip span { font-size: 9px; } + .battle-card-grid { grid-template-columns: 1fr; gap: 22px; } + .battle-art { height: 270px; } + .battle-card-content { padding: 23px 22px 0; } + .battle-card-content h3 { font-size: 31px; } + .battle-type { font-size: 8px; } + .battle-art-seal { font-size: 8px; } + .battle-crest { inset-inline-start: 26px; } +} +@media (max-width: 390px) { + .battle-art-top, .battle-art-bottom { inset-inline: 17px; } + .battle-art { height: 250px; } + .battle-art-seal { display: none; } + .battle-card-content { padding-inline: 18px; } + .battle-card-meta { font-size: 9px; } + [dir=rtl] .battle-card-content h3 { font-size: 22px; } +} +@media (prefers-reduced-motion: reduce) { + .battle-card, .battle-terrain, .battle-crest, .battle-open-icon, .ledger-toggle { transition: none; } + .battle-card:hover, .battle-card:focus-within { transform: none; } +} + +/* Preserve the complete AlbionBB scoreboard when a real report image loads. */ +.has-report-preview.battle-art { height: auto; min-height: 290px; padding-block: 54px 66px; } +.has-report-preview .battle-report-image { position: relative; inset: auto; width: 100%; height: auto; object-fit: contain; } diff --git a/test/battles.test.mjs b/test/battles.test.mjs new file mode 100644 index 0000000..6b6000f --- /dev/null +++ b/test/battles.test.mjs @@ -0,0 +1,92 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import { battleDetails, renderBattleCards } from '../scripts/render-battles.mjs'; +import { directPreview, discoverPreview } from '../scripts/battle-previews.mjs'; + +const translations=JSON.parse(await readFile(new URL('../content/translations.json',import.meta.url),'utf8')); +const single={title:{en:'A single fight',fa:'یک نبرد'},url:'https://europe.albionbb.com/battles/448776222'}; +const combined={title:{en:'A campaign',fa:'مجموعه نبردها'},url:'https://europe.albionbb.com/battles/multi?ids=448776222,441001581,440997498'}; +const render=(battles,lang='en',previews={})=>renderBattleCards({battles,lang,previews,base:lang==='fa'?'../':'./',t:translations[lang],icon:()=>''}); + +test('reports use direct images without a cache and keep artwork for unavailable previews',()=>{ + for(const lang of ['en','fa']){ + const html=render([single,combined],lang); + assert.equal((html.match(/class="battle-art"/g)||[]).length,2); + assert.equal((html.match(/class="battle-terrain"/g)||[]).length,2); + assert.match(html,/battle-card--single/); + assert.match(html,/battle-card--campaign/); + assert.ok(html.includes(single.title[lang])); + assert.ok(html.includes(combined.title[lang])); + assert.match(html,/#441001581/); + assert.equal((html.match(/class="battle-report-image"/g)||[]).length,2); + assert.match(html,/src="https:\/\/api.albionbb.com\/eu\/preview\/448776222"/); + assert.match(html,/src="https:\/\/api.albionbb.com\/eu\/preview\/multi\?ids=448776222,441001581,440997498"/); + assert.ok(!html.includes('battle-card-stats')); + assert.ok(!html.includes('{ + assert.equal(directPreview(single.url),'https://api.albionbb.com/eu/preview/448776222'); + assert.equal(directPreview(single.url+'/'),'https://api.albionbb.com/eu/preview/448776222'); + assert.equal(directPreview(combined.url),'https://api.albionbb.com/eu/preview/multi?ids=448776222,441001581,440997498'); + assert.equal(directPreview('https://europe.albionbb.com/battles/multi?ids=441002770%2C441001581%2C440997498'),'https://api.albionbb.com/eu/preview/multi?ids=441002770,441001581,440997498'); + assert.equal(directPreview('https://europe.albionbb.com/battles/multi/?ids=441002770,441001581'),'https://api.albionbb.com/eu/preview/multi?ids=441002770,441001581'); + assert.equal(directPreview('https://europe.albionbb.com/battles/multi'),null); + assert.equal(directPreview('https://europe.albionbb.com/battles/multi?ids=441002770,invalid'),null); + assert.equal(directPreview('https://albionbb.com/battles/448776222'),null); + assert.equal(directPreview('https://europe.albionbb.com.evil.test/battles/448776222'),null); + assert.equal(directPreview('invalid'),null); +}); + +test('automatic discovery prefers report metadata over a derived endpoint',async()=>{ + const image='https://api.albionbb.com/eu/preview/new-format'; + const fetchPage=async url=>{ + assert.equal(url,single.url); + return new Response(``); + }; + assert.equal(await discoverPreview(single,fetchPage),image); +}); + +test('combined reports discover their own preview and overrides skip metadata fetching',async()=>{ + const fetchPage=async()=>new Response(''); + assert.equal(await discoverPreview(combined,fetchPage),'https://europe.albionbb.com/combined-preview.png'); + assert.equal(await discoverPreview({...single,preview:'https://example.com/override.png'},()=>{throw Error('Should not fetch metadata');}),'https://example.com/override.png'); +}); + +test('discovery falls back to single and combined endpoints when report metadata is unavailable',async()=>{ + const offline=async()=>{throw Error('Offline');}; + assert.equal(await discoverPreview(single,offline),'https://api.albionbb.com/eu/preview/448776222'); + assert.equal(await discoverPreview(single,async()=>new Response('No image metadata')),'https://api.albionbb.com/eu/preview/448776222'); + assert.equal(await discoverPreview(combined,offline),'https://api.albionbb.com/eu/preview/multi?ids=448776222,441001581,440997498'); + assert.equal(await discoverPreview(combined,async()=>new Response('No metadata')),'https://api.albionbb.com/eu/preview/multi?ids=448776222,441001581,440997498'); + await assert.rejects(discoverPreview({url:'https://albionbb.com/battles/multi?ids=1,2'},offline),/Offline/); +}); + +test('combined reports deduplicate battle IDs when counting recorded engagements',()=>{ + assert.deepEqual(battleDetails(combined.url).ids,['448776222','441001581','440997498']); + const html=render([single,combined]); + assert.match(html,/2<\/strong>Archived reports/); + assert.match(html,/3<\/strong>Recorded engagements/); +}); + +test('previews retain underlying artwork and verified zero values remain visible',()=>{ + const battle={...single,preview:'https://example.com/preview.png',kills:0,deaths:7,date:'2026-10-18'}; + const html=render([battle],'fa',{[battle.url]:'assets/battles/cached.png'}); + assert.match(html,/src="\.\.\/assets\/battles\/cached.png"/); + assert.match(html,/data-battle-preview/); + assert.match(html,/class="battle-terrain"/); + assert.match(html,/
۰<\/dd>/); + assert.match(html,/
۷<\/dd>/); + assert.match(html,/datetime="2026-10-18"/); + assert.match(render([battle]),/https:\/\/example.com\/preview.png/); +}); + +test('empty archives stay empty and report titles are escaped',()=>{ + assert.equal(render([]),''); + const html=render([{...single,title:''}]); + assert.ok(!html.includes('