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

Commit 3fbb19c

Browse files
committed
Add tax archive handling in static props
1 parent 6e41aa1 commit 3fbb19c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

api/wordpress/_global/getPostTypeStaticProps.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {algoliaIndexName} from '@/api/algolia/connector'
22
import getPostTypeById from './getPostTypeById'
3-
import getPostTypeArchive from './getPostTypeArchive'
3+
import getPostTypeArchive, {archiveQuerySeo} from './getPostTypeArchive'
44
import {addApolloState} from '@/api/apolloConfig'
55
import getFrontendPage, {frontendPageSeo} from './getFrontendPage'
66
import getSettingsCustomPage, {
77
customPageQuerySeo
88
} from './getSettingsCustomPage'
9+
import getPostTypeTaxonomyArchive from './getPostTypeTaxonomyArchive'
910

1011
/**
1112
* Retrieve static props by post type.
@@ -75,6 +76,30 @@ export default async function getPostTypeStaticProps(
7576
})
7677
}
7778

79+
/* -- Handle taxonomy archives. -- */
80+
if (
81+
Object.keys(archiveQuerySeo).includes(postType) &&
82+
params.slug.length > 1
83+
) {
84+
const taxonomy = params.slug.shift()
85+
const taxonomySlug = params.slug.join('/')
86+
87+
const {apolloClient, ...archiveData} = await getPostTypeTaxonomyArchive(
88+
taxonomy,
89+
taxonomySlug
90+
)
91+
92+
// Merge in query results as Apollo state.
93+
return addApolloState(apolloClient, {
94+
props: {
95+
...archiveData,
96+
...sharedProps,
97+
archive: true
98+
},
99+
revalidate
100+
})
101+
}
102+
78103
/* -- Handle individual posts. -- */
79104

80105
// Handle catch-all routes.

0 commit comments

Comments
 (0)