[ci] format

This commit is contained in:
matthewp 2023-01-19 13:36:12 +00:00 committed by fredkbot
parent be901dc98c
commit e36f310c2c
2 changed files with 13 additions and 10 deletions

View file

@ -80,15 +80,15 @@ export function createGetEntryBySlug({
// This is not an optimized lookup. Should look into an O(1) implementation
// as it's probably that people will have very large collections.
const entries = await getCollection(collection);
let candidate: typeof entries[number] | undefined = undefined;
for(let entry of entries) {
if(entry.slug === slug) {
let candidate: (typeof entries)[number] | undefined = undefined;
for (let entry of entries) {
if (entry.slug === slug) {
candidate = entry;
break;
}
}
if(typeof candidate === 'undefined') {
if (typeof candidate === 'undefined') {
return undefined;
}

View file

@ -32,16 +32,19 @@ declare module 'astro:content' {
type EntryMapKeys = keyof typeof entryMap;
type AllValuesOf<T> = T extends any ? T[keyof T] : never;
type ValidEntrySlug<C extends EntryMapKeys> = AllValuesOf<typeof entryMap[C]>['slug'];
type ValidEntrySlug<C extends EntryMapKeys> = AllValuesOf<(typeof entryMap)[C]>['slug'];
export function getEntryBySlug<C extends keyof typeof entryMap, E extends ValidEntrySlug<C> | (string & {})>(
export function getEntryBySlug<
C extends keyof typeof entryMap,
E extends ValidEntrySlug<C> | (string & {})
>(
collection: C,
// Note that this has to accept a regular string too, for SSR
entrySlug: E
): E extends ValidEntrySlug<C> ? Promise<CollectionEntry<C>> : Promise<CollectionEntry<C> | undefined>;
export function getCollection<
C extends keyof typeof entryMap,
>(
): E extends ValidEntrySlug<C>
? Promise<CollectionEntry<C>>
: Promise<CollectionEntry<C> | undefined>;
export function getCollection<C extends keyof typeof entryMap>(
collection: C,
filter?: (data: CollectionEntry<C>) => boolean
): Promise<CollectionEntry<C>[]>;