From 62e3869ce9d0fada97a58c67b24802a42ef29f16 Mon Sep 17 00:00:00 2001 From: Firq-ow Date: Tue, 9 Jan 2024 17:01:31 +0100 Subject: [PATCH] Removed unnecessary types and fixed some bugs --- src/components/questListing.astro | 5 +++-- src/components/taCard.astro | 5 ++--- src/content/config.ts | 4 ++-- src/layouts/taShowcaseLayout.astro | 2 +- src/pages/database/index.astro | 8 ++------ src/types/generic.ts | 7 ++----- src/types/ta.ts | 21 --------------------- src/utils/tools.ts | 10 ++++------ 8 files changed, 16 insertions(+), 46 deletions(-) delete mode 100644 src/types/ta.ts diff --git a/src/components/questListing.astro b/src/components/questListing.astro index 64ff216..e5b82b7 100644 --- a/src/components/questListing.astro +++ b/src/components/questListing.astro @@ -2,7 +2,7 @@ export interface Props { slug: string title: string - questReleaseDate: string + questReleaseDate: Date shortdescription: string } @@ -11,9 +11,10 @@ const options_date: Intl.DateTimeFormatOptions = { month: 'long', day: '2-digit', } + const { shortdescription, questReleaseDate, slug, title } = Astro.props const url = `/database/${slug}` -const render_date = new Date(questReleaseDate).toLocaleDateString( +const render_date = questReleaseDate.toLocaleDateString( 'en-GB', options_date ) diff --git a/src/components/taCard.astro b/src/components/taCard.astro index 0d2fdc4..0c31bac 100644 --- a/src/components/taCard.astro +++ b/src/components/taCard.astro @@ -1,12 +1,11 @@ --- -import type { ImageMetadata } from 'astro' import { Image } from 'astro:assets' import { plsLoadImage } from '../utils/tools' import type { GlobImage } from '../types/generic' export interface Props { title: string link: string - date: string + date: Date servant: string turns: string runner: string @@ -26,7 +25,7 @@ const servant_images = import.meta.glob( ) const loaded_image = plsLoadImage(servant_images, servantImagePath) -const formatted_date = new Date(date).toLocaleDateString('de-DE', options_date) +const formatted_date = date.toLocaleDateString('de-DE', options_date) const arialabel = `By ${runner} • ${formatted_date} ${turns}` --- diff --git a/src/content/config.ts b/src/content/config.ts index 7d8cf2d..57de031 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -5,7 +5,7 @@ const taInfo = defineCollection({ schema: z.object({ info: z.object({ title: z.string(), - questReleaseDate: z.string(), + questReleaseDate: z.string().transform((str) => new Date(str)), shortdescription: z.string(), description: z.string(), fightNumber: z.number().default(1), @@ -14,7 +14,7 @@ const taInfo = defineCollection({ z.object({ title: z.string(), link: z.string().url(), - date: z.string(), + date: z.string().transform((str) => new Date(str)), servant: z.string(), turns: z.string(), runner: z.string(), diff --git a/src/layouts/taShowcaseLayout.astro b/src/layouts/taShowcaseLayout.astro index 9b97566..ad0a82f 100644 --- a/src/layouts/taShowcaseLayout.astro +++ b/src/layouts/taShowcaseLayout.astro @@ -11,7 +11,7 @@ export interface Props { const { datafile } = Astro.props const taEntry = await plsLoadTAEntry(datafile) const pagetitle = `${taEntry.info.title} - FGO TA` -taEntry.data.sort((a, b) => Date.parse(b.date) - Date.parse(a.date)) +taEntry.data.sort((a, b) => b.date.valueOf() - a.date.valueOf() ) --- Date.parse(b.data.info.questReleaseDate) - Date.parse(a.data.info.questReleaseDate) || b.data.info.fightNumber - a.data.info.fightNumber + (a, b) => b.data.info.questReleaseDate.valueOf() - a.data.info.questReleaseDate.valueOf() || b.data.info.fightNumber - a.data.info.fightNumber ) -const infodata = fulldata.map((quest) => ({ - ...quest.data.info, - slug: quest.id -})) --- @@ -23,7 +19,7 @@ const infodata = fulldata.map((quest) => ({ descriptionOverride={description} > - {infodata.map((quest) => )} + {fulldata.map((quest) => )} diff --git a/src/types/generic.ts b/src/types/generic.ts index 038edd8..d1a9693 100644 --- a/src/types/generic.ts +++ b/src/types/generic.ts @@ -1,5 +1,3 @@ -import type { FileData } from "./ta" - export interface IconsLookup { [key: string]: ImageMetadata } @@ -7,7 +5,6 @@ export interface IconsLookup { interface GlobGeneric { default: T } - -export type GlobAny = GlobGeneric -export type GlobFiledata = GlobGeneric export type GlobImage = GlobGeneric + +export type ImportRecord = Record Promise> \ No newline at end of file diff --git a/src/types/ta.ts b/src/types/ta.ts deleted file mode 100644 index c3ed231..0000000 --- a/src/types/ta.ts +++ /dev/null @@ -1,21 +0,0 @@ -interface TAData { - title: string - link: string - servant: string - turns: string - runner: string - date: string -} - -interface Info { - title: string - questReleaseDate: string - description: string - shortdescription: string - fightNumber: number -} - -export interface FileData { - info: Info - data: TAData[] -} diff --git a/src/utils/tools.ts b/src/utils/tools.ts index 891468a..9cb727c 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -1,16 +1,14 @@ import { getEntry } from 'astro:content' +import type { GlobImage, ImportRecord } from '../types/generic' -export function plsLoadImage( - record: Record Promise<{ default: ImageMetadata }>>, - path: string -) { +export function plsLoadImage(record: ImportRecord, path: string) { const loadedImage = record[path]?.() - if (!loadedImage) throw new Error('Asset was not found:' + path) + if (!loadedImage) throw new Error(`Asset was not found for path ${path}`) return loadedImage } export async function plsLoadTAEntry(key: string) { const filecontent = (await getEntry('taInfoData', key))?.data - if (!filecontent) throw new Error(`Datafile ${key} is missing!`) + if (!filecontent) throw new Error(`Datafile was not found for key ${key}`) return filecontent }