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

Commit 19bdf7d

Browse files
author
Greg Rickaby
authored
Merge pull request #143 from WebDevStudios/feature/33-breadcrumbs
Feature/33 breadcrumbs
2 parents d5fa0e5 + 1a6c15f commit 19bdf7d

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

api/wordpress/_global/getPostTypeTaxonomyArchive.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,26 @@ export default async function getPostTypeTaxonomyArchive(
102102
// Flatten posts array to include inner node post data.
103103
response.posts = posts.map((post) => post.node)
104104

105+
// Use final breadcrumb as alternative canonical URL.
106+
const breadcrumb =
107+
archiveSeo?.breadcrumbs &&
108+
archiveSeo.breadcrumbs.length > 0 &&
109+
archiveSeo.breadcrumbs.slice(-1)[0]?.url
110+
111+
// Manually create fallback taxonomy canonical URL.
112+
const fallback = `${response.defaultSeo?.openGraph?.url ?? ''}/${
113+
postTypes?.[postType]?.route
114+
}/${taxonomy}/${taxonomyId}`
115+
105116
// Structure archive SEO.
106117
response.post = {
107118
seo: {
119+
...archiveSeo,
108120
title:
109121
archiveSeo?.title ??
110122
`${taxonomyId} - ${response.defaultSeo?.openGraph?.siteName ?? ''}`,
111123
metaDesc: archiveSeo?.metaDesc ?? '',
112-
canonical:
113-
archiveSeo?.canonical ??
114-
`${response.defaultSeo?.openGraph?.url ?? ''}/${
115-
postTypes?.[postType]?.route
116-
}/${taxonomy}/${taxonomyId}`,
124+
canonical: archiveSeo?.canonical ?? breadcrumb ?? fallback,
117125
metaRobotsNofollow: archiveSeo?.metaRobotsNofollow ?? 'follow',
118126
metaRobotsNoindex: archiveSeo?.metaRobotsNoindex ?? 'index'
119127
}

api/wordpress/_global/postTypes.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// Define valid WP post types (singular and plural GraphQL names).
22
export const postTypes = {
3-
comment: {
4-
pluralName: 'comments',
5-
route: null
6-
},
73
mediaItem: {
84
pluralName: 'mediaItems',
95
route: null

api/wordpress/_partials/seoPostFields.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Query partial: retrieve SEO post fields.
22
const seoPostFields = `
33
seo {
4+
breadcrumbs {
5+
text
6+
url
7+
}
48
canonical
59
title
610
metaDesc

components/common/Layout.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export default function Layout({children, seo, hasJsonLd}) {
2828
}
2929
]
3030

31+
// Extract breadcrumbs from SEO.
32+
const breadcrumbs = seo?.breadcrumbs
33+
3134
return (
3235
<>
3336
<NextSeo
@@ -55,7 +58,21 @@ export default function Layout({children, seo, hasJsonLd}) {
5558
)}
5659
<Meta />
5760
<Header />
58-
<main>{children}</main>
61+
<main>
62+
{/* TODO: extract breadcrumbs to component and make pretty. */}
63+
{!!breadcrumbs && !!breadcrumbs.length && (
64+
<div>
65+
{breadcrumbs.map((breadcrumb, index) => (
66+
<span key={index}>
67+
<a href={breadcrumb?.url}>{breadcrumb?.text}</a>
68+
{index < breadcrumbs.length - 1 && <span> &raquo; </span>}
69+
</span>
70+
))}
71+
</div>
72+
)}
73+
74+
{children}
75+
</main>
5976
<Footer social={seo?.social} siteTitle={seo?.siteTitle} />
6077
</>
6178
)

functions/getPagePropTypes.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ export const seoSocialPropTypes = {
2121
// Yoast SEO prop types.
2222
export const seoPropTypes = {
2323
seo: PropTypes.shape({
24-
siteTitle: PropTypes.string,
25-
siteDescription: PropTypes.string,
26-
title: PropTypes.string,
24+
breadcrumbs: PropTypes.array,
25+
canonical: PropTypes.string,
2726
description: PropTypes.string,
28-
url: PropTypes.string,
2927
metaRobotsIndex: PropTypes.string,
3028
metaRobotsFollow: PropTypes.string,
3129
opengraphAuthor: PropTypes.string,
@@ -35,6 +33,10 @@ export const seoPropTypes = {
3533
altText: PropTypes.string,
3634
sourceUrl: PropTypes.string
3735
}),
36+
siteTitle: PropTypes.string,
37+
siteDescription: PropTypes.string,
38+
title: PropTypes.string,
39+
url: PropTypes.string,
3840
...seoSocialPropTypes
3941
})
4042
}

0 commit comments

Comments
 (0)