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

Commit 46ac367

Browse files
committed
Fix archive seo
1 parent 1084af7 commit 46ac367

File tree

1 file changed

+56
-8
lines changed

1 file changed

+56
-8
lines changed

api/wordpress/_global/getPostTypeArchive.js

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,45 @@ import queryPortfoliosArchive from '../portfolios/queryPortfoliosArchive'
99
import queryTestimonialsArchive from '../testimonials/queryTestimonialsArchive'
1010
import formatDefaultSeoData from '@/functions/formatDefaultSeoData'
1111

12+
// Define SEO for archives.
13+
export const archiveSeo = {
14+
career: {
15+
title: 'Careers',
16+
description: '',
17+
route: 'careers'
18+
},
19+
event: {
20+
title: 'Events',
21+
description: '',
22+
route: 'events'
23+
},
24+
portfolio: {
25+
title: 'Portfolio',
26+
description: '',
27+
route: 'portfolio'
28+
},
29+
post: {
30+
title: 'Blog',
31+
description: '',
32+
route: 'blog'
33+
},
34+
service: {
35+
title: 'Services',
36+
description: '',
37+
route: 'service'
38+
},
39+
team: {
40+
title: 'Team Members',
41+
description: '',
42+
route: 'team'
43+
},
44+
testimonial: {
45+
title: 'Testimonials',
46+
description: '',
47+
route: 'testimonial'
48+
}
49+
}
50+
1251
/**
1352
* Retrieve post archive.
1453
*
@@ -97,14 +136,23 @@ export default async function getPostTypeArchive(
97136
// Flatten posts array to include inner node post data.
98137
response.posts = data.edges.map((post) => post.node)
99138

100-
// Attempt to use posts page for blog, default to front page.
101-
const defaultPage =
102-
'post' === postType && homepageSettings?.postsPage
103-
? homepageSettings.postsPage
104-
: homepageSettings?.frontPage
105-
106-
// Populate post object.
107-
response.post = {...defaultPage}
139+
// Attempt to use posts page for blog, default to custom SEO.
140+
response.post = {
141+
seo:
142+
'post' === postType && homepageSettings?.postsPage?.seo
143+
? homepageSettings.postsPage.seo
144+
: {
145+
title: `${archiveSeo?.[postType]?.title} - ${
146+
response.defaultSeo?.openGraph?.siteName ?? ''
147+
}`,
148+
metaDesc: archiveSeo?.[postType]?.description,
149+
canonical: `${response.defaultSeo?.openGraph?.url ?? ''}/${
150+
archiveSeo?.[postType]?.route
151+
}`,
152+
metaRobotsNofollow: 'follow',
153+
metaRobotsNoindex: 'index'
154+
}
155+
}
108156

109157
// Extract pagination data.
110158
response.pagination = data.pageInfo

0 commit comments

Comments
 (0)