fix(andreknie.de): close accessibility and performance review gaps
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import content from 'virtual:content'
|
||||
import detailLoaders from 'virtual:content-detail-loaders'
|
||||
|
||||
const detailCache = new Map()
|
||||
const detailModulePromise = import('virtual:content-details')
|
||||
|
||||
/**
|
||||
* Get all content of a given type, sorted by date descending.
|
||||
@@ -65,11 +65,20 @@ export function useContentItem(type, slug) {
|
||||
let active = true
|
||||
if (!metadata || detailCache.has(cacheKey)) return () => { active = false }
|
||||
|
||||
detailModulePromise.then(module => {
|
||||
const detail = module.default[type]?.find(candidate => candidate.slug === slug) || null
|
||||
if (detail) detailCache.set(cacheKey, detail)
|
||||
if (active) setDetailState({ key: cacheKey, item: detail })
|
||||
})
|
||||
const loadDetail = detailLoaders[type]?.[slug]
|
||||
const detailPromise = loadDetail
|
||||
? loadDetail()
|
||||
: Promise.reject(new Error(`No detail loader for ${cacheKey}`))
|
||||
|
||||
detailPromise
|
||||
.then(module => {
|
||||
const detail = module.default
|
||||
detailCache.set(cacheKey, detail)
|
||||
if (active) setDetailState({ key: cacheKey, item: detail })
|
||||
})
|
||||
.catch(() => {
|
||||
if (active) setDetailState({ key: cacheKey, item: { ...metadata, detailError: true } })
|
||||
})
|
||||
|
||||
return () => { active = false }
|
||||
}, [cacheKey, metadata, slug, type])
|
||||
|
||||
Reference in New Issue
Block a user