mirror of
https://github.com/withastro/astro.git
synced 2025-02-24 22:46:02 -05:00
[ci] format
This commit is contained in:
parent
be901dc98c
commit
e36f310c2c
2 changed files with 13 additions and 10 deletions
|
@ -80,15 +80,15 @@ export function createGetEntryBySlug({
|
||||||
// This is not an optimized lookup. Should look into an O(1) implementation
|
// This is not an optimized lookup. Should look into an O(1) implementation
|
||||||
// as it's probably that people will have very large collections.
|
// as it's probably that people will have very large collections.
|
||||||
const entries = await getCollection(collection);
|
const entries = await getCollection(collection);
|
||||||
let candidate: typeof entries[number] | undefined = undefined;
|
let candidate: (typeof entries)[number] | undefined = undefined;
|
||||||
for(let entry of entries) {
|
for (let entry of entries) {
|
||||||
if(entry.slug === slug) {
|
if (entry.slug === slug) {
|
||||||
candidate = entry;
|
candidate = entry;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof candidate === 'undefined') {
|
if (typeof candidate === 'undefined') {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
packages/astro/src/content/template/types.d.ts
vendored
15
packages/astro/src/content/template/types.d.ts
vendored
|
@ -32,16 +32,19 @@ declare module 'astro:content' {
|
||||||
|
|
||||||
type EntryMapKeys = keyof typeof entryMap;
|
type EntryMapKeys = keyof typeof entryMap;
|
||||||
type AllValuesOf<T> = T extends any ? T[keyof T] : never;
|
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,
|
collection: C,
|
||||||
// Note that this has to accept a regular string too, for SSR
|
// Note that this has to accept a regular string too, for SSR
|
||||||
entrySlug: E
|
entrySlug: E
|
||||||
): E extends ValidEntrySlug<C> ? Promise<CollectionEntry<C>> : Promise<CollectionEntry<C> | undefined>;
|
): E extends ValidEntrySlug<C>
|
||||||
export function getCollection<
|
? Promise<CollectionEntry<C>>
|
||||||
C extends keyof typeof entryMap,
|
: Promise<CollectionEntry<C> | undefined>;
|
||||||
>(
|
export function getCollection<C extends keyof typeof entryMap>(
|
||||||
collection: C,
|
collection: C,
|
||||||
filter?: (data: CollectionEntry<C>) => boolean
|
filter?: (data: CollectionEntry<C>) => boolean
|
||||||
): Promise<CollectionEntry<C>[]>;
|
): Promise<CollectionEntry<C>[]>;
|
||||||
|
|
Loading…
Add table
Reference in a new issue