master @ 73 LINES
[ HISTORY ] [ UP ]
┌─ ASTRO ────────────────────────────────────────────────────────────────────┐
│ --- │
│ import type { Enchantment } from "../../lib/types"; │
│ │
│ // builds the `<a data-wowhead="...">` for an item. tooltip rendering itself │
│ // is done by Wowhead's tooltips.js loaded in PageLayout │
│ │
│ interface Props { │
│ itemId: number | undefined | null; │
│ // pass 463 to scale tooltip stats to Challenge Mode ilvl │
│ ilvl?: number; │
│ // permanent enchant becomes `ench=N`; gems (slot_id 2-5 with no │
│ // slot_type) become `gems=A:B:C` │
│ enchants?: Enchantment[]; │
│ domain?: string; │
│ class?: string; │
│ // default _blank so in-page tooltip stays the primary surface │
│ target?: string; │
│ href?: string; │
│ ariaLabel?: string; │
│ } │
│ │
│ const { │
│ itemId, │
│ ilvl, │
│ enchants = [], │
│ domain = "mop-classic", │
│ class: extraClass, │
│ target = "_blank", │
│ href, │
│ ariaLabel, │
│ } = Astro.props; │
│ │
│ const params: string[] = []; │
│ if (itemId) { │
│ params.push(`item=${itemId}`); │
│ params.push(`domain=${domain}`); │
│ if (ilvl) params.push(`ilvl=${ilvl}`); │
│ │
│ const permanent = enchants.find((e) => e.slot_type === "PERMANENT"); │
│ if (permanent?.enchantment_id) { │
│ params.push(`ench=${permanent.enchantment_id}`); │
│ } │
│ │
│ // Blizzard tags gem rows with slot_id 2..5 and no slot_type; │
│ // Wowhead wants colon-separated gem item ids │
│ const gems = enchants │
│ .filter((e) => !e.slot_type && e.slot_id >= 2 && e.slot_id <= 5) │
│ .map((g) => g.source_item_id) │
│ .filter((id): id is number => typeof id === "number" && id > 0); │
│ if (gems.length > 0) { │
│ params.push(`gems=${gems.join(":")}`); │
│ } │
│ } │
│ const wowheadAttr = params.length > 0 ? params.join("&") : undefined; │
│ │
│ const resolvedHref = │
│ href ?? │
│ (itemId │
│ ? `https://www.wowhead.com/${domain}/item=${itemId}${ilvl ? `?ilvl=${ilvl}` : │
│ ""}` │
│ : undefined); │
│ --- │
│ │
│ <a │
│ href={resolvedHref} │
│ data-wowhead={wowheadAttr} │
│ class:list={["item-tooltip", extraClass]} │
│ rel="noopener noreferrer" │
│ target={target} │
│ aria-label={ariaLabel} │
│ > │
│ <slot /> │
│ </a> │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ASTRO ──────────────────────────────┐
│ --- │
│ import type { Enchantment } from "../../lib/ │
│ types"; │
│ │
│ // builds the `<a data-wowhead="...">` for a │
│ n item. tooltip rendering itself │
│ // is done by Wowhead's tooltips.js loaded i │
│ n PageLayout │
│ │
│ interface Props { │
│ itemId: number | undefined | null; │
│ // pass 463 to scale tooltip stats to Chal │
│ lenge Mode ilvl │
│ ilvl?: number; │
│ // permanent enchant becomes `ench=N`; gem │
│ s (slot_id 2-5 with no │
│ // slot_type) become `gems=A:B:C` │
│ enchants?: Enchantment[]; │
│ domain?: string; │
│ class?: string; │
│ // default _blank so in-page tooltip stays │
│ the primary surface │
│ target?: string; │
│ href?: string; │
│ ariaLabel?: string; │
│ } │
│ │
│ const { │
│ itemId, │
│ ilvl, │
│ enchants = [], │
│ domain = "mop-classic", │
│ class: extraClass, │
│ target = "_blank", │
│ href, │
│ ariaLabel, │
│ } = Astro.props; │
│ │
│ const params: string[] = []; │
│ if (itemId) { │
│ params.push(`item=${itemId}`); │
│ params.push(`domain=${domain}`); │
│ if (ilvl) params.push(`ilvl=${ilvl}`); │
│ │
│ const permanent = enchants.find((e) => e.s │
│ lot_type === "PERMANENT"); │
│ if (permanent?.enchantment_id) { │
│ params.push(`ench=${permanent.enchantmen │
│ t_id}`); │
│ } │
│ │
│ // Blizzard tags gem rows with slot_id 2.. │
│ 5 and no slot_type; │
│ // Wowhead wants colon-separated gem item │
│ ids │
│ const gems = enchants │
│ .filter((e) => !e.slot_type && e.slot_id │
│ >= 2 && e.slot_id <= 5) │
│ .map((g) => g.source_item_id) │
│ .filter((id): id is number => typeof id │
│ === "number" && id > 0); │
│ if (gems.length > 0) { │
│ params.push(`gems=${gems.join(":")}`); │
│ } │
│ } │
│ const wowheadAttr = params.length > 0 ? para │
│ ms.join("&") : undefined; │
│ │
│ const resolvedHref = │
│ href ?? │
│ (itemId │
│ ? `https://www.wowhead.com/${domain}/ite │
│ m=${itemId}${ilvl ? `?ilvl=${ilvl}` : ""}` │
│ : undefined); │
│ --- │
│ │
│ <a │
│ href={resolvedHref} │
│ data-wowhead={wowheadAttr} │
│ class:list={["item-tooltip", extraClass]} │
│ rel="noopener noreferrer" │
│ target={target} │
│ aria-label={ariaLabel} │
│ > │
│ <slot /> │
│ </a> │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET