diff --git a/package.json b/package.json index 80ea74a..1c5f132 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@firq/fgosite", "type": "module", - "version": "0.1.22", + "version": "0.1.23", "private": true, "scripts": { "dev": "astro dev", diff --git a/src/components/ceCard.astro b/src/components/ceCard.astro index 94ad0a2..51786f0 100644 --- a/src/components/ceCard.astro +++ b/src/components/ceCard.astro @@ -1,29 +1,26 @@ --- -import type { ImageMetadata } from 'astro' import { Image } from 'astro:assets' import mlb_ce from '../assets/ce/mlb.webp' +import type { GlobImage } from '../types/generic' +import { plsLoadImage } from '../utils/tools' export interface Props { name: string imageFile: string - mlb: string + mlb: boolean } const { mlb, imageFile, name } = Astro.props const imagePath = `/src/assets/ce/${imageFile}` -const images_ces = import.meta.glob<{ default: ImageMetadata }>( - '/src/assets/ce/*.png' -) +const images_ces = import.meta.glob('/src/assets/ce/*.png') +const loadedCEImage = plsLoadImage(images_ces, imagePath) -let mlb_image: string = 'mlbalign' -if (mlb === 'false') { - mlb_image = 'hidemlb' -} +const mlb_image = mlb ? 'mlbalign' : 'hidemlb' ---
- {name} + {name}
Max-limit broken diff --git a/src/components/contactCard.astro b/src/components/contactCard.astro index 2210b8e..93772f5 100644 --- a/src/components/contactCard.astro +++ b/src/components/contactCard.astro @@ -1,6 +1,7 @@ --- -import type { ImageMetadata } from 'astro' import { Image } from 'astro:assets' +import type { GlobImage } from '../types/generic' +import { plsLoadImage } from '../utils/tools' export interface Props { site: string @@ -11,14 +12,20 @@ export interface Props { const { imageFile, link, site } = Astro.props const logoAltText = `${site} Logo` const imagePath = `/src/assets/social/${imageFile}` -const images_logos = import.meta.glob<{ default: ImageMetadata }>( +const images_logos = import.meta.glob( '/src/assets/social/*.{png,webp}' ) +const loadedLogoImage = plsLoadImage(images_logos, imagePath) --- - +
- {logoAltText} + {logoAltText}

{site}

diff --git a/src/components/favouriteCard.astro b/src/components/favouriteCard.astro index 2d098ab..1e67512 100644 --- a/src/components/favouriteCard.astro +++ b/src/components/favouriteCard.astro @@ -1,6 +1,7 @@ --- -import type { ImageMetadata } from 'astro'; import { Image } from 'astro:assets'; +import type { GlobImage } from '../types/generic' +import { plsLoadImage } from '../utils/tools' export interface Props { name: string @@ -11,12 +12,13 @@ export interface Props { const { link, imageFile, origin, name } = Astro.props const imagePath = `/src/assets/favourites/${imageFile}` -const images = import.meta.glob<{ default: ImageMetadata }>('/src/assets/favourites/*.{png,webp}') +const images = import.meta.glob('/src/assets/favourites/*.{png,webp}') +const loadedImage = plsLoadImage(images, imagePath) ---
{name}
- {name} + {name}

{origin}

diff --git a/src/components/servantCard.astro b/src/components/servantCard.astro index 22390d2..34abab5 100644 --- a/src/components/servantCard.astro +++ b/src/components/servantCard.astro @@ -1,6 +1,7 @@ --- -import type { ImageMetadata } from 'astro'; import { Image } from 'astro:assets'; +import type { GlobImage } from '../types/generic' +import { plsLoadImage } from '../utils/tools' export interface Props { name: string @@ -16,8 +17,10 @@ export interface Props { const { bond10, ml, bondceImageFile, servantImageFile, np, skills, level, name } = Astro.props const servantImagePath = `/src/assets/servant/${servantImageFile}` const bondceImagePath = `/src/assets/ce/bond-ce/${bondceImageFile}` -const images_servants = import.meta.glob<{ default: ImageMetadata }>('/src/assets/servant/*.{png,webp}') -const images_bond_ces = import.meta.glob<{ default: ImageMetadata }>('/src/assets/ce/bond-ce/*.{png,webp}') +const images_servants = import.meta.glob('/src/assets/servant/*.{png,webp}') +const images_bond_ces = import.meta.glob('/src/assets/ce/bond-ce/*.{png,webp}') +const loadedServantImage = plsLoadImage(images_servants, servantImagePath) +const loadedBondCEImage = plsLoadImage(images_bond_ces, bondceImagePath) let bondce_css: string = 'bond-ce' @@ -27,14 +30,14 @@ if (bond10 === false) { ---
- {name} + {name}

Level {level}
{skills}
NP {np}

- +

Mana Loading: {ml === 'Not Unlocked' &&
}{ml}

diff --git a/src/components/taCard.astro b/src/components/taCard.astro index 8852ebc..be4659d 100644 --- a/src/components/taCard.astro +++ b/src/components/taCard.astro @@ -1,6 +1,8 @@ --- -import type { ImageMetadata } from 'astro' import { Image } from 'astro:assets' +import type { GlobImage } from '../types/generic' +import { plsLoadImage } from '../utils/tools' + export interface Props { date: string title: string @@ -24,13 +26,16 @@ const targetImagePath = `/src/assets/ta_icons/${targetImageFile}` const servantImagePath = `/src/assets/ta_icons/ta_servants/${servantImageFile}` const formatted_date = new Date(date).toLocaleDateString('de-DE', options_date) -const target_images = import.meta.glob<{ default: ImageMetadata }>( +const target_images = import.meta.glob( '/src/assets/ta_icons/*.{png,webp}' ) -const servant_images = import.meta.glob<{ default: ImageMetadata }>( +const servant_images = import.meta.glob( '/src/assets/ta_icons/ta_servants/*.{png,webp}' ) +const loadedServantImage = plsLoadImage(servant_images, servantImagePath) +const loadedTargetImage = plsLoadImage(target_images, targetImagePath) + let hasuser = '' if (user !== undefined) { hasuser = 'hasuser' @@ -39,7 +44,7 @@ if (user !== undefined) {
- {title} + {title}

{title}

@@ -50,7 +55,7 @@ if (user !== undefined) { {formatted_date}

- +

{turns}

diff --git a/src/components/technologyCard.astro b/src/components/technologyCard.astro index 41e61d0..bee5474 100644 --- a/src/components/technologyCard.astro +++ b/src/components/technologyCard.astro @@ -1,6 +1,7 @@ --- -import type { ImageMetadata } from 'astro' import { Image } from 'astro:assets' +import type { GlobImage } from '../types/generic' +import { plsLoadImage } from '../utils/tools' export interface Props { title: string @@ -11,14 +12,15 @@ export interface Props { const { imageFile, link, title } = Astro.props const logoAltText = `${title} Logo` const imagePath = `/src/assets/technologies/${imageFile}` -const images_logos = import.meta.glob<{ default: ImageMetadata }>( +const images_logos = import.meta.glob( '/src/assets/technologies/*.{png,webp}' ) +const loadedImage = plsLoadImage(images_logos, imagePath) ---
- {logoAltText} + {logoAltText}

{title}

diff --git a/src/types/generic.ts b/src/types/generic.ts new file mode 100644 index 0000000..65db641 --- /dev/null +++ b/src/types/generic.ts @@ -0,0 +1,10 @@ +export interface IconsLookup { + [key: string]: ImageMetadata +} + +interface GlobGeneric { + default: T +} + +export type GlobAny = GlobGeneric +export type GlobImage = GlobGeneric diff --git a/src/utils/tools.ts b/src/utils/tools.ts new file mode 100644 index 0000000..4dc88c9 --- /dev/null +++ b/src/utils/tools.ts @@ -0,0 +1,5 @@ +export function plsLoadImage(record: Record Promise<{default: ImageMetadata}>>, path: string) { + const loadedImage = record[path]?.(); + if (!loadedImage) throw new Error("Asset was not found:" + path); + return loadedImage; +} diff --git a/static/data/_cedata.json b/static/data/_cedata.json index 188f42a..c40f365 100644 --- a/static/data/_cedata.json +++ b/static/data/_cedata.json @@ -2,56 +2,56 @@ { "name": "The Merciless One", "imageFile": "merciless_one.png", - "mlb": "true" + "mlb": true }, { "name": "Ox-Demon King", "imageFile": "ox-demon.png", - "mlb": "true" + "mlb": true }, { "name": "Holy Maiden's Teachings", "imageFile": "maidens_teachings.png", - "mlb": "true" + "mlb": true }, { "name": "Kaleidoscope", "imageFile": "kaleidoscope.png", - "mlb": "true" + "mlb": true }, { "name": "The Black Grail", "imageFile": "black_grail.png", - "mlb": "true" + "mlb": true }, { "name": "A Fragment Of 2030", "imageFile": "2030.png", - "mlb": "true" + "mlb": true }, { "name": "Outrage", "imageFile": "outrage.png", - "mlb": "false" + "mlb": false }, { "name": "Vessel of the Saint", "imageFile": "vessel.png", - "mlb": "false" + "mlb": false }, { "name": "Devilish Bodhisattva", "imageFile": "devilish_bodhisattva.png", - "mlb": "true" + "mlb": true }, { "name": "500-Year Obsession", "imageFile": "500.png", - "mlb": "true" + "mlb": true }, { "name": "Prisma Cosmos", "imageFile": "prisma_cosmos.png", - "mlb": "true" + "mlb": true } ]