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

Commit 58122aa

Browse files
committed
Simplify return
1 parent 91d5053 commit 58122aa

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

api/wordpress/_global/getPostTypeStaticPaths.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,24 @@ export default async function getPostTypeStaticPaths(postType) {
4141
const posts = await apolloClient.query({query})
4242

4343
// Process paths.
44-
return {
45-
paths: !posts?.data?.[pluralName]?.nodes
46-
? []
47-
: posts.data[pluralName].nodes.map((post) => {
48-
// Use string path for non-hierarchical posts, split into array if hierarchical.
49-
const slug = !isHierarchical
50-
? post[pathField]
51-
: post[pathField].replace(/^\/|\/$/g, '').split('/')
52-
53-
return {
54-
params: {
55-
slug
56-
}
44+
const paths = !posts?.data?.[pluralName]?.nodes
45+
? []
46+
: posts.data[pluralName].nodes.map((post) => {
47+
// Use path field as-is for non-hierarchical post types.
48+
// Trim leading and trailing slashes then split into array on inner slashes for hierarchical post types.
49+
const slug = !isHierarchical
50+
? post[pathField]
51+
: post[pathField].replace(/^\/|\/$/g, '').split('/')
52+
53+
return {
54+
params: {
55+
slug
5756
}
58-
}),
57+
}
58+
})
59+
60+
return {
61+
paths,
5962
fallback: false
6063
}
6164
}

0 commit comments

Comments
 (0)