Removed unnecessary types and fixed some bugs

This commit is contained in:
Firq-ow 2024-01-09 17:01:31 +01:00
parent 441d8a42a3
commit 8308413c60
Signed by: Firq
GPG key ID: BC5CE35A72BDB4AB
8 changed files with 16 additions and 46 deletions

View file

@ -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
)

View file

@ -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<GlobImage>(
)
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}`
---

View file

@ -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(),

View file

@ -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() )
---
<Layout

View file

@ -8,12 +8,8 @@ const description = 'FGO NA TA Database'
const fulldata = await getCollection('taInfoData')
fulldata.sort(
(a, b) => 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}
>
<DatabaseSection title="FGO NA TA Database">
{infodata.map((quest) => <QuestListing { ...quest } />)}
{fulldata.map((quest) => <QuestListing { ...{...quest.data.info, slug: quest.id} } />)}
</DatabaseSection>
</Layout>

View file

@ -1,5 +1,3 @@
import type { FileData } from "./ta"
export interface IconsLookup {
[key: string]: ImageMetadata
}
@ -7,7 +5,6 @@ export interface IconsLookup {
interface GlobGeneric<T> {
default: T
}
export type GlobAny = GlobGeneric<any>
export type GlobFiledata = GlobGeneric<FileData>
export type GlobImage = GlobGeneric<ImageMetadata>
export type ImportRecord<T> = Record<string, () => Promise<T>>

View file

@ -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[]
}

View file

@ -1,16 +1,14 @@
import { getEntry } from 'astro:content'
import type { GlobImage, ImportRecord } from '../types/generic'
export function plsLoadImage(
record: Record<string, () => Promise<{ default: ImageMetadata }>>,
path: string
) {
export function plsLoadImage(record: ImportRecord<GlobImage>, 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
}