Skip to content

Commit

Permalink
fix: updated contentful to work in build env
Browse files Browse the repository at this point in the history
  • Loading branch information
schaechinger committed Dec 7, 2023
1 parent fdfe542 commit 0644c24
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/lib/contentful.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { cache } from 'react';
let instance: ContentfulClientApi<any> | null = null;

const connect = () => {
if (!instance) {
if (!instance && process.env.CONTENTFUL_API_KEY) {
instance = createClient({
space: process.env.CONTENTFUL_SPACE!,
accessToken: process.env.CONTENTFUL_API_KEY!,
accessToken: process.env.CONTENTFUL_API_KEY,
});
}

Expand Down Expand Up @@ -108,23 +108,23 @@ const getEntryFields = <T>(collection: EntryCollection<any>) => (
);

export const loadAvailability = () => (
connect().getEntries<AvailabilityEntrySkeleton>({
connect()?.getEntries<AvailabilityEntrySkeleton>({
content_type: 'availability',
})
.then(getEntryFields<AvailabilityData>)
.then((availabilities) => availabilities[0])
);

export const loadCareer = () => (
connect().getEntries<CareerEntrySkeleton>({
connect()?.getEntries<CareerEntrySkeleton>({
content_type: 'career',
})
.then(getEntryFields<CareerData>)
.then(sortCareerList)
);

export const loadProjects = (highlights = false) => (
connect().getEntries<ProjectEntrySkeleton>({
connect()?.getEntries<ProjectEntrySkeleton>({
content_type: 'project',
'fields.highlight': highlights || undefined,
})
Expand All @@ -148,7 +148,7 @@ export const loadProjects = (highlights = false) => (
);

export const loadProjectBySlug = cache((slug: string) => (
connect().getEntries<ProjectEntrySkeleton>({
connect()?.getEntries<ProjectEntrySkeleton>({
content_type: 'project',
'fields.slug': slug,
})
Expand Down

0 comments on commit 0644c24

Please sign in to comment.