Skip to content

Commit b0f576d

Browse files
committed
enable apis
1 parent e86c1e2 commit b0f576d

File tree

3 files changed

+51
-39
lines changed

3 files changed

+51
-39
lines changed

src/js/contentfulClient.js

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,61 @@ const client = contentful.createClient({
66
})
77

88
export const monthNames = [
9-
'Jan',
10-
'Feb',
11-
'Mar',
12-
'Apr',
13-
'May',
14-
'Jun',
15-
'Jul',
16-
'Aug',
17-
'Sep',
18-
'Oct',
19-
'Nov',
20-
'Dec'
9+
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
2110
]
2211

12+
// --------- one cached fetch for *all* entries ---------
13+
14+
let allEntriesPromise = null
15+
16+
export const getEntries = async() => {
17+
if (allEntriesPromise) return allEntriesPromise
18+
19+
allEntriesPromise = (async() => {
20+
const pageSize = 1000
21+
let skip = 0
22+
const all = []
23+
24+
while (true) {
25+
const res = await client.getEntries({ limit: pageSize, skip })
26+
all.push(...res.items)
27+
skip += res.items.length
28+
if (all.length >= res.total || res.items.length === 0) break
29+
}
30+
31+
return all
32+
})().catch((err) => {
33+
allEntriesPromise = null
34+
throw err
35+
})
36+
37+
return allEntriesPromise
38+
}
39+
40+
const byType = (items, contentTypeId) =>
41+
items.filter((e) => e.sys?.contentType?.sys?.id === contentTypeId)
42+
2343
export const getNews = async() => {
24-
const items = await client
25-
.getEntries({
26-
content_type: 'latestNews'
27-
})
28-
.then(({ items }) => items.map(({ fields }) => ({
29-
...fields,
30-
image: fields.image?.fields,
31-
imageDark: fields.imageDark?.fields // optional, for darkmode, eg white text variant
32-
})))
33-
return items
44+
const items = byType(await getEntries(), 'latestNews')
45+
return items.map(({ fields }) => ({
46+
...fields,
47+
image: fields.image?.fields,
48+
imageDark: fields.imageDark?.fields
49+
}))
3450
}
3551

3652
export const getEvents = async() => {
37-
const items = await client
38-
.getEntries({
39-
content_type: 'event'
40-
})
41-
.then(({ items }) => items.map(({ fields }) => ({
42-
...fields,
43-
image: fields.image?.fields
44-
})))
45-
return items
53+
const items = byType(await getEntries(), 'event')
54+
return items.map(({ fields }) => ({
55+
...fields,
56+
image: fields.image?.fields
57+
}))
4658
}
4759

4860
export const getSponsors = async() => {
49-
const { items } = await client
50-
.getEntries({
51-
content_type: 'sponsor'
52-
})
53-
return items
61+
return byType(await getEntries(), 'sponsor')
62+
}
63+
64+
export const clearEntriesCache = () => {
65+
allEntriesPromise = null
5466
}

src/views/Foundation.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
title-id="what-we-do"
3030
:title="$t('foundation.whatWeDo.title')"
3131
:body="$t('foundation.whatWeDo.body')">
32-
<!-- <sponsors-detailed class="" /> -->
32+
<sponsors-detailed class="" />
3333
</page-section>
3434
</div>
3535
<page-footer />

src/views/Home.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<div class="col-sm-12 col-lg-8 col-lg-offset-2 type-large p-medium card bg-secondary">
99
<div v-html="$t('introduction.body')" />
1010
</div>
11-
<!-- <div class="col-sm-12 col-lg-3 col-lg-offset-2 calendar-container">
11+
<div class="col-sm-12 col-lg-3 col-lg-offset-2 calendar-container">
1212
<calendar />
1313
</div>
1414
<div class="col-sm-12 col-lg-5 pl-medium news-container">
1515
<news />
16-
</div> -->
16+
</div>
1717
</div>
1818
<hr class="theme">
1919
<!-- getting started -->

0 commit comments

Comments
 (0)