awwwards-mcp 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Afjal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,362 @@
1
+ # awwwards-mcp
2
+
3
+ Free, open-source MCP server that gives AI agents design inspiration from
4
+ [Awwwards](https://www.awwwards.com/) — the Mobbin-style visual reference loop,
5
+ sourced from the web's best award-winning websites.
6
+
7
+ <a href="https://github.com/INSANE0777/Awwwards-mcp"><img src="assets/demo.gif" alt="awwwards-mcp in action: search results, design DNA, motion filmstrip, band map — real tool output" width="480"></a>
8
+
9
+ Your agent searches in natural language ("dark 3D portfolio sites", "soft pastel
10
+ e-commerce"), sees **real screenshots inline**, and can pull the **design DNA**
11
+ of any site: color palette, tech stack, design elements, award history.
12
+ Free-text queries run on a porter-stemmed, prefix-matching FTS5 index with BM25
13
+ ranking — "magazines" now finds Magazine-tagged sites (68 on the live index),
14
+ best matches first, where the old substring path returned zero. Multi-word
15
+ queries keep AND semantics: every token must hit the same site.
16
+
17
+ ## Tools
18
+
19
+ | Tool | What it does |
20
+ |------|--------------|
21
+ | `search_sites` | Search by color, tags, technology, award type or free-text query. Multi-word queries match against the local FTS5 index and rank BM25 (title hits lead); zero results come with loose-match and taxonomy-tag hints. Returns site cards with inline screenshots. |
22
+ | `get_site_details` | Full design DNA for one site: palette, technologies, elements, awards, description. |
23
+ | `get_site_elements` | Component-level visuals for one site: each element's poster image inline (3D models, video content, mobile layouts, microcopy…) + video URLs. |
24
+ | `list_categories` | Every filter the agent can search by (200+ tags, 27 colors). |
25
+ | `capture_live_site` | Optional: fresh full-page screenshot of any live URL. Waits for `load` + a settle window with a bounded pre-scroll, so heavy sites work (`waitStrategy: "networkidle"` available). Pass `viewport: "mobile"` for the 390×844 iPhone-class render (`"desktop"` 1440×900 default). (needs [playwright](https://playwright.dev)). |
26
+ | `analyze_page_structure` | Section band map of any page (live URL or local file:// build): tag, background, offset, height per band. Compare a reference site's structure against your build. Same heavy-site-friendly wait (`waitStrategy: "networkidle"` available); `viewport: "mobile"` analyzes the phone-class layout (`"desktop"` default). (needs [playwright](https://playwright.dev)). |
27
+ | `record_site_motion` | Optional: short motion-through video of a live URL — preloader, scroll-triggered and hover/cursor animations. Returns an inline filmstrip JPEG plus the saved .webm path. `viewport: "mobile"` records at phone size — the filmstrip renders at the selected viewport, no pillarboxing (`"desktop"` default). (needs [playwright](https://playwright.dev) + ffmpeg-static). |
28
+
29
+ ## Setup
30
+
31
+ **v1.0.0-beta.1** — the first beta. Any MCP-compatible coding agent can use awwwards-mcp — no API key, no account.
32
+ Requires Node ≥ 22.13 (`node -v` to check). Pick your agent:
33
+
34
+ **Updates**: the server checks the npm registry once a day and prints an
35
+ stderr notice when a newer `awwwards-mcp` exists (stdout stays clean for the
36
+ JSON-RPC channel — your agent sees the notice as a log line). Set
37
+ `AWWWARDS_AUTO_UPDATE=1` in the server's `env` to opt into background
38
+ self-update; restart your agent afterwards to load it. Nothing is fetched
39
+ more than once a day and serving never waits on the check.
40
+
41
+ **Claude Code**
42
+
43
+ ```bash
44
+ claude mcp add awwwards -- npx -y awwwards-mcp
45
+ ```
46
+
47
+ **Codex CLI** (ChatGPT desktop app and the IDE extension share this config)
48
+
49
+ ```bash
50
+ codex mcp add awwwards -- npx -y awwwards-mcp
51
+ ```
52
+
53
+ or in `~/.codex/config.toml` (project-scoped: `.codex/config.toml`):
54
+
55
+ ```toml
56
+ [mcp_servers.awwwards]
57
+ command = "npx"
58
+ args = ["-y", "awwwards-mcp"]
59
+ ```
60
+
61
+ **OpenCode** (`opencode.json` — note the command is an array)
62
+
63
+ ```json
64
+ {
65
+ "$schema": "https://opencode.ai/config.json",
66
+ "mcp": {
67
+ "awwwards": {
68
+ "type": "local",
69
+ "command": ["npx", "-y", "awwwards-mcp"]
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ **ZCode** (`~/.zcode/cli/config.json` — note servers nest under `"mcp": { "servers": ... }`)
76
+
77
+ ```json
78
+ {
79
+ "mcp": {
80
+ "servers": {
81
+ "awwwards": { "command": "npx", "args": ["-y", "awwwards-mcp"], "env": {} }
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ **Claude Desktop / Cursor / Windsurf / Gemini CLI / Cline / Continue** — anything
88
+ reading the common `mcpServers` JSON shape (e.g. `~/.claude/claude_desktop_config.json`
89
+ or `~/.gemini/settings.json`):
90
+
91
+ ```json
92
+ {
93
+ "mcpServers": {
94
+ "awwwards": { "command": "npx", "args": ["-y", "awwwards-mcp"] }
95
+ }
96
+ }
97
+ ```
98
+
99
+ **Anything else** — awwwards-mcp is a plain stdio MCP server: point your client
100
+ at `npx -y awwwards-mcp` and it works. To pin a version, use
101
+ `npx -y awwwards-mcp@1.0.0`.
102
+
103
+ **pi coding agent** has no built-in MCP by design — it uses skills and
104
+ extensions instead. Two options:
105
+
106
+ 1. Install the awwwards-inspiration skill (below). pi reads skills from
107
+ `~/.pi/agent/skills/` or `~/.agents/skills/` (the latter is shared across
108
+ agents following the Agent Skills standard). The skill teaches the workflow;
109
+ for it to reach the live data, add an MCP-supporting pi extension, or run
110
+ the queries in another agent and paste results.
111
+ 2. Skip MCP entirely: ask pi to build you a small CLI wrapper around
112
+ awwwards.com, or use a shared skills directory (`~/.agents/skills/`) so the
113
+ same skill file serves pi and every other agent.
114
+
115
+ Optional full-page captures (needed by `capture_live_site`,
116
+ `analyze_page_structure`, `record_site_motion`):
117
+
118
+ ```bash
119
+ npm install -g playwright && npx playwright install chromium
120
+ ```
121
+
122
+ `record_site_motion` additionally uses ffmpeg; it resolves the `ffmpeg-static`
123
+ package automatically if present.
124
+
125
+ ## Skills
126
+
127
+ This package ships three agent skills. Any agent that follows the
128
+ [Agent Skills standard](https://agentskills.io) can load them; copy them into
129
+ your agent's skills directory:
130
+
131
+ ```bash
132
+ npm install awwwards-mcp
133
+ mkdir -p ~/.agents/skills && cp -r node_modules/awwwards-mcp/skills/awwwards-inspiration node_modules/awwwards-mcp/skills/awwwards-doctor node_modules/awwwards-mcp/skills/awwwards-motion-study ~/.agents/skills/
134
+ ```
135
+
136
+ | Skill | What it teaches |
137
+ |-------|-----------------|
138
+ | `awwwards-inspiration` | The inspiration loop: search, judge from screenshots, pull design DNA, state a design direction, capture/motion-first builds. |
139
+ | `awwwards-motion-study` | The full video chain: what to record from a live site (and what to skip), frame-by-frame review (video input or tile-per-element), the motion inventory, and build verification by re-recording. |
140
+ | `awwwards-doctor` | Repair: run `npm run doctor`, apply its fixes, re-anchor parsers after real awwwards.com drift, recover the in-flight task that surfaced the failure. |
141
+
142
+ | Agent | Skills directory |
143
+ |-------|------------------|
144
+ | Claude Code | `~/.claude/skills/` |
145
+ | pi | `~/.pi/agent/skills/` (also reads `~/.agents/skills/`) |
146
+ | ZCode | `~/.zcode/skills/` |
147
+ | Agent Skills-standard agents | `~/.agents/skills/` |
148
+
149
+ Windows: run this from Git Bash, or copy
150
+ `node_modules\awwwards-mcp\skills\awwwards-inspiration` manually.
151
+
152
+ ## Indexing (recommended)
153
+
154
+ `search_sites` works out of the box, but its depth is limited by polite live
155
+ scraping (~31 sites per filter page). Build a local index once and searches
156
+ draw from thousands of award-winning sites instantly:
157
+
158
+ ```bash
159
+ npx -y -p awwwards-mcp awwwards-index # once published
160
+ # or, from a local checkout of this repo:
161
+ npm run index
162
+ ```
163
+
164
+ - Crawls all ~200 tag pages at 1 request/second (~4 minutes) into the local
165
+ SQLite cache at `~/.awwwards-mcp/`.
166
+ - Resumable: interrupt it and re-run — completed pages are skipped.
167
+ - The MCP server re-indexes automatically in the background whenever the
168
+ index is older than 7 days (never blocking your session).
169
+
170
+ Site details (palettes, tech stacks) are still fetched on demand and cached
171
+ for 7 days.
172
+
173
+ ## How it works
174
+
175
+ - Live, polite scraping of awwwards.com public pages (max 1 request/second,
176
+ robots.txt-compliant paths only, cached 7 days in SQLite at `~/.awwwards-mcp/`).
177
+ - Screenshots are served from Awwwards' own CDN (880×660), cached on disk.
178
+ - No API key, no account, no cost.
179
+
180
+ ## Ethics & terms
181
+
182
+ This tool fetches publicly available pages for **personal design-inspiration
183
+ use**, at human-ish request rates, honoring robots.txt. Awwwards' screenshots
184
+ and content remain the property of Awwwards and the credited creators — don't
185
+ bulk-scrape, redistribute, or republish them. If you use this commercially,
186
+ review awwwards.com's terms yourself.
187
+
188
+ ## Built with awwwards-mcp: four real sites
189
+
190
+ Four complete sites were built through the full inspiration loop this MCP
191
+ enables, using nothing but the server's tools plus the shipped
192
+ `awwwards-inspiration` skill. Each one exercised a different corner of the
193
+ loop — and every correction the loop caught on the way became doctrine in the
194
+ skill.
195
+
196
+ > **Built in one shot, by a model that can't watch video.** All three sites
197
+ > were built in a single prompt run on **GLM 5.3-flash** — which does not
198
+ > support video input. The loop's motion study worked entirely from
199
+ > frame-tiled filmstrips (ffmpeg, 1–2 fps per element) instead of watching
200
+ > the recordings. With a video-native model, those same `get_site_elements`
201
+ > videos and `record_site_motion` .webm files could be watched directly —
202
+ > timing, easing and overlap read at full fidelity — and the motion-true
203
+ > results would be better still. The skill's frame-tile doctrine is what
204
+ > closes that gap today.
205
+
206
+ **1. [Ridge](showcase/ridge/index.html)**
207
+ ([source](showcase/ridge/)) — a Swiss-minimal single-page showcase for a fictional engineering-talent studio, direction **Aspen Search** (SOTD + Developer Award, jury 7.48): monochrome `#FAFAF8`/`#1A1A1A` + mint, giant grotesque section markers, halftone grain, asymmetric panel grid, dark discipline panels in an interior **horizontal pin passage**, count-up stats, client rows, theme toggle, cursor-follower. Built with the v1.4.0 toolkit: FTS5-ranked direction search, **both-viewports** reference captures and QA (desktop 7,849px + mobile 390×844), overflow audit (0px both), pin-center shots, film verification — and the skill-memory flywheel recorded the findings. QA evidence: `showcase/ridge/_qa/`.
208
+
209
+ | Panel grid (desktop) | Horizontal discipline passage | Mobile 390×844 |
210
+ |---|---|---|
211
+ | ![Ridge desktop — Swiss panel grid with mint and grain](assets/ridge-home.jpg) | ![Ridge disciplines — pinned horizontal passage mid-slide](assets/ridge-disciplines.jpg) | ![Ridge mobile — stacked grid, zero overflow](assets/ridge-mobile.jpg) |
212
+
213
+ **2. [Fallow Press](fallow-press/index.html)**
214
+ ([source](fallow-press/)) — a flat-2D editorial journal, direction
215
+ **Emergence Magazine** (SOTD): pink `#FF9398` on cream and black, torn-paper
216
+ masthead (pure CSS `clip-path`, zero WebGL), giant grotesque display over
217
+ grayscale photography, serif-italic brand, three pages with **separate
218
+ horizontal** projects/about pages (GSAP ScrollTrigger pin +
219
+ `containerAnimation`).
220
+
221
+ | Torn-paper masthead (home) | Horizontal gallery (Fields) | Horizontal chapters (Practices) |
222
+ |---|---|---|
223
+ | ![Fallow Press home — torn-paper masthead over grayscale photography](assets/fallow-home.jpg) | ![Fallow Press Fields — pinned horizontal gallery panel](assets/fallow-fields.jpg) | ![Fallow Press Practices — pink quote chapter](assets/fallow-practices.jpg) |
224
+
225
+ The loop as it ran:
226
+
227
+ 1. `search_sites` (magazine filters) → shortlist judged from inline
228
+ screenshots → `get_site_details` on Emergence Magazine.
229
+ 2. **Capture before building**: `capture_live_site` + `record_site_motion`
230
+ on the live site *first*; full-page PNG and motion .webm kept in
231
+ [fallow-press/ref-motion/](fallow-press/ref-motion/) as the evidence trail.
232
+ 3. Build, then verify: full-page capture plus **panel-center pin shots** of
233
+ both horizontal pages (13 stops each, in
234
+ [fallow-press/_qa/](fallow-press/_qa/) — `capture-qa.mjs` is reusable).
235
+ 4. The pin shots caught a real bug: horizontal-panel entrances used
236
+ `toggleActions: "play none none reverse"`, and 100vw panels hide content
237
+ at midpoints on the way back — copy disappeared mid-view. Fix
238
+ (one-shot play entrances) is now doctrine: **full-viewport panels get
239
+ one-shot entrances**; QA pin shots land at panel **centers**, not uniform
240
+ fractions, or you photograph empty transition zones.
241
+
242
+ **3. Cerebrium recreation** (`C:/Users/Afjal/cerebrium-recreation/`) — a
243
+ fidelity-first recreation of cerebrium.ai, pixel-checked against the live
244
+ reference: full-page captures of both sides, `analyze_page_structure` band
245
+ compare, and SVG icon/legend fixes until the build matched the reference to
246
+ within 1px of total page height (10,871px vs 10,870px). This is the
247
+ **structure-before-pixels** doctrine at its strictest — band maps compared,
248
+ never just totals.
249
+
250
+ ![Cerebrium recreation — full-page build capture](assets/cerebrium-build.jpg)
251
+
252
+ **4. The Meridian** (`C:/Users/Afjal/editorial-site/`) — an editorial journal
253
+ built from ORDR/Hearst references: the first build to run the whole loop
254
+ end-to-end. `analyze_page_structure` caught a masthead band bug by comparing
255
+ the build's band map against the reference's; the reference captures,
256
+ motion film, and the reusable pre-scroll capture script live in
257
+ `editorial-site/_qa/`.
258
+
259
+ ![The Meridian editorial journal — full-page build capture](assets/meridian-build.jpg)
260
+
261
+ ![The Meridian — motion filmstrip from record_site_motion](assets/meridian-filmstrip.jpg)
262
+
263
+ ## Skills used to build these
264
+
265
+ | Skill | Role in the builds |
266
+ |---|---|
267
+ | `awwwards-inspiration` | The 8-step loop itself (ships with this package): search → judge from screenshots → design DNA → capture/motion study → state direction → build → band-map verify. |
268
+ | `gsap-scrolltrigger` | The horizontal pin + `containerAnimation` pattern (ease `"none"`, one-shot entrances) driving both Fallow Press horizontal pages. |
269
+ | `gsap-core` / `gsap-timeline` | Tween composition and sequenced hero entrances (torn-paper drop, panel copy rises). |
270
+ | `frontend-design` | Typography, palette and layout judgment applied when translating reference DNA into original pages. |
271
+ | `lenis` (library, via skill guidance) | smooth scrolling synced to ScrollTrigger on the Fallow Press home page. |
272
+ | `tailwindcss` / plain CSS | All builds are plain hand-rolled CSS — flat 2D, no frameworks needed. |
273
+
274
+ **The skills self-improve:** every loop pass records what verification caught (`scripts/skill-memory.mjs record`), and a deterministic distiller folds rules seen 2+ times into your installed skill copy — while the shipped copies only change via human PR. A techniques registry (`skills/_memory/techniques.json`) catalogs researched how-tos per domain (video understanding, motion detection, UI structure, micro-interactions, images).
275
+
276
+ Reduced-motion, JS-less visits, and capture tools all get graceful fallbacks
277
+ (vertical stacks; progressive-enhancement reveals).
278
+
279
+ **What the verification loop caught** — proof the structure-before-pixels
280
+ doctrine is load-bearing:
281
+
282
+ - Element **posters lie**: the first showcase build was designed from poster
283
+ frames alone and rendered a spinning 3D ring as *floating static cards*.
284
+ Downloading the element videos (`get_site_elements`) and frame-tiling them
285
+ revealed the motion truth — now the skill mandates studying motion before
286
+ animating.
287
+ - Full-page captures of reveal-on-scroll builds showed blank sections: `.reveal`
288
+ animation state vs capture's no-scroll reality. Builds ship
289
+ content-visible-without-JS progressive enhancement.
290
+ - Horizontal-panel copy vanished **mid-view** on the Fallow Press pages:
291
+ `toggleActions` reverse reverts entrances while a 100vw panel is still
292
+ holding the viewport (see above).
293
+ - Band-map compare kept the references' rhythm instead of drifting on
294
+ section heights (Cerebrium, The Meridian).
295
+
296
+ Prompt counts: **3** for the original showcase build (the build ask, the
297
+ motion correction that exposed the poster-lie, the structure pass) and
298
+ **1** for Fallow Press ("create a new website using our MCP and skills… no
299
+ 3D websites") — its two follow-ups were caught by the QA loop, not by the
300
+ user. Each correction became doctrine in the shipped `awwwards-inspiration`
301
+ skill: frame-study element videos before animating; judge page architecture
302
+ from the studied passages; tile per element, not one giant filmstrip;
303
+ capture live sites and animation **before** building.
304
+
305
+ ## Can awwwards-mcp crawl the sitemap? (robots.txt notes)
306
+
307
+ The awwwards.com `robots.txt` advertises
308
+ `Sitemap: https://www.awwwards.com/sitemap.xml` and — verified live
309
+ 2026-09-18 — **that sitemap URL returns a soft-404 HTML page** (as do common
310
+ child names like `/sitemap-websites.xml`). So sitemap discovery isn't
311
+ currently a path to more data; the polite crawl surface is exactly what the
312
+ indexer uses:
313
+
314
+ - **Allowed and used**: `/websites/`, `/websites/<filter>/`, `/sites/<slug>`
315
+ (one filter per URL; deep pagination stays un-crawled).
316
+ - **Disallowed and never fetched**: `/tag/`, `/search-websites`,
317
+ `/websites/?` (query-string pagination), `/elements/*`, `/vote/`,
318
+ favourites/likes/follows, and the rest of the 33 rules.
319
+ - Our client (`src/awwwards.ts` `buildFilterUrl`) constructs **only**
320
+ `/websites/…` paths at 1 request/second — the loop stays inside the
321
+ published rules by construction, not by convention.
322
+
323
+ ## Contributing
324
+
325
+ PRs welcome! The project especially needs **parser-drift fixes** — when live
326
+ awwwards.com markup changes, a fresh HTML snapshot attached to an issue often
327
+ becomes the new test fixture and the fastest merged PR. See
328
+ [CONTRIBUTING.md](CONTRIBUTING.md) for the full guide:
329
+
330
+ **Parser-drift is monitored automatically.** A probe script
331
+ ([scripts/parser-drift-probe.mjs](scripts/parser-drift-probe.mjs),
332
+ `npm run drift`) checks every markup anchor the parsers depend on — the
333
+ `split`/`indexOf`/regex literals in `src/parsers.ts` — against the live
334
+ listing and detail pages (2 fetches, 1 request/second, same politeness as
335
+ the client). A daily GitHub Action ([.github/workflows/parser-drift.yml](.github/workflows/parser-drift.yml))
336
+ runs it and, on drift, opens/updates a single tracking issue with the exact
337
+ anchors that changed (and auto-closes it when a later run is green). To run
338
+ it yourself: `npm run drift` (live, exit code 0/1/2) or `npm run drift -- --fixture`
339
+ (offline, checks the committed fixtures still feed every anchor). Raw HTML
340
+ is never diffed or stored — anchors only fire when the parsers actually
341
+ break, so there are no false alarms from cosmetic tweaks.
342
+
343
+ - Development setup & project layout (offline fixture-tested, no network in tests)
344
+ - How to create a PR: fork → `fix/`/`feat/`/`docs/` branch → typecheck + tests → PR template
345
+ - The politeness constraints new code must keep (1 req/s, robots.txt paths, light runtime deps)
346
+
347
+ Bugs and feature ideas start as
348
+ [issues](https://github.com/INSANE0777/Awwwards-mcp/issues/new/choose) with
349
+ templates. Security problems go privately — see
350
+ [SECURITY.md](SECURITY.md). By participating you agree to the
351
+ [Code of Conduct](CODE_OF_CONDUCT.md).
352
+
353
+ ## Development
354
+
355
+ ```bash
356
+ npm install
357
+ npm test # offline unit tests against committed HTML fixtures
358
+ npm run smoke # manual live smoke test against awwwards.com
359
+ npm run build # compile to dist/
360
+ ```
361
+
362
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,113 @@
1
+ export const BASE_URL = "https://www.awwwards.com";
2
+ export const ASSETS_URL = "https://assets.awwwards.com";
3
+ export const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36 awwwards-mcp/1.0";
4
+ export const AWARD_FILTERS = {
5
+ sotd: "websites/sites_of_the_day",
6
+ developer: "websites/developer",
7
+ honorable: "websites/honorable",
8
+ };
9
+ // Combined filter URLs return 404 on awwwards.com (verified 2026-09-17), so
10
+ // exactly one filter is used in the URL — the most specific one. The caller
11
+ // applies the remaining filters client-side over the parsed results.
12
+ export function buildFilterUrl(filters) {
13
+ if (filters.color) {
14
+ return `${BASE_URL}/websites/%23${filters.color.replace("#", "").toUpperCase()}/`;
15
+ }
16
+ if (filters.award)
17
+ return `${BASE_URL}/${AWARD_FILTERS[filters.award]}/`;
18
+ const tag = filters.technology ?? filters.tags?.[0];
19
+ if (tag)
20
+ return `${BASE_URL}/websites/${encodeURIComponent(tag.toLowerCase())}/`;
21
+ return `${BASE_URL}/websites/`;
22
+ }
23
+ export function thumbnailUrl(thumbPath, size = 880) {
24
+ const dim = size === 880 ? "880_660" : "440_330";
25
+ return `${ASSETS_URL}/awards/media/cache/thumb_${dim}/${thumbPath}`;
26
+ }
27
+ export function elementUrl(mediaPath) {
28
+ return `${ASSETS_URL}/awards/${mediaPath}`;
29
+ }
30
+ // Video elements ship a poster at the same path with .mp4 → _static.jpeg
31
+ // (live-verified on the CDN); image elements are used as-is.
32
+ export function elementPosterPath(mediaPath) {
33
+ return mediaPath.endsWith(".mp4")
34
+ ? mediaPath.replace(/\.mp4$/, "_static.jpeg")
35
+ : mediaPath;
36
+ }
37
+ export class BlockedError extends Error {
38
+ status;
39
+ constructor(url, status) {
40
+ super(`Awwwards is blocking requests (HTTP ${status} on ${url}). ` +
41
+ "Try again later; the tool never retries through blocks.");
42
+ this.status = status;
43
+ }
44
+ }
45
+ export class RateLimiter {
46
+ intervalMs;
47
+ last = 0;
48
+ chain = Promise.resolve();
49
+ constructor(intervalMs) {
50
+ this.intervalMs = intervalMs;
51
+ }
52
+ acquire() {
53
+ const next = this.chain.then(async () => {
54
+ const wait = this.last + this.intervalMs - Date.now();
55
+ if (wait > 0)
56
+ await new Promise((r) => setTimeout(r, wait));
57
+ this.last = Date.now();
58
+ });
59
+ this.chain = next.catch(() => { });
60
+ return next;
61
+ }
62
+ }
63
+ export class AwwwardsClient {
64
+ rateLimiter;
65
+ fetchFn;
66
+ constructor(opts = {}) {
67
+ this.rateLimiter = opts.rateLimiter ?? new RateLimiter(1000);
68
+ this.fetchFn = opts.fetchFn ?? fetch;
69
+ }
70
+ // Rate-limited page fetch with one retry on transient failures.
71
+ // Blocks (403/429) are never retried.
72
+ async getHtml(path) {
73
+ const url = path.startsWith("http") ? path : BASE_URL + path;
74
+ let lastErr;
75
+ for (let attempt = 0; attempt < 2; attempt++) {
76
+ try {
77
+ await this.rateLimiter.acquire();
78
+ const res = await this.fetchFn(url, {
79
+ headers: { "User-Agent": USER_AGENT },
80
+ redirect: "follow",
81
+ });
82
+ if (res.status === 403 || res.status === 429)
83
+ throw new BlockedError(url, res.status);
84
+ if (!res.ok)
85
+ throw new Error(`HTTP ${res.status} for ${url}`);
86
+ return await res.text();
87
+ }
88
+ catch (err) {
89
+ if (err instanceof BlockedError)
90
+ throw err;
91
+ lastErr = err;
92
+ }
93
+ }
94
+ throw lastErr;
95
+ }
96
+ // Thumbnail fetch from the CDN — not rate-limited.
97
+ async getThumbnail(thumbPath, size = 880) {
98
+ return this.fetchCdnBinary(thumbnailUrl(thumbPath, size), `thumbnail ${thumbPath}`);
99
+ }
100
+ // Asset fetch from the CDN (element posters etc.) — not rate-limited.
101
+ async getAsset(assetPath) {
102
+ return this.fetchCdnBinary(elementUrl(assetPath), `asset ${assetPath}`);
103
+ }
104
+ // Binary CDN assets (thumbnails, element media) all fetch through this single path.
105
+ async fetchCdnBinary(url, label) {
106
+ const res = await this.fetchFn(url, {
107
+ headers: { "User-Agent": USER_AGENT },
108
+ });
109
+ if (!res.ok)
110
+ throw new Error(`HTTP ${res.status} fetching ${label}`);
111
+ return Buffer.from(await res.arrayBuffer());
112
+ }
113
+ }