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

Commit 33a2ce2

Browse files
committed
Add check for archive to static props
1 parent 798a1d5 commit 33a2ce2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

api/wordpress/_global/getPostTypeStaticProps.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import getPostTypeById from './getPostTypeById'
22
import {addApolloState} from '../connector'
3+
import getPostTypeArchive from './getPostTypeArchive'
34

45
/**
56
* Retrieve static props by post type.
@@ -16,6 +17,24 @@ export default async function getPostTypeStaticProps(
1617
// preview = false, // TODO - add preview handling.
1718
// previewData = null
1819
) {
20+
// Check for dynamic archive display.
21+
if (!Object.keys(params).length) {
22+
const {apolloClient, posts, error, errorMessage} = await getPostTypeArchive(
23+
postType
24+
)
25+
26+
// Merge in query results as Apollo state.
27+
return addApolloState(apolloClient, {
28+
props: {
29+
posts,
30+
error,
31+
errorMessage,
32+
archive: true
33+
},
34+
revalidate: 60 * 5
35+
})
36+
}
37+
1938
// Handle catch-all routes.
2039
const slug = Array.isArray(params.slug) ? params.slug.join('/') : params.slug
2140

0 commit comments

Comments
 (0)