Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 068d153

Browse files
committed
Abstract shared props
1 parent b72be6a commit 068d153

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

api/wordpress/_global/getPostTypeStaticProps.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,29 @@ export default async function getPostTypeStaticProps(
2222
// Get WP Nav Menus.
2323
const menus = await getMenus(config.menuLocations)
2424

25-
// Check for dynamic archive display.
26-
if (!Object.keys(params).length) {
27-
const {apolloClient, ...archiveData} = await getPostTypeArchive(postType)
28-
29-
// Add WP Nav Menus to archive.
30-
archiveData.menus = menus
25+
// Set revalidate length (seconds).
26+
const revalidate = 60 * 5
3127

32-
// Add Algolia env vars to archive.
33-
archiveData.algolia = {
28+
// Set sharedProps.
29+
const sharedProps = {
30+
menus,
31+
algolia: {
3432
indexName: algoliaIndexName
3533
}
34+
}
35+
36+
// Check for dynamic archive display.
37+
if (!Object.keys(params).length) {
38+
const {apolloClient, ...archiveData} = await getPostTypeArchive(postType)
3639

3740
// Merge in query results as Apollo state.
3841
return addApolloState(apolloClient, {
3942
props: {
4043
...archiveData,
44+
...sharedProps,
4145
archive: true
4246
},
43-
revalidate: 60 * 5
47+
revalidate
4448
})
4549
}
4650

@@ -53,7 +57,11 @@ export default async function getPostTypeStaticProps(
5357
slug
5458
)
5559

56-
const props = {...postData, error}
60+
const props = {
61+
...postData,
62+
...sharedProps,
63+
error
64+
}
5765

5866
// Custom handling for homepage.
5967
if ('/' === slug && error) {
@@ -62,17 +70,9 @@ export default async function getPostTypeStaticProps(
6270
props.error = false
6371
}
6472

65-
// Set WP Nav Menus.
66-
props.menus = menus
67-
68-
// Add Algolia env vars.
69-
props.algolia = {
70-
indexName: algoliaIndexName
71-
}
72-
7373
// Merge in query results as Apollo state.
7474
return addApolloState(apolloClient, {
7575
props,
76-
revalidate: 60 * 5
76+
revalidate
7777
})
7878
}

0 commit comments

Comments
 (0)