summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/src/content/internal.ts8
-rw-r--r--packages/astro/src/content/template/types.d.ts15
2 files changed, 13 insertions, 10 deletions
diff --git a/packages/astro/src/content/internal.ts b/packages/astro/src/content/internal.ts
index 550f6665a..8d20aa184 100644
--- a/packages/astro/src/content/internal.ts
+++ b/packages/astro/src/content/internal.ts
@@ -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;
}
diff --git a/packages/astro/src/content/template/types.d.ts b/packages/astro/src/content/template/types.d.ts
index 5b4dc874b..81ea9a95e 100644
--- a/packages/astro/src/content/template/types.d.ts
+++ b/packages/astro/src/content/template/types.d.ts
@@ -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>[]>;